|
|||||||||
| Home >> All >> org >> jgroups >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jgroups.util
Class Queue2

java.lang.Objectorg.jgroups.util.Queue2
- public class Queue2
- extends java.lang.Object
Elements are added at the tail and removed from the head. Class is thread-safe in that 1 producer and 1 consumer may add/remove elements concurrently. The class is not explicitely designed for multiple producers or consumers. Implemented as a linked list, so that removal of an element at the head does not cause a right-shift of the remaining elements (as in a Vector-based implementation).
Implementation is based on util.concurrent.* classes
| Nested Class Summary | |
(package private) class |
Queue2.Element
the class Element indicates an object in the queue. |
| Field Summary | |
(package private) CondVar |
add_condvar
Signals to listeners when an element has been added |
(package private) boolean |
closed
|
private static java.lang.Object |
endMarker
if the queue closes during the runtime an endMarker object is added to the end of the queue to indicate that the queue will close automatically when the end marker is encountered This allows for a "soft" close. |
(package private) Queue2.Element |
head
|
protected static org.apache.commons.logging.Log |
log
|
(package private) Sync |
mutex
|
(package private) int |
num_markers
|
(package private) CondVar |
remove_condvar
Signals to listeners when an element has been removed |
(package private) int |
size
|
(package private) Queue2.Element |
tail
|
| Constructor Summary | |
Queue2()
creates an empty queue |
|
| Method Summary | |
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 |
(package private) void |
decrementSize()
|
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. |
private java.lang.Object |
removeInternal()
Removes the first element. |
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
head
Queue2.Element head
tail
Queue2.Element tail
closed
boolean closed
size
int size
mutex
final Sync mutex
add_condvar
final CondVar add_condvar
- Signals to listeners when an element has been added
remove_condvar
final CondVar remove_condvar
- Signals to listeners when an element has been removed
num_markers
int num_markers
log
protected static final org.apache.commons.logging.Log log
endMarker
private static final java.lang.Object endMarker
- if the queue closes during the runtime
an endMarker object is added to the end of the queue to indicate that
the queue will close automatically when the end marker is encountered
This allows for a "soft" close.
- See Also:
Queue.close(boolean)55
| Constructor Detail |
Queue2
public Queue2()
- creates an empty queue
| Method Detail |
getFirst
public java.lang.Object getFirst()
- Returns the first element. Returns null if no elements are available.
getLast
public java.lang.Object getLast()
- Returns the last element. Returns null if no elements are available.
closed
public 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.
add
public void add(java.lang.Object obj) throws QueueClosedException
- 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.
addAtHead
public void addAtHead(java.lang.Object obj) throws QueueClosedException
- 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.
remove
public java.lang.Object remove() throws QueueClosedException
- Removes 1 element from head or blocks
until next element has been added or until queue has been closed
remove
public java.lang.Object remove(long timeout) throws QueueClosedException, org.jgroups.TimeoutException
- Removes 1 element from the head.
If the queue is empty the operation will wait for timeout ms.
if no object is added during the timeout time, a Timout exception is thrown
removeElement
public void removeElement(java.lang.Object obj) throws QueueClosedException
- removes a specific object from the queue.
the object is matched up using the Object.equals method.
peek
public java.lang.Object peek() throws QueueClosedException
- returns the first object on the queue, without removing it.
If the queue is empty this object blocks until the first queue object has
been added
peek
public java.lang.Object peek(long timeout) throws QueueClosedException, org.jgroups.TimeoutException
- returns the first object on the queue, without removing it.
If the queue is empty this object blocks until the first queue object has
been added or the operation times out
close
public void close(boolean flush_entries)
- Marks the queues as closed. When an
addorremoveoperation is attempted on a closed queue, an exception is thrown.
reset
public void reset()
- resets the queue.
This operation removes all the objects in the queue and marks the queue open
size
public int size()
- returns the number of objects that are currently in the queue
toString
public java.lang.String toString()
- prints the size of the queue
debug
public java.lang.String debug()
- Dumps internal state @remove
getContents
public java.util.Vector getContents()
- returns a vector with all the objects currently in the queue
waitUntilEmpty
public void waitUntilEmpty(long timeout)
throws QueueClosedException,
org.jgroups.TimeoutException
- Blocks until the queue has no elements left. If the queue is empty, the call will return
immediately
removeInternal
private java.lang.Object removeInternal()
- Removes the first element. Returns null if no elements in queue.
Always called with mutex locked (we don't have to lock mutex ourselves)
decrementSize
void decrementSize()
|
|||||||||
| Home >> All >> org >> jgroups >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jgroups.util.Queue2