Package java.util.concurrent

Examples of java.util.concurrent.BlockingQueue


        }
        super.doStop();
    }

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

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

            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


      if (!started) {
         throw new IllegalStateException("You have to start the service first!");
      }
      if (address == null)
         throw new NullPointerException("Null address not supported!");
      BlockingQueue queue = address2key.get(address);
      if (queue == null)
         throw new IllegalStateException("Address " + address + " is no longer in the cluster");

      try {
         maxNumberInvariant.readLock().lock();
         Object result = null;
         try {
            while (result == null && !keyGenWorker.isStopped()) {
               // first try to take an element without waiting
               result = queue.poll();
               if (result == null) {
                  // there are no elements in the queue, make sure the producer is started
                  keyProducerStartLatch.open();
                  // our address might have been removed from the consistent hash
                  if (!address.equals(getAddressForKey(address)))
                     throw new IllegalStateException("Address " + address + " is no longer in the cluster");
               }
            }
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
      } finally {
         if (queue.size() < maxNumberOfKeys.get() * THRESHOLD + 1) {
            keyProducerStartLatch.open();
         }
      }
   }
View Full Code Here

         }
         return false;
      }

      private void tryAddKey(Address address, Object key) {
         BlockingQueue queue = address2key.get(address);
         // on node stop the distribution manager might still return the dead server for a while after we have already removed its queue
         if (queue == null)
            return;

         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            if (added)
View Full Code Here

        }
        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

    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

      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

   */
  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

        }
        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

    /**
     * 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

    /**
     * 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

TOP

Related Classes of java.util.concurrent.BlockingQueue

Copyright © 2018 www.massapicom. 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.