Class RoundRobinBlockingQueue<T>

  • Type Parameters:
    T - queue item type.
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.concurrent.BlockingQueue<T>, java.util.Queue<T>
    Direct Known Subclasses:
    ListenerNotificationQueue, NotificationEventBlockingQueue

    public class RoundRobinBlockingQueue<T>
    extends RoundRobinQueue<T>
    implements java.util.concurrent.BlockingQueue<T>
    Round Robin Blocking Queue. put(Object) and take() are recommended, as other methods internally call these methods.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T e)
      Add an item to the queue.
      boolean contains​(java.lang.Object e)
      Check if queue contains an item.
      int drainTo​(java.util.Collection<? super T> c)
      Empty queue into a collection.
      int drainTo​(java.util.Collection<? super T> c, int max)
      Empty queue into a collection, stopping after max elements.
      boolean offer​(T e)
      Offer an item to the queue.
      boolean offer​(T e, long timeout, java.util.concurrent.TimeUnit unit)
      Offer an item to the queue.
      T poll​(long timeout, java.util.concurrent.TimeUnit unit)
      Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
      void put​(T e)
      Put an item in the queue.
      int remainingCapacity()
      Unbounded queues return Integer.MAX_VALUE.
      boolean remove​(java.lang.Object e)
      Remove an object from the queue.
      T take()
      Remove an object from the queue.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Queue

        element, peek, poll, remove
    • Constructor Detail

      • RoundRobinBlockingQueue

        public RoundRobinBlockingQueue()
        Constructor
    • Method Detail

      • add

        public boolean add​(T e)
        Add an item to the queue.
        Specified by:
        add in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Queue<T>
        Overrides:
        add in class RoundRobinQueue<T>
        Parameters:
        e - item to add
        Returns:
        true if added.
      • contains

        public boolean contains​(java.lang.Object e)
        Check if queue contains an item.
        Specified by:
        contains in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        contains in interface java.util.Collection<T>
        Overrides:
        contains in class RoundRobinQueue<T>
      • offer

        public boolean offer​(T e)
        Offer an item to the queue. Calls add(Object), but returns false if any exceptions thrown.
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        offer in interface java.util.Queue<T>
        Overrides:
        offer in class RoundRobinQueue<T>
        Parameters:
        e - item to add
        Returns:
        true if added, false otherwise.
      • offer

        public boolean offer​(T e,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Offer an item to the queue. Same as offer(Object), this is an unbounded queue.
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • poll

        public T poll​(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws java.lang.InterruptedException
        Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
        Specified by:
        poll in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • put

        public void put​(T e)
                 throws java.lang.InterruptedException
        Put an item in the queue.
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException - if interrupted while acquiring lock.
      • remainingCapacity

        public int remainingCapacity()
        Unbounded queues return Integer.MAX_VALUE.
        Specified by:
        remainingCapacity in interface java.util.concurrent.BlockingQueue<T>
        Returns:
        Integer.MAX_VALUE;
      • remove

        public boolean remove​(java.lang.Object e)
        Remove an object from the queue.
        Specified by:
        remove in interface java.util.concurrent.BlockingQueue<T>
        Specified by:
        remove in interface java.util.Collection<T>
        Overrides:
        remove in class RoundRobinQueue<T>
      • take

        public T take()
               throws java.lang.InterruptedException
        Remove an object from the queue.
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<T>
        Throws:
        java.lang.InterruptedException
      • drainTo

        public int drainTo​(java.util.Collection<? super T> c)
        Empty queue into a collection.
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<T>
      • drainTo

        public int drainTo​(java.util.Collection<? super T> c,
                           int max)
        Empty queue into a collection, stopping after max elements.
        Specified by:
        drainTo in interface java.util.concurrent.BlockingQueue<T>