Examples of BlockingQueue


Examples of java.util.concurrent.BlockingQueue

        }
        super.doStop();
    }

    public void run() {
        final BlockingQueue queue = endpoint.getQueue();

        while (queue != null && isRunAllowed()) {
            final Exchange exchange = new DefaultExchange(this.getEndpoint().getCamelContext());

            try {
                final Object body = queue.poll(endpoint.getConfiguration().getPollInterval(), TimeUnit.MILLISECONDS);

                if (body != null) {
                    exchange.getIn().setBody(body);
                    try {
                        processor.process(exchange, new AsyncCallback() {
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    Object eventThread = field.get(zkclient);
    // System.out.println("field: " + eventThread);

    java.lang.reflect.Field field2 = getField(eventThread.getClass(), "_events");
    field2.setAccessible(true);
    BlockingQueue queue = (BlockingQueue) field2.get(eventThread);
    // System.out.println("field2: " + queue + ", " + queue.size());

    if (queue == null) {
      LOG.error("fail to get event-queue from zkclient. skip waiting");
      return false;
    }

    for (int i = 0; i < 20; i++) {
      if (queue.size() == 0) {
        return true;
      }
      Thread.sleep(100);
      System.out.println("pending zk-events in queue: " + queue);
    }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

      logger.info("Initializing ThreadPoolExecutor" + (this.beanName != null ? " '" + this.beanName + "'" : ""));
    }
    if (!this.threadNamePrefixSet && this.beanName != null) {
      setThreadNamePrefix(this.beanName + "-");
    }
    BlockingQueue queue = createQueue(this.queueCapacity);
    this.threadPoolExecutor = new ThreadPoolExecutor(
        this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
        queue, this.threadFactory, this.rejectedExecutionHandler);
    if (this.allowCoreThreadTimeOut) {
      this.threadPoolExecutor.allowCoreThreadTimeOut(true);
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

   */
  public void initialize() {
    if (logger.isInfoEnabled()) {
      logger.info("Initializing ThreadPoolExecutor" + (this.beanName != null ? " '" + this.beanName + "'" : ""));
    }
    BlockingQueue queue = createQueue(this.queueCapacity);
    this.threadPoolExecutor = new ThreadPoolExecutor(
        this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
        queue, this.threadFactory, this.rejectedExecutionHandler);
  }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

        }
        super.doStop();
    }

    public void run() {
        final BlockingQueue queue = endpoint.getQueue();

        while (queue != null && isRunAllowed()) {
            final Exchange exchange = new DefaultExchange(this.getEndpoint().getCamelContext());

            try {
                final Object body = queue.poll(endpoint.getConfiguration().getPollInterval(), TimeUnit.MILLISECONDS);

                if (body != null) {
                    if (body instanceof DefaultExchangeHolder) {
                        DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) body);
                    } else {
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    /**
     * iterator ordering is FIFO
     */
    @Test
    public void testIteratorOrdering() {
        final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(3);
        q.add(one);
        q.add(two);
        q.add(three);

        assertEquals("queue should be full", 0, q.remainingCapacity());

        int k = 0;
        for (Iterator it = q.iterator(); it.hasNext(); ) {
            assertEquals(++k, it.next());
        }
        assertEquals(3, k);
    }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    /**
     * Modifications do not cause iterators to fail
     */
    @Test
    public void testWeaklyConsistentIteration() {
        final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(3);
        q.add(one);
        q.add(two);
        q.add(three);
        for (Iterator it = q.iterator(); it.hasNext(); ) {
            q.remove();
            it.next();
        }
        assertEquals(0, q.size());
    }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    /**
     * toString contains toStrings of elements
     */
    @Test
    public void testToString() {
        BlockingQueue q = populatedQueue(SIZE);
        String s = q.toString();
        for (int i = 0; i < SIZE; ++i) {
            assertTrue(s.contains(String.valueOf(i)));
        }
    }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    /**
     * offer transfers elements across Executor tasks
     */
    @Test
    public void testOfferInExecutor() {
        final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
        q.add(one);
        q.add(two);
        ExecutorService executor = Executors.newFixedThreadPool(2);
        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }
        });

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertEquals(0, q.remainingCapacity());
                assertSame(one, q.take());
            }
        });

        joinPool(executor);
    }
View Full Code Here

Examples of java.util.concurrent.BlockingQueue

    /**
     * timed poll retrieves elements across Executor threads
     */
    @Test
    public void testPollInExecutor() {
        final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
        final CheckedBarrier threadsStarted = new CheckedBarrier(2);
        ExecutorService executor = Executors.newFixedThreadPool(2);
        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                assertNull(q.poll());
                threadsStarted.await();
                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
                checkEmpty(q);
            }
        });

        executor.execute(new CheckedRunnable() {
            public void realRun() throws InterruptedException {
                threadsStarted.await();
                q.put(one);
            }
        });

        joinPool(executor);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.