brahms.base.util
Class Queue<E>

java.lang.Object
  extended by brahms.base.util.Queue<E>

public class Queue<E>
extends java.lang.Object

The Queue is a generic queue used to enqueue and dequeue Objects in a thread safe way. One or more threads can add new Objects to the queue and one or more other threads can dequeue Objects from the queue.

Version:
$Revision: 1.1 $ $Date: 2007/10/10 14:02:57 $ $Author: rvhoof $
Author:
Ron van Hoof

Constructor Summary
Queue()
          Constructor, creates a new Queue.
 
Method Summary
 java.util.List<E> close()
          Closes the queue and releases all threads waiting for new data.
 E dequeue()
          Removes the first element from the queue and blocks the calling thread if no data is queued.
 E dequeue(boolean block)
          Removes the first element from the queue and blocks the calling thread if no data is queued and block = true or returns null if block = false.
 void enqueue(E data)
          Adds the specified element to the end of the queue.
 long getQueueSize()
          Returns the number of Objects in the queue.
 void open()
          Opens the queue for data elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructor, creates a new Queue.

Method Detail

enqueue

public void enqueue(E data)
             throws QueueException
Adds the specified element to the end of the queue.

Parameters:
data - the element to be queued.
Throws:
QueueException - if the queue is closed.

dequeue

public E dequeue()
          throws QueueException
Removes the first element from the queue and blocks the calling thread if no data is queued.

Returns:
E the first element in the queue
Throws:
QueueException - if the queue was closed while waiting for new objects.

dequeue

public E dequeue(boolean block)
          throws QueueException
Removes the first element from the queue and blocks the calling thread if no data is queued and block = true or returns null if block = false.

Parameters:
block - true to have the method block until an element is enqueued, false to not block and return null if no elements are present
Returns:
E the first element in the queue, or null if there are no elements and block=false
Throws:
QueueException - if the queue was closed while waiting for new objects.

getQueueSize

public long getQueueSize()
Returns the number of Objects in the queue.

Returns:
long the number of Objects in the queue

open

public void open()
Opens the queue for data elements.


close

public java.util.List<E> close()
Closes the queue and releases all threads waiting for new data. Returns all elements that were remaining on the queue.

Returns:
List the elements that were remaining on the queue


Copyright © 1997-2012 All Rights Reserved.