9 |
|
|
10 |
|
/** |
11 |
|
* A {@link BlockingQueue} in which producers may wait for consumers |
12 |
< |
* to receive elements. A <tt>TransferQueue</tt> may be useful for |
12 |
> |
* to receive elements. A {@code TransferQueue} may be useful for |
13 |
|
* example in message passing applications in which producers |
14 |
< |
* sometimes (using method <tt>transfer</tt>) await receipt of |
15 |
< |
* elements by consumers invoking <tt>take</tt> or <tt>poll</tt>, |
16 |
< |
* while at other times enqueue elements (via method <tt>put</tt>) |
14 |
> |
* sometimes (using method {@code transfer}) await receipt of |
15 |
> |
* elements by consumers invoking {@code take} or {@code poll}, |
16 |
> |
* while at other times enqueue elements (via method {@code put}) |
17 |
|
* without waiting for receipt. Non-blocking and time-out versions of |
18 |
< |
* <tt>tryTransfer</tt> are also available. A TransferQueue may also |
19 |
< |
* be queried via <tt>hasWaitingConsumer</tt> whether there are any |
18 |
> |
* {@code tryTransfer} are also available. A TransferQueue may also |
19 |
> |
* be queried via {@code hasWaitingConsumer} whether there are any |
20 |
|
* threads waiting for items, which is a converse analogy to a |
21 |
< |
* <tt>peek</tt> operation |
21 |
> |
* {@code peek} operation. |
22 |
|
* |
23 |
< |
* <p>Like any <tt>BlockingQueue</tt>, a <tt>TransferQueue</tt> may be |
24 |
< |
* capacity bounded. If so, an attempted <tt>transfer</tt> operation |
23 |
> |
* <p>Like any {@code BlockingQueue}, a {@code TransferQueue} may be |
24 |
> |
* capacity bounded. If so, an attempted {@code transfer} operation |
25 |
|
* may initially block waiting for available space, and/or |
26 |
|
* subsequently block waiting for reception by a consumer. Note that |
27 |
|
* in a queue with zero capacity, such as {@link SynchronousQueue}, |
28 |
< |
* <tt>put</tt> and <tt>transfer</tt> are effectively synonymous. |
28 |
> |
* {@code put} and {@code transfer} are effectively synonymous. |
29 |
|
* |
30 |
|
* <p>This interface is a member of the |
31 |
|
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
38 |
|
public interface TransferQueue<E> extends BlockingQueue<E> { |
39 |
|
/** |
40 |
|
* Transfers the specified element if there exists a consumer |
41 |
< |
* already waiting to receive it, otherwise returning <tt>false</tt> |
41 |
> |
* already waiting to receive it, otherwise returning {@code false} |
42 |
|
* without enqueuing the element. |
43 |
|
* |
44 |
|
* @param e the element to transfer |
45 |
< |
* @return <tt>true</tt> if the element was transferred, else |
46 |
< |
* <tt>false</tt> |
45 |
> |
* @return {@code true} if the element was transferred, else |
46 |
> |
* {@code false} |
47 |
|
* @throws ClassCastException if the class of the specified element |
48 |
|
* prevents it from being added to this queue |
49 |
|
* @throws NullPointerException if the specified element is null |
55 |
|
/** |
56 |
|
* Inserts the specified element into this queue, waiting if |
57 |
|
* necessary for space to become available and the element to be |
58 |
< |
* dequeued by a consumer invoking <tt>take</tt> or <tt>poll</tt>. |
58 |
> |
* dequeued by a consumer invoking {@code take} or {@code poll}. |
59 |
|
* |
60 |
|
* @param e the element to transfer |
61 |
|
* @throws InterruptedException if interrupted while waiting, |
72 |
|
* Inserts the specified element into this queue, waiting up to |
73 |
|
* the specified wait time if necessary for space to become |
74 |
|
* available and the element to be dequeued by a consumer invoking |
75 |
< |
* <tt>take</tt> or <tt>poll</tt>. |
75 |
> |
* {@code take} or {@code poll}. |
76 |
|
* |
77 |
|
* @param e the element to transfer |
78 |
|
* @param timeout how long to wait before giving up, in units of |
79 |
< |
* <tt>unit</tt> |
80 |
< |
* @param unit a <tt>TimeUnit</tt> determining how to interpret the |
81 |
< |
* <tt>timeout</tt> parameter |
82 |
< |
* @return <tt>true</tt> if successful, or <tt>false</tt> if |
79 |
> |
* {@code unit} |
80 |
> |
* @param unit a {@code TimeUnit} determining how to interpret the |
81 |
> |
* {@code timeout} parameter |
82 |
> |
* @return {@code true} if successful, or {@code false} if |
83 |
|
* the specified waiting time elapses before completion, |
84 |
|
* in which case the element is not enqueued. |
85 |
|
* @throws InterruptedException if interrupted while waiting, |
94 |
|
throws InterruptedException; |
95 |
|
|
96 |
|
/** |
97 |
< |
* Returns true if there is at least one consumer waiting to |
98 |
< |
* dequeue an element via <tt>take</tt> or <tt>poll</tt>. The |
99 |
< |
* return value represents a momentary state of affairs. |
100 |
< |
* @return true if there is at least one waiting consumer. |
97 |
> |
* Returns {@code true} if there is at least one consumer waiting |
98 |
> |
* to dequeue an element via {@code take} or {@code poll}. |
99 |
> |
* The return value represents a momentary state of affairs. |
100 |
> |
* |
101 |
> |
* @return {@code true} if there is at least one waiting consumer |
102 |
|
*/ |
103 |
|
boolean hasWaitingConsumer(); |
104 |
|
|
104 |
– |
|
105 |
|
/** |
106 |
|
* Returns an estimate of the number of consumers waiting to |
107 |
< |
* dequeue elements via <tt>take</tt> or <tt>poll</tt>. The return |
107 |
> |
* dequeue elements via {@code take} or {@code poll}. The return |
108 |
|
* value is an approximation of a momentary state of affairs, that |
109 |
|
* may be inaccurate if consumers have completed or given up |
110 |
|
* waiting. The value may be useful for monitoring and heuristics, |
111 |
|
* but not for synchronization control. Implementations of this |
112 |
|
* method are likely to be noticeably slower than those for |
113 |
< |
* <tt>hasWaitingConsumer</tt>. |
113 |
> |
* {@link #hasWaitingConsumer}. |
114 |
> |
* |
115 |
|
* @return the number of consumers waiting to dequeue elements |
116 |
|
*/ |
117 |
|
int getWaitingConsumerCount(); |