|
|||||||||
| 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 Queue

java.lang.Objectorg.jgroups.util.Queue
- public class Queue
- 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).
| Nested Class Summary | |
(package private) static class |
Queue.Element
the class Element indicates an object in the queue. |
| Field Summary | |
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. |
private Queue.Element |
head
|
protected static org.apache.commons.logging.Log |
log
|
private java.lang.Object |
mutex
|
private int |
num_markers
Lock object for syncing on removes. |
private int |
size
|
private Queue.Element |
tail
|
| Constructor Summary | |
Queue()
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 |
addAll(java.util.Collection c)
|
void |
addAll(List l)
|
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. |
private void |
addInternal(java.lang.Object obj)
|
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. |
private void |
decrementSize()
Doesn't need to be synchronized; is always called from synchronized methods |
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 |
java.util.LinkedList |
values()
Returns all the elements of the queue |
void |
waitUntilClosed(long timeout)
Waits until the queue has been closed. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
head
private Queue.Element head
tail
private Queue.Element tail
closed
private boolean closed
size
private int size
mutex
private final java.lang.Object mutex
num_markers
private int num_markers
- Lock object for syncing on removes. It is notified when an object is removed
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:
close(boolean)55
log
protected static final org.apache.commons.logging.Log log
| Constructor Detail |
Queue
public Queue()
- 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.
addAll
public void addAll(java.util.Collection c) throws QueueClosedException
addAll
public void addAll(List l) throws QueueClosedException
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.
waitUntilClosed
public void waitUntilClosed(long timeout)
- Waits until the queue has been closed. Returns immediately if already closed
reset
public void reset()
- resets the queue.
This operation removes all the objects in the queue and marks the queue open
values
public java.util.LinkedList values()
- Returns all the elements of the queue
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
addInternal
private final void addInternal(java.lang.Object obj)
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
private final void decrementSize()
- Doesn't need to be synchronized; is always called from synchronized methods
|
|||||||||
| 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.Queue