Package java.util.concurrent

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


      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 {
         Object result = null;
         while (result == null && !keyGenWorker.isStopped()) {
            // obtain the read lock inside the loop, otherwise a topology change will never be able
            // to obtain the write lock
            maxNumberInvariant.readLock().lock();
            try {
               // 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 (!isNodeInConsistentHash(address))
                     throw new IllegalStateException("Address " + address + " is no longer in the cluster");
               }
            } finally {
               maxNumberInvariant.readLock().unlock();
            }
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
      } finally {
         if (queue.size() < bufferSize * THRESHOLD + 1) {
            keyProducerStartLatch.open();
         }
      }
   }
View Full Code Here

         }
         return false;
      }

      private boolean 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 false;

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

    private void execute(Object task, int partitionId, boolean priority) {
        if (task == null) {
            throw new NullPointerException();
        }

        BlockingQueue workQueue;
        Queue priorityWorkQueue;
        if (partitionId < 0) {
            workQueue = genericWorkQueue;
            priorityWorkQueue = genericPriorityWorkQueue;
        } 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)
         return null; // No address for key, unlikely

      try {
         maxNumberInvariant.readLock().lock();
         Object result;
         try {
            result = queue.take();
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
      } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
         return null;
      } 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

         }
         return false;
      }

      private void tryAddKey(Address address, Object key) {
         BlockingQueue queue = address2key.get(address);
         boolean added = queue.offer(key);
         if (added) {
            exitingNumberOfKeys.incrementAndGet();
         }
         if (log.isTraceEnabled()) {
            if (added)
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);
      try {
         maxNumberInvariant.readLock().lock();
         Object result;
         try {
            result = queue.take();
         } finally {
            maxNumberInvariant.readLock().unlock();
         }
         exitingNumberOfKeys.decrementAndGet();
         return result;
      } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
         return null;
      } finally {
         if (queue.size() < maxNumberOfKeys.get() * THRESHOLD + 1) {
            keyProducerStartLatch.open();
         }
      }
   }
View Full Code Here

     * @param batchSize the number of elements to feed at once into main output
     * queue.
     * @return the newly registered queue
     */
    public BlockingQueue<JTweet> register(String queueName, int capacity, int batchSize) {
        BlockingQueue q = new LinkedBlockingQueue<JTweet>(capacity);
        QueueInfo qInfo = new QueueInfo(queueName, q);
        for (QueueInfo<JTweet> qi : inputQueues) {
            if (qi.getName().equals(queueName))
                throw new IllegalStateException("cannot register queue. Queue " + queueName + " already exists");
        }
View Full Code Here

        val = ejbContainer.getPropertyValue(RuntimeTagNames.PRESTART_ALL_CORE_THREADS);
        boolean preStartAllCoreThreads = val != null ? Boolean.parseBoolean(val.trim())
                : EjbContainer.DEFAULT_PRESTART_ALL_CORE_THREADS;

        BlockingQueue workQueue = queueCapacity > 0
                ? new LinkedBlockingQueue<Runnable>(queueCapacity)
                : new SynchronousQueue(true);

        result = new EjbThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, workQueue, poolName);
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.