fr.dyade.aaa.common
Class Queue

java.lang.Object
  extended by fr.dyade.aaa.common.Queue
All Implemented Interfaces:
java.io.Serializable

public class Queue
extends java.lang.Object
implements java.io.Serializable

The Queue class implements a First-In-First-Out (FIFO) list of objects.

A queue is for the exclusive use of one single consumer, whereas many producers may access it. It is ready for use after instantiation. A producer may wait for the queue to be empty by calling the stop() method. This method returns when the queue is actually empty, and prohibits any further call to the push method. To be able to use the queue again, it must be re-started through the start() method.

See Also:
Serialized Form

Constructor Summary
Queue()
          Constructs a Queue instance.
 
Method Summary
 void clear()
          Removes all of the elements from this queue.
 void close()
          Closes the queue.
 java.lang.Object get()
          Waits for an object to be pushed in the queue, and eventually returns it without removing it.
 java.lang.Object getAndPop()
          Waits for an object to be pushed in the queue, then removes and returns the object at the top of this queue.
 boolean isEmpty()
          Returns true if this queue contains no elements.
 java.lang.Object pop()
          Removes and returns the object at the top of this queue.
 void push(java.lang.Object item)
          Pushes an item at the end of this queue.
 int size()
          Returns the number of elements in this list.
 void start()
          Authorizes the use of the queue by producers.
 void stop()
          Stops the queue by returning when it is empty and prohibiting any further producers call to the push method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructs a Queue instance.

Method Detail

push

public void push(java.lang.Object item)
Pushes an item at the end of this queue.

Parameters:
item - The item to be pushed at the end of this queue.
Throws:
StoppedQueueException - If the queue is stopping or stopped.

get

public java.lang.Object get()
                     throws java.lang.InterruptedException
Waits for an object to be pushed in the queue, and eventually returns it without removing it.

Returns:
The object at the top of this queue.
Throws:
java.lang.InterruptedException

pop

public java.lang.Object pop()
Removes and returns the object at the top of this queue.

Returns:
The object at the top of this queue.
Throws:
EmptyQueueException - If the queue is empty.

getAndPop

public java.lang.Object getAndPop()
                           throws java.lang.InterruptedException
Waits for an object to be pushed in the queue, then removes and returns the object at the top of this queue.

Returns:
The object at the top of this queue.
Throws:
java.lang.InterruptedException

start

public void start()
Authorizes the use of the queue by producers.


stop

public void stop()
          throws java.lang.InterruptedException
Stops the queue by returning when it is empty and prohibiting any further producers call to the push method.

Throws:
java.lang.InterruptedException

close

public void close()
Closes the queue. Interrupts all threads blocked on get() with an InterruptedException.


isEmpty

public boolean isEmpty()
Returns true if this queue contains no elements.


clear

public void clear()
Removes all of the elements from this queue.


size

public int size()
Returns the number of elements in this list.



Copyright © 2011 ScalAgent D.T.. All Rights Reserved.