public class Queue2
extends java.lang.Object
Implementation is based on util.concurrent.* classes
Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
log |
Constructor and Description |
---|
Queue2()
creates an empty queue
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.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(java.lang.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.
|
java.lang.String |
debug()
Dumps internal state @remove
|
java.util.Vector |
getContents()
returns a vector with all the objects currently in the queue
|
java.lang.Object |
getFirst()
Returns the first element.
|
java.lang.Object |
getLast()
Returns the last element.
|
java.lang.Object |
peek()
returns the first object on the queue, without removing it.
|
java.lang.Object |
peek(long timeout)
returns the first object on the queue, without removing it.
|
java.lang.Object |
remove()
Removes 1 element from head or blocks
until next element has been added or until queue has been closed
|
java.lang.Object |
remove(long timeout)
Removes 1 element from the head.
|
void |
removeElement(java.lang.Object obj)
removes a specific object from the queue.
|
void |
reset()
resets the queue.
|
int |
size()
returns the number of objects that are currently in the queue
|
java.lang.String |
toString()
prints the size of the queue
|
void |
waitUntilEmpty(long timeout)
Blocks until the queue has no elements left.
|
public java.lang.Object getFirst()
public java.lang.Object getLast()
public boolean closed()
public void add(java.lang.Object obj) throws QueueClosedException
obj
- - the object to be added to the queueQueueClosedException
- exception if closed() returns truepublic void addAtHead(java.lang.Object obj) throws QueueClosedException
obj
- - the object to be added to the queueQueueClosedException
- exception if closed() returns truepublic java.lang.Object remove() throws QueueClosedException
QueueClosedException
public java.lang.Object remove(long timeout) throws QueueClosedException, TimeoutException
timeout
- - the number of milli seconds this operation will wait before it times outQueueClosedException
TimeoutException
public void removeElement(java.lang.Object obj) throws QueueClosedException
obj
- the actual object to be removed from the queueQueueClosedException
public java.lang.Object peek() throws QueueClosedException
QueueClosedException
public java.lang.Object peek(long timeout) throws QueueClosedException, TimeoutException
timeout
- how long in milli seconds will this operation wait for an object to be added to the queue
before it times outQueueClosedException
TimeoutException
public void close(boolean flush_entries)
add
or remove
operation is
attempted on a closed queue, an exception is thrown.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.public void reset()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String debug()
public java.util.Vector getContents()
public void waitUntilEmpty(long timeout) throws QueueClosedException, TimeoutException
timeout
- Call returns if timeout has elapsed (number of milliseconds). 0 means to wait foreverQueueClosedException
- Thrown if queue has been closedTimeoutException
- Thrown if timeout has elapsedCopyright ? 1998-2006 Bela Ban. All Rights Reserved.