public abstract class ForwardingBlockingDeque<E> extends ForwardingDeque<E> implements BlockingDeque<E>
BlockingDeque which forwards all its method calls to another BlockingDeque.
Subclasses should override one or more methods to modify the behavior of the backing deque as
desired per the decorator pattern.
Warning: The methods of ForwardingBlockingDeque forward
indiscriminately to the methods of the delegate. For example, overriding ForwardingCollection.add(E)
alone will not change the behaviour of offer(E, long, java.util.concurrent.TimeUnit) which can lead to unexpected
behaviour. In this case, you should override offer as well, either providing your own
implementation, or delegating to the provided standardOffer method.
The standard methods are not guaranteed to be thread-safe, even when all of the methods
that they depend on are thread-safe.
| Modifier | Constructor and Description |
|---|---|
protected |
ForwardingBlockingDeque()
Constructor for use by subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract BlockingDeque<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 the queue represented by this deque
(in other words, at the tail of this deque), waiting up to the
specified wait time if necessary for space to become available.
|
boolean |
offerFirst(E e,
long timeout,
TimeUnit unit)
Inserts the specified element at the front of this deque,
waiting up to the specified wait time if necessary for space to
become available.
|
boolean |
offerLast(E e,
long timeout,
TimeUnit unit)
Inserts the specified element at the end of this deque,
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 the queue represented by this deque
(in other words, the first element of this deque), waiting up to the
specified wait time if necessary for an element to become available.
|
E |
pollFirst(long timeout,
TimeUnit unit)
Retrieves and removes the first element of this deque, waiting
up to the specified wait time if necessary for an element to
become available.
|
E |
pollLast(long timeout,
TimeUnit unit)
Retrieves and removes the last element of this deque, waiting
up to the specified wait time if necessary for an element to
become available.
|
void |
put(E e)
Inserts the specified element into the queue represented by this deque
(in other words, at the tail of this deque), waiting if necessary for
space to become available.
|
void |
putFirst(E e)
Inserts the specified element at the front of this deque,
waiting if necessary for space to become available.
|
void |
putLast(E e)
Inserts the specified element at the end of this deque,
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 the queue represented by this deque
(in other words, the first element of this deque), waiting if
necessary until an element becomes available.
|
E |
takeFirst()
Retrieves and removes the first element of this deque, waiting
if necessary until an element becomes available.
|
E |
takeLast()
Retrieves and removes the last element of this deque, waiting
if necessary until an element becomes available.
|
addFirst, addLast, descendingIterator, getFirst, getLast, offerFirst, offerLast, peekFirst, peekLast, pollFirst, pollLast, pop, push, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrenceelement, offer, peek, poll, remove, standardOffer, standardPeek, standardPolladd, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArraytoStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitadd, addFirst, addLast, contains, element, iterator, offer, offerFirst, offerLast, peek, poll, push, remove, remove, removeFirstOccurrence, removeLastOccurrence, sizedescendingIterator, getFirst, getLast, peekFirst, peekLast, pollFirst, pollLast, pop, removeFirst, removeLastprotected ForwardingBlockingDeque()
protected abstract BlockingDeque<E> delegate()
ForwardingObjectForwardingSet.delegate(). Concrete subclasses override this method to supply
the instance being decorated.delegate in class ForwardingDeque<E>public int remainingCapacity()
java.util.concurrent.BlockingQueueNote 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 void putFirst(E e) throws InterruptedException
java.util.concurrent.BlockingDequeputFirst in interface BlockingDeque<E>e - the element to addInterruptedException - if interrupted while waitingpublic void putLast(E e) throws InterruptedException
java.util.concurrent.BlockingDequeputLast in interface BlockingDeque<E>e - the element to addInterruptedException - if interrupted while waitingpublic boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequeofferFirst in interface BlockingDeque<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 boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequeofferLast in interface BlockingDeque<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 takeFirst() throws InterruptedException
java.util.concurrent.BlockingDequetakeFirst in interface BlockingDeque<E>InterruptedException - if interrupted while waitingpublic E takeLast() throws InterruptedException
java.util.concurrent.BlockingDequetakeLast in interface BlockingDeque<E>InterruptedException - if interrupted while waitingpublic E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequepollFirst in interface BlockingDeque<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 E pollLast(long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequepollLast in interface BlockingDeque<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.BlockingDequeThis method is equivalent to putLast.
put in interface BlockingDeque<E>put in interface BlockingQueue<E>e - the element to addInterruptedException - if interrupted while waitingpublic boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequeThis method is equivalent to
offerLast.
offer in interface BlockingDeque<E>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 take() throws InterruptedException
java.util.concurrent.BlockingDequeThis method is equivalent to takeFirst.
take in interface BlockingDeque<E>take in interface BlockingQueue<E>InterruptedException - if interrupted while waitingpublic E poll(long timeout, TimeUnit unit) throws InterruptedException
java.util.concurrent.BlockingDequeThis method is equivalent to
pollFirst.
poll in interface BlockingDeque<E>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 int drainTo(Collection<? super E> c)
java.util.concurrent.BlockingQueuedrainTo in interface BlockingQueue<E>c - the collection to transfer elements intopublic int drainTo(Collection<? super E> c, int maxElements)
java.util.concurrent.BlockingQueuedrainTo in interface BlockingQueue<E>c - the collection to transfer elements intomaxElements - the maximum number of elements to transferCopyright © 2010-2014. All Rights Reserved.