Class ForwardingBlockingQueue<E>

  • Type Parameters:
    E - the type of elements held in this collection
    All Implemented Interfaces:
    <E>, <E>, <E>, <E>

    @GwtIncompatible
    public abstract class ForwardingBlockingQueue<E>
    extends ForwardingQueue<E>
    implements <E>
    A which forwards all its method calls to another . Subclasses should override one or more methods to modify the behavior of the backing collection as desired per the .

    default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingBlockingQueue.

    Since:
    4.0
    Author:
    Raimundo Mirisola
    • Method Detail

      • delegate

        protected abstract <Edelegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingQueue<E>
      • drainTo

        public int <? super E> c,
                           int maxElements)
        Description copied from interface: 
        Removes at most the given number of available elements from this queue and adds them to the given collection. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
        Specified by:
         in interface <E>
        Parameters:
        c - the collection to transfer elements into
        maxElements - the maximum number of elements to transfer
        Returns:
        the number of elements transferred
      • drainTo

        public int <? super E> c)
        Description copied from interface: 
        Removes all available elements from this queue and adds them to the given collection. This operation may be more efficient than repeatedly polling this queue. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
        Specified by:
         in interface <E>
        Parameters:
        c - the collection to transfer elements into
        Returns:
        the number of elements transferred
      • offer

        public boolean offer​(E e,
                             long timeout,
                              unit)
                      throws 
        Description copied from interface: 
        Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.
        Specified by:
         in interface <E>
        Parameters:
        e - the element to add
        timeout - how long to wait before giving up, in units of unit
        unit - a TimeUnit determining how to interpret the timeout parameter
        Returns:
        true if successful, or false if the specified waiting time elapses before space is available
        Throws:
        - if interrupted while waiting
      • poll

        public E poll​(long timeout,
                       unit)
               throws 
        Description copied from interface: 
        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:
         in interface <E>
        Parameters:
        timeout - how long to wait before giving up, in units of unit
        unit - a TimeUnit determining how to interpret the timeout parameter
        Returns:
        the head of this queue, or null if the specified waiting time elapses before an element is available
        Throws:
        - if interrupted while waiting
      • put

        public void put​(E e)
                 throws 
        Description copied from interface: 
        Inserts the specified element into this queue, waiting if necessary for space to become available.
        Specified by:
         in interface <E>
        Parameters:
        e - the element to add
        Throws:
        - if interrupted while waiting
      • remainingCapacity

        public int remainingCapacity()
        Description copied from interface: 
        Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, or Integer.MAX_VALUE if there is no intrinsic limit.

        Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacity because it may be the case that another thread is about to insert or remove an element.

        Specified by:
         in interface <E>
        Returns:
        the remaining capacity
      • take

        public E take()
               throws 
        Description copied from interface: 
        Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
        Specified by:
         in interface <E>
        Returns:
        the head of this queue
        Throws:
        - if interrupted while waiting