# TransferQueue

public interface **TransferQueue** implements [BlockingQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html)\<E\>

|---|---|---|
| Known Indirect Subclasses [LinkedTransferQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/LinkedTransferQueue.html)\<E\> |---|---| | [LinkedTransferQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/LinkedTransferQueue.html)\<E\> | An unbounded `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html` based on linked nodes. | |||

A `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html` in which producers may wait for consumers
to receive elements. A `TransferQueue` may be useful for
example in message passing applications in which producers
sometimes (using method `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#transfer(E)`) await receipt of
elements by consumers invoking `take` or `poll`, while
at other times enqueue elements (via method `put`) without
waiting for receipt.
{@linkplain #tryTransfer(Object) Non-blocking} and
{@linkplain #tryTransfer(Object,long,TimeUnit) time-out} versions of
`tryTransfer` are also available.
A `TransferQueue` may also be queried, via `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#hasWaitingConsumer()`, whether there are any threads waiting for
items, which is a converse analogy to a `peek` operation.

Like other blocking queues, a `TransferQueue` may be
capacity bounded. If so, an attempted transfer operation may
initially block waiting for available space, and/or subsequently
block waiting for reception by a consumer. Note that in a queue
with zero capacity, such as `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/SynchronousQueue.html`, `put`
and `transfer` are effectively synonymous.

### Public Method Summary

|---|---|
| abstract int | [getWaitingConsumerCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#getWaitingConsumerCount())() Returns an estimate of the number of consumers waiting to receive elements via `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`. |
| abstract boolean | [hasWaitingConsumer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#hasWaitingConsumer())() Returns `true` if there is at least one consumer waiting to receive an element via `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`. |
| abstract void | [transfer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#transfer(E))(E e) Transfers the element to a consumer, waiting if necessary to do so. |
| abstract boolean | [tryTransfer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#tryTransfer(E))(E e) Transfers the element to a waiting consumer immediately, if possible. |
| abstract boolean | [tryTransfer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#tryTransfer(E,%20long,%20java.util.concurrent.TimeUnit))(E e, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit) Transfers the element to a consumer if it is possible to do so before the timeout elapses. |

### Inherited Method Summary

From interface [java.util.concurrent.BlockingQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html)

|---|---|
| abstract boolean | [add](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#add(E))(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and throwing an `IllegalStateException` if no space is currently available. |
| abstract boolean | [contains](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#contains(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Returns `true` if this queue contains the specified element. |
| abstract int | [drainTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#drainTo(java.util.Collection<?%20super%20E>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<? super E\> c) Removes all available elements from this queue and adds them to the given collection. |
| abstract int | [drainTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#drainTo(java.util.Collection<?%20super%20E>,%20int))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<? super E\> c, int maxElements) Removes at most the given number of available elements from this queue and adds them to the given collection. |
| abstract boolean | [offer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#offer(E))(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and `false` if no space is currently available. |
| abstract boolean | [offer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#offer(E,%20long,%20java.util.concurrent.TimeUnit))(E e, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit) Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available. |
| abstract E | [poll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit))(long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit) Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available. |
| abstract void | [put](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#put(E))(E e) Inserts the specified element into this queue, waiting if necessary for space to become available. |
| abstract int | [remainingCapacity](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#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. |
| abstract boolean | [remove](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#remove(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Removes a single instance of the specified element from this queue, if it is present. |
| abstract E | [take](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take())() Retrieves and removes the head of this queue, waiting if necessary until an element becomes available. |

From interface [java.util.Queue](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html)

|---|---|
| abstract boolean | [add](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#add(E))(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and throwing an `IllegalStateException` if no space is currently available. |
| abstract E | [element](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#element())() Retrieves, but does not remove, the head of this queue. |
| abstract boolean | [offer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#offer(E))(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. |
| abstract E | [peek](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#peek())() Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty. |
| abstract E | [poll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#poll())() Retrieves and removes the head of this queue, or returns `null` if this queue is empty. |
| abstract E | [remove](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Queue.html#remove())() Retrieves and removes the head of this queue. |

From interface [java.util.Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)

|---|---|
| abstract boolean | [add](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#add(E))(E e) Ensures that this collection contains the specified element (optional operation). |
| abstract boolean | [addAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#addAll(java.util.Collection<?%20extends%20E>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<? extends E\> c) Adds all of the elements in the specified collection to this collection (optional operation). |
| abstract void | [clear](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#clear())() Removes all of the elements from this collection (optional operation). |
| abstract boolean | [contains](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#contains(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Returns true if this collection contains the specified element. |
| abstract boolean | [containsAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#containsAll(java.util.Collection<?>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<?\> c) Returns true if this collection contains all of the elements in the specified collection. |
| abstract boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Compares the specified object with this collection for equality. |
| abstract int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#hashCode())() Returns the hash code value for this collection. |
| abstract boolean | [isEmpty](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#isEmpty())() Returns true if this collection contains no elements. |
| abstract [Iterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Iterator.html)\<E\> | [iterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#iterator())() Returns an iterator over the elements in this collection. |
| [Stream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/stream/Stream.html)\<E\> | [parallelStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#parallelStream())() Returns a possibly parallel `Stream` with this collection as its source. |
| abstract boolean | [remove](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#remove(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) o) Removes a single instance of the specified element from this collection, if it is present (optional operation). |
| abstract boolean | [removeAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#removeAll(java.util.Collection<?>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<?\> c) Removes all of this collection's elements that are also contained in the specified collection (optional operation). |
| boolean | [removeIf](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#removeIf(java.util.function.Predicate<?%20super%20E>))([Predicate](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/Predicate.html)\<? super E\> filter) Removes all of the elements of this collection that satisfy the given predicate. |
| abstract boolean | [retainAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#retainAll(java.util.Collection<?>))([Collection](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html)\<?\> c) Retains only the elements in this collection that are contained in the specified collection (optional operation). |
| abstract int | [size](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#size())() Returns the number of elements in this collection. |
| [Spliterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Spliterator.html)\<E\> | [spliterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#spliterator())() Creates a `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Spliterator.html` over the elements in this collection. |
| [Stream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/stream/Stream.html)\<E\> | [stream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#stream())() Returns a sequential `Stream` with this collection as its source. |
| abstract \<T\> T\[\] | [toArray](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#toArray(T[]))(T\[\] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
| abstract [Object\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [toArray](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html#toArray())() Returns an array containing all of the elements in this collection. |

From interface [java.lang.Iterable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Iterable.html)

|---|---|
| void | [forEach](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Iterable.html#forEach(java.util.function.Consumer<?%20super%20T>))([Consumer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/Consumer.html)\<? super T\> action) Performs the given action for each element of the `Iterable` until all elements have been processed or the action throws an exception. |
| abstract [Iterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Iterator.html)\<E\> | [iterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Iterable.html#iterator())() Returns an iterator over elements of type `T`. |
| [Spliterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Spliterator.html)\<E\> | [spliterator](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Iterable.html#spliterator())() Creates a `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Spliterator.html` over the elements described by this `Iterable`. |

## Public Methods

#### public abstract int
**getWaitingConsumerCount**
()

Returns an estimate of the number of consumers waiting to
receive elements via `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`. The return value is an
approximation of a momentary state of affairs, that may be
inaccurate if consumers have completed or given up waiting.
The value may be useful for monitoring and heuristics, but
not for synchronization control. Implementations of this
method are likely to be noticeably slower than those for
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TransferQueue.html#hasWaitingConsumer()`.

##### Returns

- the number of consumers waiting to receive elements

#### public abstract boolean
**hasWaitingConsumer**
()

Returns `true` if there is at least one consumer waiting
to receive an element via `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or
timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`.
The return value represents a momentary state of affairs.

##### Returns

- `true` if there is at least one waiting consumer

#### public abstract void
**transfer**
(E e)

Transfers the element to a consumer, waiting if necessary to do so.

More precisely, transfers the specified element immediately
if there exists a consumer already waiting to receive it (in
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`),
else waits until the element is received by a consumer.

##### Parameters

| e | the element to transfer |
|---|---|

##### Throws

| [InterruptedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/InterruptedException.html) | if interrupted while waiting, in which case the element is not left enqueued |
| [ClassCastException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ClassCastException.html) | if the class of the specified element prevents it from being added to this queue |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified element is null |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if some property of the specified element prevents it from being added to this queue |
|---|---|

#### public abstract boolean
**tryTransfer**
(E e)

Transfers the element to a waiting consumer immediately, if possible.

More precisely, transfers the specified element immediately
if there exists a consumer already waiting to receive it (in
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`),
otherwise returning `false` without enqueuing the element.

##### Parameters

| e | the element to transfer |
|---|---|

##### Returns

- `true` if the element was transferred, else `false`

##### Throws

| [ClassCastException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ClassCastException.html) | if the class of the specified element prevents it from being added to this queue |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified element is null |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if some property of the specified element prevents it from being added to this queue |
|---|---|

#### public abstract boolean
**tryTransfer**
(E e, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit)

Transfers the element to a consumer if it is possible to do so
before the timeout elapses.

More precisely, transfers the specified element immediately
if there exists a consumer already waiting to receive it (in
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#take()` or timed `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/BlockingQueue.html#poll(long,%20java.util.concurrent.TimeUnit)`),
else waits until the element is received by a consumer,
returning `false` if the specified wait time elapses
before the element can be transferred.

##### Parameters

| e | the element to transfer |
| timeout | how long to wait before giving up, in units of `unit` |
| unit | a `TimeUnit` determining how to interpret the `timeout` parameter |
|---|---|

##### Returns

- `true` if successful, or `false` if the specified waiting time elapses before completion, in which case the element is not left enqueued

##### Throws

| [InterruptedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/InterruptedException.html) | if interrupted while waiting, in which case the element is not left enqueued |
| [ClassCastException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ClassCastException.html) | if the class of the specified element prevents it from being added to this queue |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if the specified element is null |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if some property of the specified element prevents it from being added to this queue |
|---|---|