| |
|
| java.lang.Object org.jgroups.util.Queue
Queue | public class Queue (Code) | | 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).
author: Bela Ban |
Inner Class :static class Element | |
Field Summary | |
final protected static Log | log |
Constructor Summary | |
public | Queue() |
Method Summary | |
public 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. | public void | addAll(Collection c) | public void | addAll(List l) | public 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. | public void | clear() Removes all elements from the queue. | public void | close(boolean flush_entries) Marks the queues as 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. | public Object | getFirst() Returns the first element. | public Object | getLast() Returns the last element. | public Object | peek() returns the first object on the queue, without removing it. | public Object | peek(long timeout) returns the first object on the queue, without removing it. | public Object | remove() | public Object | remove(long timeout) Removes 1 element from the head. | public void | removeElement(Object obj) removes a specific object from the queue. | public void | reset() resets the queue. | public int | size() | public String | toString() | public LinkedList | values() | public void | waitUntilClosed(long timeout) Waits until the queue has been closed. |
log | final protected static Log log(Code) | | |
Queue | public Queue()(Code) | | creates an empty queue
|
add | public void add(Object obj) throws QueueClosedException(Code) | | 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.
Parameters: obj - - the object to be added to the queue exception: QueueClosedException - exception if closed() returns true |
addAtHead | public void addAtHead(Object obj) throws QueueClosedException(Code) | | 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.
Parameters: obj - - the object to be added to the queue exception: QueueClosedException - exception if closed() returns true |
clear | public void clear()(Code) | | Removes all elements from the queue. This method can succeed even when the queue is closed
|
close | public void close(boolean flush_entries)(Code) | | Marks the queues as closed. When an 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 markeris encountered, the queue is marked as closed. This allows to flushpending messages before closing the queue. |
closed | public boolean closed()(Code) | | 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.
true if the queue has been closed |
getFirst | public Object getFirst()(Code) | | Returns the first element. Returns null if no elements are available.
|
getLast | public Object getLast()(Code) | | Returns the last element. Returns null if no elements are available.
|
peek | public Object peek() throws QueueClosedException(Code) | | 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
the first object on the queue |
peek | public Object peek(long timeout) throws QueueClosedException, TimeoutException(Code) | | 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
Parameters: timeout - how long in milli seconds will this operation wait for an object to be added to the queuebefore it times out the first object on the queue |
remove | public Object remove() throws QueueClosedException(Code) | | Removes 1 element from head or blocks
until next element has been added or until queue has been closed
the first element to be taken of the queue |
remove | public Object remove(long timeout) throws QueueClosedException, TimeoutException(Code) | | 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
Parameters: timeout - - the number of milli seconds this operation will wait before it times out the first object in the queue |
removeElement | public void removeElement(Object obj) throws QueueClosedException(Code) | | removes a specific object from the queue.
the object is matched up using the Object.equals method.
Parameters: obj - the actual object to be removed from the queue |
reset | public void reset()(Code) | | resets the queue.
This operation removes all the objects in the queue and marks the queue open
|
size | public int size()(Code) | | returns the number of objects that are currently in the queue
|
toString | public String toString()(Code) | | prints the size of the queue
|
values | public LinkedList values()(Code) | | Returns all the elements of the queue
A copy of the queue |
waitUntilClosed | public void waitUntilClosed(long timeout)(Code) | | Waits until the queue has been closed. Returns immediately if already closed
Parameters: timeout - Number of milliseconds to wait. A value <= 0 means to wait forever |
|
|
|