org.jgroups.util
Class LinkedListQueue

java.lang.Object
  extended byorg.jgroups.util.LinkedListQueue

public class LinkedListQueue
extends java.lang.Object

LinkedListQueue implementation based on java.util.Queue. Can be renamed to Queue.java and compiled if someone wants to use this implementation rather than the original Queue. However, a simple insertion and removal of 1 million objects into this queue shoed that it was ca. 15-20% slower than the original queue. We just include it in the JGroups distribution to maybe use it at a later point when it has become faster.

Author:
Bela Ban

Field Summary
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
LinkedListQueue()
          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(LinkedListQueue.remove(LinkedListQueue.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.util.Vector getContents()
          returns a vector with all the objects currently in the queue
 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
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
Constructor Detail

LinkedListQueue

public LinkedListQueue()
creates an empty queue

Method Detail

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.

Returns:
true if the queue has been closed

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.

Parameters:
obj - - the object to be added to the queue
Throws:
QueueClosed - exception if closed() returns true
QueueClosedException

addAtHead

public void addAtHead(java.lang.Object obj)
               throws QueueClosedException
Adds a new object to the head of the queue basically (obj.equals(LinkedListQueue.remove(LinkedListQueue.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
Throws:
QueueClosed - exception if closed() returns true
QueueClosedException

remove

public java.lang.Object remove()
                        throws QueueClosedException
Removes 1 element from head or blocks until next element has been added

Returns:
the first element to be taken of the queue
Throws:
QueueClosedException

remove

public java.lang.Object remove(long timeout)
                        throws QueueClosedException,
                               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

Parameters:
timeout - - the number of milli seconds this operation will wait before it times out
Returns:
the first object in the queue
Throws:
QueueClosedException
TimeoutException

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.

Parameters:
obj - the actual object to be removed from the queue
Throws:
QueueClosedException

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

Returns:
the first object on the queue
Throws:
QueueClosedException

peek

public java.lang.Object peek(long timeout)
                      throws QueueClosedException,
                             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

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
Throws:
QueueClosedException
TimeoutException

close

public void close(boolean flush_entries)
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 marker is encountered, the queue is marked as closed. This allows to flush pending messages before closing the queue.

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


getContents

public java.util.Vector getContents()
returns a vector with all the objects currently in the queue



Copyright ? 1998-2005 Bela Ban. All Rights Reserved.