edu.emory.mathcs.backport.java.util.concurrent
public class DelayQueue extends AbstractQueue implements BlockingQueue
This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.
This class is a member of the Java Collections Framework.
Since: 1.5
Constructor Summary | |
---|---|
DelayQueue()
Creates a new DelayQueue that is initially empty. | |
DelayQueue(Collection c)
Creates a DelayQueue initially containing the elements of the
given collection of Delayed instances.
|
Method Summary | |
---|---|
boolean | add(Object e)
Inserts the specified element into this delay queue.
|
void | clear()
Atomically removes all of the elements from this delay queue.
|
int | drainTo(Collection c) |
int | drainTo(Collection c, int maxElements) |
Iterator | iterator()
Returns an iterator over all the elements (both expired and
unexpired) in this queue. |
boolean | offer(Object e)
Inserts the specified element into this delay queue.
|
boolean | offer(Object e, long timeout, TimeUnit unit)
Inserts the specified element into this delay queue. |
Object | peek()
Retrieves, but does not remove, the head of this queue, or
returns null if this queue is empty. |
Object | poll()
Retrieves and removes the head of this queue, or returns null
if this queue has no elements with an expired delay.
|
Object | poll(long timeout, TimeUnit unit)
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue,
or the specified wait time expires.
|
void | put(Object e)
Inserts the specified element into this delay queue. |
int | remainingCapacity()
Always returns Integer.MAX_VALUE because
a DelayQueue is not capacity constrained.
|
boolean | remove(Object o)
Removes a single instance of the specified element from this
queue, if it is present, whether or not it has expired. |
int | size() |
Object | take()
Retrieves and removes the head of this queue, waiting if necessary
until an element with an expired delay is available on this queue.
|
Object[] | toArray()
Returns an array containing all of the elements in this queue.
|
Object[] | toArray(Object[] a)
Returns an array containing all of the elements in this queue; the
runtime type of the returned array is that of the specified array.
|
Parameters: c the collection of elements to initially contain
Throws: NullPointerException if the specified collection or any of its elements are null
Parameters: e the element to add
Returns: true (as specified by Collection#add)
Throws: NullPointerException if the specified element is null
Throws: UnsupportedOperationException {@inheritDoc } ClassCastException {@inheritDoc } NullPointerException {@inheritDoc } IllegalArgumentException {@inheritDoc }
Throws: UnsupportedOperationException {@inheritDoc } ClassCastException {@inheritDoc } NullPointerException {@inheritDoc } IllegalArgumentException {@inheritDoc }
Returns: an iterator over the elements in this queue
Parameters: e the element to add
Returns: true
Throws: NullPointerException if the specified element is null
Parameters: e the element to add timeout This parameter is ignored as the method never blocks unit This parameter is ignored as the method never blocks
Returns: true
Throws: NullPointerException {@inheritDoc }
Returns: the head of this queue, or null if this queue is empty.
Returns: the head of this queue, or null if this queue has no elements with an expired delay
Returns: the head of this queue, or null if the specified waiting time elapses before an element with an expired delay becomes available
Throws: InterruptedException {@inheritDoc }
Parameters: e the element to add
Throws: NullPointerException {@inheritDoc }
Returns: Integer.MAX_VALUE
Returns: the head of this queue
Throws: InterruptedException {@inheritDoc }
The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
Returns: an array containing all of the elements in this queue
If this queue fits in the specified array with room to spare (i.e., the array has more elements than this queue), the element in the array immediately following the end of the queue is set to null.
Like the toArray method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
The following code can be used to dump a delay queue into a newly allocated array of Delayed:
Delayed[] a = q.toArray(new Delayed[0]);Note that toArray(new Object[0]) is identical in function to toArray().
Parameters: a the array into which the elements of the queue are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
Returns: an array containing all of the elements in this queue
Throws: ArrayStoreException if the runtime type of the specified array is not a supertype of the runtime type of every element in this queue NullPointerException if the specified array is null