org.jgroups.util
public class Queue2 extends Object
Implementation is based on util.concurrent.* classes
Field Summary | |
---|---|
protected static Log | log |
Constructor Summary | |
---|---|
Queue2()
creates an empty queue |
Method Summary | |
---|---|
void | add(Object obj)
adds an object to the tail of this queue
If the queue has been closed with close(true) no exception will be
thrown if the queue has not been flushed yet. |
void | addAtHead(Object obj)
Adds a new object to the head of the queue
basically (obj.equals(queue.remove(queue.add(obj)))) returns true
If the queue has been closed with close(true) no exception will be
thrown if the queue has not been flushed yet. |
void | close(boolean flush_entries)
Marks the queues as closed. |
boolean | closed()
returns true if the Queue has been closed
however, this method will return false if the queue has been closed
using the close(true) method and the last element has yet not been received. |
String | debug()
Dumps internal state @remove |
Vector | getContents()
returns a vector with all the objects currently in the queue |
Object | getFirst()
Returns the first element. |
Object | getLast()
Returns the last element. |
Object | peek()
returns the first object on the queue, without removing it.
|
Object | peek(long timeout)
returns the first object on the queue, without removing it.
|
Object | remove()
Removes 1 element from head or blocks
until next element has been added or until queue has been closed |
Object | remove(long timeout)
Removes 1 element from the head.
|
void | removeElement(Object obj)
removes a specific object from the queue.
the object is matched up using the Object.equals method. |
void | reset()
resets the queue.
|
int | size()
returns the number of objects that are currently in the queue |
String | toString()
prints the size of the queue |
void | waitUntilEmpty(long timeout)
Blocks until the queue has no elements left. |
Parameters: obj - the object to be added to the queue
Throws: QueueClosedException exception if closed() returns true
Parameters: obj - the object to be added to the queue
Throws: QueueClosedException exception if closed() returns true
add
or remove
operation is
attempted on a closed queue, an exception is thrown.Parameters: flush_entries When true, a end-of-entries marker is added to the end of the queue. Entries may be added and removed, but when the end-of-entries marker is encountered, the queue is marked as closed. This allows to flush pending messages before closing the queue.
Returns: true if the queue has been closed
Returns: the first object on the queue
Parameters: timeout how long in milli seconds will this operation wait for an object to be added to the queue before it times out
Returns: the first object on the queue
Returns: the first element to be taken of the queue
Parameters: timeout - the number of milli seconds this operation will wait before it times out
Returns: the first object in the queue
Parameters: obj the actual object to be removed from the queue
Parameters: timeout Call returns if timeout has elapsed (number of milliseconds). 0 means to wait forever
Throws: QueueClosedException Thrown if queue has been closed TimeoutException Thrown if timeout has elapsed