E
- the type of elements held in this collection@CanIgnoreReturnValue @GwtIncompatible public abstract class ForwardingBlockingQueue<E> extends ForwardingQueue<E> implements BlockingQueue<E>
BlockingQueue
which forwards all its method calls to another BlockingQueue
.
Subclasses should override one or more methods to modify the behavior of the backing collection
as desired per the decorator
pattern.
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
.
Modifier | Constructor and Description |
---|---|
protected |
ForwardingBlockingQueue()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract BlockingQueue<E> |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
int |
drainTo(Collection<? super E> c)
Removes all available elements from this queue and adds them
to the given collection.
|
int |
drainTo(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.
|
boolean |
offer(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.
|
E |
poll(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.
|
void |
put(E e)
Inserts the specified element into this queue, waiting if necessary
for space to become available.
|
int |
remainingCapacity()
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. |
E |
take()
Retrieves and removes the head of this queue, waiting if necessary
until an element becomes available.
|
element, offer, peek, poll, remove, standardOffer, standardPeek, standardPoll
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add, contains, offer, remove
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
protected ForwardingBlockingQueue()
protected abstract BlockingQueue<E> delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply the
instance being decorated.delegate
in class ForwardingQueue<E>
public int drainTo(Collection<? super E> c, int maxElements)
java.util.concurrent.BlockingQueue
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.drainTo
in interface BlockingQueue<E>
c
- the collection to transfer elements intomaxElements
- the maximum number of elements to transferpublic int drainTo(Collection<? super E> c)
java.util.concurrent.BlockingQueue
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.drainTo
in interface BlockingQueue<E>
c
- the collection to transfer elements intopublic boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingQueue
offer
in interface BlockingQueue<E>
e
- the element to addtimeout
- how long to wait before giving up, in units of
unit
unit
- a TimeUnit
determining how to interpret the
timeout
parametertrue
if successful, or false
if
the specified waiting time elapses before space is availableInterruptedException
- if interrupted while waitingpublic E poll(long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingQueue
poll
in interface BlockingQueue<E>
timeout
- how long to wait before giving up, in units of
unit
unit
- a TimeUnit
determining how to interpret the
timeout
parameternull
if the
specified waiting time elapses before an element is availableInterruptedException
- if interrupted while waitingpublic void put(E e) throws InterruptedException
java.util.concurrent.BlockingQueue
put
in interface BlockingQueue<E>
e
- the element to addInterruptedException
- if interrupted while waitingpublic int remainingCapacity()
java.util.concurrent.BlockingQueue
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.
remainingCapacity
in interface BlockingQueue<E>
public E take() throws InterruptedException
java.util.concurrent.BlockingQueue
take
in interface BlockingQueue<E>
InterruptedException
- if interrupted while waitingCopyright © 2010–2017. All rights reserved.