eu.larkc.core.queue
Class Queue<E>

java.lang.Object
  extended by eu.larkc.core.queue.Queue<E>
Type Parameters:
E - The class of objects passed along the queue.

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

A blocking queue. Not as good as Queue1 (which uses one of Doug Lea's nifty queue classes), but this one does allow the putting of 'null' on the queue. Of course, this doesn't make much sense if the consumer is polling, but it's useful in the short term.


Constructor Summary
Queue()
          Constructor that initializes listeners.
 
Method Summary
 void addListener(QueueListener<E> theQueueListener)
          Adds a listener to the queue.
 void fireElementAdded(E e)
          Informs all listener that a element was added.
 boolean isEmpty()
          Answers the question if the queue is empty.
 E poll()
          Returns the first element of the queue.
 void put(E item)
          Puts one element to the queue.
 int size()
          Returns the size of the queue.
 E take()
          Returns one element of the queue and deletes it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructor that initializes listeners.

Method Detail

take

public E take()
Returns one element of the queue and deletes it.

Returns:
The first element of the queue.

put

public void put(E item)
Puts one element to the queue.

Parameters:
item - The item to put in the queue.

size

public int size()
Returns the size of the queue.

Returns:
The size of the queue.

isEmpty

public boolean isEmpty()
Answers the question if the queue is empty.

Returns:
True if the queue is empty, false otherwise.

poll

public E poll()
Returns the first element of the queue.

Returns:
The first element of the queue.

addListener

public void addListener(QueueListener<E> theQueueListener)
Adds a listener to the queue.

Parameters:
theQueueListener - The listener to add.

fireElementAdded

public void fireElementAdded(E e)
Informs all listener that a element was added.

Parameters:
e - The added element.