E
- the type of elements held in this collectionpublic 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.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
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
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
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
unitunit
- a TimeUnit determining how to interpret the
timeout parameterInterruptedException
- 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
unitunit
- a TimeUnit determining how to interpret the
timeout parameterInterruptedException
- 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
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-2013. All Rights Reserved.