13 |
|
* sometimes (using method {@link #transfer}) await receipt of |
14 |
|
* elements by consumers invoking {@code take} or {@code poll}, while |
15 |
|
* at other times enqueue elements (via method {@code put}) without |
16 |
< |
* waiting for receipt. {@linkplain |
17 |
< |
* #tryTransfer(Object) Non-blocking} and {@linkplain |
18 |
< |
* #tryTransfer(Object,long,TimeUnit) time-out} versions of {@code |
19 |
< |
* tryTransfer} are also available. A {@code TransferQueue} may also |
20 |
< |
* be queried, via {@link #hasWaitingConsumer}, whether there are any |
21 |
< |
* threads waiting for items, which is a converse analogy to a {@code |
22 |
< |
* peek} operation. |
16 |
> |
* waiting for receipt. |
17 |
> |
* {@linkplain #tryTransfer(Object) Non-blocking} and |
18 |
> |
* {@linkplain #tryTransfer(Object,long,TimeUnit) time-out} versions of |
19 |
> |
* {@code tryTransfer} are also available. |
20 |
> |
* A {@code TransferQueue} may also be queried, via {@link |
21 |
> |
* #hasWaitingConsumer}, whether there are any threads waiting for |
22 |
> |
* items, which is a converse analogy to a {@code peek} operation. |
23 |
|
* |
24 |
|
* <p>Like other blocking queues, a {@code TransferQueue} may be |
25 |
< |
* capacity bounded. If so, an attempted {@code transfer} operation |
26 |
< |
* may initially block waiting for available space, and/or |
27 |
< |
* subsequently block waiting for reception by a consumer. Note that |
28 |
< |
* in a queue with zero capacity, such as {@link SynchronousQueue}, |
29 |
< |
* {@code put} and {@code transfer} are effectively synonymous. |
25 |
> |
* capacity bounded. If so, an attempted transfer operation may |
26 |
> |
* initially block waiting for available space, and/or subsequently |
27 |
> |
* block waiting for reception by a consumer. Note that in a queue |
28 |
> |
* with zero capacity, such as {@link SynchronousQueue}, {@code put} |
29 |
> |
* and {@code transfer} are effectively synonymous. |
30 |
|
* |
31 |
|
* <p>This interface is a member of the |
32 |
|
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
38 |
|
*/ |
39 |
|
public interface TransferQueue<E> extends BlockingQueue<E> { |
40 |
|
/** |
41 |
< |
* Transfers the specified element immediately if there exists a |
42 |
< |
* consumer already waiting to receive it (in {@link #take} or |
43 |
< |
* timed {@link #poll(long,TimeUnit) poll}), otherwise returning |
44 |
< |
* {@code false} without enqueuing the element. |
41 |
> |
* Transfers the element to a waiting consumer immediately, if possible. |
42 |
> |
* |
43 |
> |
* <p>More precisely, transfers the specified element immediately |
44 |
> |
* if there exists a consumer already waiting to receive it (in |
45 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
46 |
> |
* otherwise returning {@code false} without enqueuing the element. |
47 |
|
* |
48 |
|
* @param e the element to transfer |
49 |
|
* @return {@code true} if the element was transferred, else |
57 |
|
boolean tryTransfer(E e); |
58 |
|
|
59 |
|
/** |
60 |
< |
* Inserts the specified element into this queue, waiting if |
61 |
< |
* necessary for space to become available and the element to be |
62 |
< |
* received by a consumer invoking {@code take} or {@code poll}. |
60 |
> |
* Transfers the element to a consumer, waiting if necessary to do so. |
61 |
> |
* |
62 |
> |
* <p>More precisely, transfers the specified element immediately |
63 |
> |
* if there exists a consumer already waiting to receive it (in |
64 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
65 |
> |
* else waits until the element is received by a consumer. |
66 |
|
* |
67 |
|
* @param e the element to transfer |
68 |
|
* @throws InterruptedException if interrupted while waiting, |
69 |
< |
* in which case the element is not enqueued |
69 |
> |
* in which case the element is not left enqueued |
70 |
|
* @throws ClassCastException if the class of the specified element |
71 |
|
* prevents it from being added to this queue |
72 |
|
* @throws NullPointerException if the specified element is null |
76 |
|
void transfer(E e) throws InterruptedException; |
77 |
|
|
78 |
|
/** |
79 |
< |
* Inserts the specified element into this queue, waiting up to |
80 |
< |
* the specified wait time if necessary for space to become |
81 |
< |
* available and the element to be received by a consumer invoking |
82 |
< |
* {@code take} or {@code poll}. |
79 |
> |
* Transfers the element to a consumer if it is possible to do so |
80 |
> |
* before the timeout elapses. |
81 |
> |
* |
82 |
> |
* <p>More precisely, transfers the specified element immediately |
83 |
> |
* if there exists a consumer already waiting to receive it (in |
84 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
85 |
> |
* else waits until the element is received by a consumer, |
86 |
> |
* returning {@code false} if the specified wait time elapses |
87 |
> |
* before the element can be transferred. |
88 |
|
* |
89 |
|
* @param e the element to transfer |
90 |
|
* @param timeout how long to wait before giving up, in units of |
93 |
|
* {@code timeout} parameter |
94 |
|
* @return {@code true} if successful, or {@code false} if |
95 |
|
* the specified waiting time elapses before completion, |
96 |
< |
* in which case the element is not enqueued |
96 |
> |
* in which case the element is not left enqueued |
97 |
|
* @throws InterruptedException if interrupted while waiting, |
98 |
< |
* in which case the element is not enqueued |
98 |
> |
* in which case the element is not left enqueued |
99 |
|
* @throws ClassCastException if the class of the specified element |
100 |
|
* prevents it from being added to this queue |
101 |
|
* @throws NullPointerException if the specified element is null |