Top Description Constructors Methods
com.google.common.util.concurrent

public abstract Class ForwardingBlockingQueue<E>

extends ForwardingQueue<E>
implements BlockingQueue<E>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.BlockingQueue, java.util.Queue, java.util.Collection, java.lang.Iterable
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Type Parameters
<E>
the type of elements held in this collection
Imports
com.google.common.annotations.GwtIncompatible, .J2ktIncompatible, com.google.common.collect.ForwardingQueue, com.google.errorprone.annotations.CanIgnoreReturnValue, java.util.Collection, java.util.concurrent.BlockingQueue, .TimeUnit, javax.annotation.CheckForNull

A 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.

Author
Raimundo Mirisola
Since
4.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingBlockingQueue()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract BlockingQueue<E>
delegate()

Implements abstract com.google.common.collect.ForwardingQueue.delegate.

Returns the backing delegate instance that methods are forwarded to.
public int
drainTo(Collection<? super E>
the collection to transfer elements into
c
,
int
the maximum number of elements to transfer
maxElements
)

Implements java.util.concurrent.BlockingQueue.drainTo.

Removes at most the given number of available elements from this queue and adds them to the given collection.
public int
drainTo(Collection<? super E>
the collection to transfer elements into
c
)

Implements java.util.concurrent.BlockingQueue.drainTo.

Removes all available elements from this queue and adds them to the given collection.
public boolean
offer(E
the element to add
e
,
long
how long to wait before giving up, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Implements java.util.concurrent.BlockingQueue.offer.

Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.
public E
poll(long
how long to wait before giving up, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Implements java.util.concurrent.BlockingQueue.poll.

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
public void
put(E
the element to add
e
)

Implements java.util.concurrent.BlockingQueue.put.

Inserts the specified element into this queue, waiting if necessary for space to become available.
public int
remainingCapacity()

Implements java.util.concurrent.BlockingQueue.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.
public E
take()

Implements java.util.concurrent.BlockingQueue.take.

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
Inherited from com.google.common.collect.ForwardingQueue:
elementofferpeekpollremovestandardOfferstandardPeekstandardPoll

Constructor Detail

ForwardingBlockingQueueback to summary
protected ForwardingBlockingQueue()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract BlockingQueue<E> delegate()

Implements abstract com.google.common.collect.ForwardingQueue.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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.

Annotations
@Override
drainToback to summary
public int drainTo(Collection<? super E> c, int maxElements)

Implements java.util.concurrent.BlockingQueue.drainTo.

Doc from java.util.concurrent.BlockingQueue.drainTo.

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.

Parameters
c:Collection<? super E>

the collection to transfer elements into

maxElements:int

the maximum number of elements to transfer

Returns:int

the number of elements transferred

Annotations
@CanIgnoreReturnValue
@Override
drainToback to summary
public int drainTo(Collection<? super E> c)

Implements java.util.concurrent.BlockingQueue.drainTo.

Doc from java.util.concurrent.BlockingQueue.drainTo.

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.

Parameters
c:Collection<? super E>

the collection to transfer elements into

Returns:int

the number of elements transferred

Annotations
@CanIgnoreReturnValue
@Override
offerback to summary
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.offer.

Doc from java.util.concurrent.BlockingQueue.offer.

Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.

Parameters
e:E

the element to add

timeout:long

how long to wait before giving up, in units of unit

unit:TimeUnit

a TimeUnit determining how to interpret the timeout parameter

Returns:boolean

true if successful, or false if the specified waiting time elapses before space is available

Annotations
@CanIgnoreReturnValue
@Override
Exceptions
InterruptedException:
if interrupted while waiting
pollback to summary
public E poll(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.poll.

Doc from java.util.concurrent.BlockingQueue.poll.

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Parameters
timeout:long

how long to wait before giving up, in units of unit

unit:TimeUnit

a TimeUnit determining how to interpret the timeout parameter

Returns:E

the head of this queue, or null if the specified waiting time elapses before an element is available

Annotations
@CanIgnoreReturnValue
@Override
@CheckForNull
Exceptions
InterruptedException:
if interrupted while waiting
putback to summary
public void put(E e) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.put.

Doc from java.util.concurrent.BlockingQueue.put.

Inserts the specified element into this queue, waiting if necessary for space to become available.

Parameters
e:E

the element to add

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
remainingCapacityback to summary
public int remainingCapacity()

Implements java.util.concurrent.BlockingQueue.remainingCapacity.

Doc from java.util.concurrent.BlockingQueue.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.

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.

Returns:int

the remaining capacity

Annotations
@Override
takeback to summary
public E take() throws InterruptedException

Implements java.util.concurrent.BlockingQueue.take.

Doc from java.util.concurrent.BlockingQueue.take.

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Returns:E

the head of this queue

Annotations
@CanIgnoreReturnValue
@Override
Exceptions
InterruptedException:
if interrupted while waiting