ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/TransferQueue.java
(Generate patch)

Comparing jsr166/src/jsr166y/TransferQueue.java (file contents):
Revision 1.2 by dl, Wed Jul 11 14:30:37 2007 UTC vs.
Revision 1.6 by jsr166, Mon Jul 27 00:01:47 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines