12 |
|
|
13 |
|
/** |
14 |
|
* An unbounded {@linkplain BlockingQueue blocking queue} of |
15 |
< |
* <tt>Delayed</tt> elements, in which an element can only be taken |
15 |
> |
* {@code Delayed} elements, in which an element can only be taken |
16 |
|
* when its delay has expired. The <em>head</em> of the queue is that |
17 |
< |
* <tt>Delayed</tt> element whose delay expired furthest in the |
18 |
< |
* past. If no delay has expired there is no head and <tt>poll</tt> |
19 |
< |
* will return <tt>null</tt>. Expiration occurs when an element's |
20 |
< |
* <tt>getDelay(TimeUnit.NANOSECONDS)</tt> method returns a value less |
17 |
> |
* {@code Delayed} element whose delay expired furthest in the |
18 |
> |
* past. If no delay has expired there is no head and {@code poll} |
19 |
> |
* will return {@code null}. Expiration occurs when an element's |
20 |
> |
* {@code getDelay(TimeUnit.NANOSECONDS)} method returns a value less |
21 |
|
* than or equal to zero. Even though unexpired elements cannot be |
22 |
< |
* removed using <tt>take</tt> or <tt>poll</tt>, they are otherwise |
23 |
< |
* treated as normal elements. For example, the <tt>size</tt> method |
22 |
> |
* removed using {@code take} or {@code poll}, they are otherwise |
23 |
> |
* treated as normal elements. For example, the {@code size} method |
24 |
|
* returns the count of both expired and unexpired elements. |
25 |
|
* This queue does not permit null elements. |
26 |
|
* |
70 |
|
private final Condition available = lock.newCondition(); |
71 |
|
|
72 |
|
/** |
73 |
< |
* Creates a new <tt>DelayQueue</tt> that is initially empty. |
73 |
> |
* Creates a new {@code DelayQueue} that is initially empty. |
74 |
|
*/ |
75 |
|
public DelayQueue() {} |
76 |
|
|
77 |
|
/** |
78 |
< |
* Creates a <tt>DelayQueue</tt> initially containing the elements of the |
78 |
> |
* Creates a {@code DelayQueue} initially containing the elements of the |
79 |
|
* given collection of {@link Delayed} instances. |
80 |
|
* |
81 |
|
* @param c the collection of elements to initially contain |
90 |
|
* Inserts the specified element into this delay queue. |
91 |
|
* |
92 |
|
* @param e the element to add |
93 |
< |
* @return <tt>true</tt> (as specified by {@link Collection#add}) |
93 |
> |
* @return {@code true} (as specified by {@link Collection#add}) |
94 |
|
* @throws NullPointerException if the specified element is null |
95 |
|
*/ |
96 |
|
public boolean add(E e) { |
101 |
|
* Inserts the specified element into this delay queue. |
102 |
|
* |
103 |
|
* @param e the element to add |
104 |
< |
* @return <tt>true</tt> |
104 |
> |
* @return {@code true} |
105 |
|
* @throws NullPointerException if the specified element is null |
106 |
|
*/ |
107 |
|
public boolean offer(E e) { |
137 |
|
* @param e the element to add |
138 |
|
* @param timeout This parameter is ignored as the method never blocks |
139 |
|
* @param unit This parameter is ignored as the method never blocks |
140 |
< |
* @return <tt>true</tt> |
140 |
> |
* @return {@code true} |
141 |
|
* @throws NullPointerException {@inheritDoc} |
142 |
|
*/ |
143 |
|
public boolean offer(E e, long timeout, TimeUnit unit) { |
145 |
|
} |
146 |
|
|
147 |
|
/** |
148 |
< |
* Retrieves and removes the head of this queue, or returns <tt>null</tt> |
148 |
> |
* Retrieves and removes the head of this queue, or returns {@code null} |
149 |
|
* if this queue has no elements with an expired delay. |
150 |
|
* |
151 |
< |
* @return the head of this queue, or <tt>null</tt> if this |
151 |
> |
* @return the head of this queue, or {@code null} if this |
152 |
|
* queue has no elements with an expired delay |
153 |
|
*/ |
154 |
|
public E poll() { |
210 |
|
* until an element with an expired delay is available on this queue, |
211 |
|
* or the specified wait time expires. |
212 |
|
* |
213 |
< |
* @return the head of this queue, or <tt>null</tt> if the |
213 |
> |
* @return the head of this queue, or {@code null} if the |
214 |
|
* specified waiting time elapses before an element with |
215 |
|
* an expired delay becomes available |
216 |
|
* @throws InterruptedException {@inheritDoc} |
257 |
|
|
258 |
|
/** |
259 |
|
* Retrieves, but does not remove, the head of this queue, or |
260 |
< |
* returns <tt>null</tt> if this queue is empty. Unlike |
261 |
< |
* <tt>poll</tt>, if no expired elements are available in the queue, |
260 |
> |
* returns {@code null} if this queue is empty. Unlike |
261 |
> |
* {@code poll}, if no expired elements are available in the queue, |
262 |
|
* this method returns the element that will expire next, |
263 |
|
* if one exists. |
264 |
|
* |
265 |
< |
* @return the head of this queue, or <tt>null</tt> if this |
265 |
> |
* @return the head of this queue, or {@code null} if this |
266 |
|
* queue is empty. |
267 |
|
*/ |
268 |
|
public E peek() { |
367 |
|
} |
368 |
|
|
369 |
|
/** |
370 |
< |
* Always returns <tt>Integer.MAX_VALUE</tt> because |
371 |
< |
* a <tt>DelayQueue</tt> is not capacity constrained. |
370 |
> |
* Always returns {@code Integer.MAX_VALUE} because |
371 |
> |
* a {@code DelayQueue} is not capacity constrained. |
372 |
|
* |
373 |
< |
* @return <tt>Integer.MAX_VALUE</tt> |
373 |
> |
* @return {@code Integer.MAX_VALUE} |
374 |
|
*/ |
375 |
|
public int remainingCapacity() { |
376 |
|
return Integer.MAX_VALUE; |
410 |
|
* <p>If this queue fits in the specified array with room to spare |
411 |
|
* (i.e., the array has more elements than this queue), the element in |
412 |
|
* the array immediately following the end of the queue is set to |
413 |
< |
* <tt>null</tt>. |
413 |
> |
* {@code null}. |
414 |
|
* |
415 |
|
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
416 |
|
* array-based and collection-based APIs. Further, this method allows |
418 |
|
* under certain circumstances, be used to save allocation costs. |
419 |
|
* |
420 |
|
* <p>The following code can be used to dump a delay queue into a newly |
421 |
< |
* allocated array of <tt>Delayed</tt>: |
421 |
> |
* allocated array of {@code Delayed}: |
422 |
|
* |
423 |
|
* <pre> {@code Delayed[] a = q.toArray(new Delayed[0]);}</pre> |
424 |
|
* |
425 |
< |
* Note that <tt>toArray(new Object[0])</tt> is identical in function to |
426 |
< |
* <tt>toArray()</tt>. |
425 |
> |
* Note that {@code toArray(new Object[0])} is identical in function to |
426 |
> |
* {@code toArray()}. |
427 |
|
* |
428 |
|
* @param a the array into which the elements of the queue are to |
429 |
|
* be stored, if it is big enough; otherwise, a new array of the |