Class ForwardingBlockingQueue<E>
- java.lang.Object
- 
- com.google.common.collect.ForwardingObject
- 
- com.google.common.collect.ForwardingCollection<E>
- 
- com.google.common.collect.ForwardingQueue<E>
- 
- com.google.common.util.concurrent.ForwardingBlockingQueue<E>
 
 
 
 
- 
- Type Parameters:
- E- the type of elements held in this collection
 - All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- BlockingQueue<E>,- Queue<E>
 
 @CanIgnoreReturnValue @GwtIncompatible public abstract class ForwardingBlockingQueue<E> extends ForwardingQueue<E> implements BlockingQueue<E> ABlockingQueuewhich forwards all its method calls to anotherBlockingQueue. Subclasses should override one or more methods to modify the behavior of the backing collection as desired per the decorator pattern.defaultmethod warning: This class does not forward calls todefaultmethods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingBlockingQueue.- Since:
- 4.0
- Author:
- Raimundo Mirisola
 
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedForwardingBlockingQueue()Constructor for use by subclasses.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract BlockingQueue<E>delegate()Returns the backing delegate instance that methods are forwarded to.intdrainTo(Collection<? super E> c)Removes all available elements from this queue and adds them to the given collection.intdrainTo(Collection<? super E> c, int maxElements)Removes at most the given number of available elements from this queue and adds them to the given collection.booleanoffer(E e, long timeout, TimeUnit unit)Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.Epoll(long timeout, 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.voidput(E e)Inserts the specified element into this queue, waiting if necessary for space to become available.intremainingCapacity()Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, orInteger.MAX_VALUEif there is no intrinsic limit.Etake()Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.- 
Methods inherited from class com.google.common.collect.ForwardingQueueelement, offer, peek, poll, remove, standardOffer, standardPeek, standardPoll
 - 
Methods inherited from class com.google.common.collect.ForwardingCollectionadd, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
 - 
Methods inherited from class com.google.common.collect.ForwardingObjecttoString
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.util.concurrent.BlockingQueueadd, contains, offer, remove
 - 
Methods inherited from interface java.util.CollectionaddAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
 
- 
 
- 
- 
- 
Constructor Detail- 
ForwardingBlockingQueueprotected ForwardingBlockingQueue() Constructor for use by subclasses.
 
- 
 - 
Method Detail- 
delegateprotected abstract BlockingQueue<E> delegate() Description copied from class:ForwardingObjectReturns 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 asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
- delegatein class- ForwardingQueue<E>
 
 - 
drainTopublic int drainTo(Collection<? super E> c, int maxElements) Description copied from interface:java.util.concurrent.BlockingQueueRemoves 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 collectioncmay result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result inIllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.- Specified by:
- drainToin interface- BlockingQueue<E>
- Parameters:
- c- the collection to transfer elements into
- maxElements- the maximum number of elements to transfer
- Returns:
- the number of elements transferred
 
 - 
drainTopublic int drainTo(Collection<? super E> c) Description copied from interface:java.util.concurrent.BlockingQueueRemoves 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 collectioncmay result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result inIllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.- Specified by:
- drainToin interface- BlockingQueue<E>
- Parameters:
- c- the collection to transfer elements into
- Returns:
- the number of elements transferred
 
 - 
offerpublic boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException Description copied from interface:java.util.concurrent.BlockingQueueInserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.- Specified by:
- offerin interface- BlockingQueue<E>
- Parameters:
- e- the element to add
- timeout- how long to wait before giving up, in units of- unit
- unit- a- TimeUnitdetermining how to interpret the- timeoutparameter
- Returns:
- trueif successful, or- falseif the specified waiting time elapses before space is available
- Throws:
- InterruptedException- if interrupted while waiting
 
 - 
pollpublic E poll(long timeout, TimeUnit unit) throws InterruptedException Description copied from interface:java.util.concurrent.BlockingQueueRetrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.- Specified by:
- pollin interface- BlockingQueue<E>
- Parameters:
- timeout- how long to wait before giving up, in units of- unit
- unit- a- TimeUnitdetermining how to interpret the- timeoutparameter
- Returns:
- the head of this queue, or nullif the specified waiting time elapses before an element is available
- Throws:
- InterruptedException- if interrupted while waiting
 
 - 
putpublic void put(E e) throws InterruptedException Description copied from interface:java.util.concurrent.BlockingQueueInserts the specified element into this queue, waiting if necessary for space to become available.- Specified by:
- putin interface- BlockingQueue<E>
- Parameters:
- e- the element to add
- Throws:
- InterruptedException- if interrupted while waiting
 
 - 
remainingCapacitypublic int remainingCapacity() Description copied from interface:java.util.concurrent.BlockingQueueReturns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, orInteger.MAX_VALUEif there is no intrinsic limit.Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacitybecause it may be the case that another thread is about to insert or remove an element.- Specified by:
- remainingCapacityin interface- BlockingQueue<E>
- Returns:
- the remaining capacity
 
 - 
takepublic E take() throws InterruptedException Description copied from interface:java.util.concurrent.BlockingQueueRetrieves and removes the head of this queue, waiting if necessary until an element becomes available.- Specified by:
- takein interface- BlockingQueue<E>
- Returns:
- the head of this queue
- Throws:
- InterruptedException- if interrupted while waiting
 
 
- 
 
-