com.tivoli.twg.libs
Class ObjectQueue

java.lang.Object
  extended bycom.tivoli.twg.libs.ObjectQueue

public class ObjectQueue
extends java.lang.Object

ObjectQueue is a generic class for defining a FIFO queue of Object references. It is thread-safe, allowing a single reader to dequeue events (without polling) while multiple other threads enqueue Objects.


Constructor Summary
ObjectQueue()
          Constructor for ObjectQueue.
 
Method Summary
 java.lang.Object dequeue()
          Dequeue next Object in queue.
 java.lang.Object dequeue(int timeout)
          Dequeue next Object in queue.
 void enqueue(java.lang.Object obj)
          Enqueue an object reference.
 void enqueueHead(java.lang.Object obj)
          Enqueue an object reference at head of queue (LIFO).
 int getQueueLength()
          Return current number of elements in the queue
 java.lang.Object peek()
          Peek next Object on queue.
 boolean remove(java.lang.Object obj)
          Remove an object from the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectQueue

public ObjectQueue()
Constructor for ObjectQueue. Creates an empty queue.

Method Detail

enqueue

public void enqueue(java.lang.Object obj)
Enqueue an object reference.

Parameters:
obj - - an instance of an Object

enqueueHead

public void enqueueHead(java.lang.Object obj)
Enqueue an object reference at head of queue (LIFO).

Parameters:
obj - - an instance of an Object

dequeue

public java.lang.Object dequeue()
                         throws java.lang.InterruptedException
Dequeue next Object in queue. Blocks until an Object is available.

Returns:
the next Object in the queue
Throws:
java.lang.InterruptedException - if another thread has interrupted this thread.

dequeue

public java.lang.Object dequeue(int timeout)
                         throws java.lang.InterruptedException
Dequeue next Object in queue. Blocks until an Object is available or until given timeout has elapsed.

Parameters:
timeout - - time, in milliseconds, to wait if no Objects in queue (<= 0 means no timeout (indefinite wait))
Returns:
the next Object in the queue, or null if timeout
Throws:
java.lang.InterruptedException - if another thread has interrupted this thread.

peek

public java.lang.Object peek()
Peek next Object on queue. Object is not removed from queue.

Returns:
the next Object on the queue, or null if none in queue

remove

public boolean remove(java.lang.Object obj)
Remove an object from the queue. If the object has been enqueued more than once, the object closest to the head of the queue will be removed.

Returns:
TRUE: object was found and removed. FALSE: Object was not found.

getQueueLength

public int getQueueLength()
Return current number of elements in the queue

Returns:
number of queued elements