visidia.simulation.evtack
Class VQueue

java.lang.Object
  extended by visidia.simulation.evtack.VQueue

public class VQueue
extends java.lang.Object

A VQueue object implements a FIFO (First In First Out) list. It can be used in multi-threads environment since all it's methods are synchronized. The get (resp. put) method blocks when there is no element to return (resp. when the queue contains maxSize elements). If the calling thread is interrupted while it is blocked in these methods, the InterruptedException is thrown.


Constructor Summary
VQueue()
          Constructs a queue with default maximum size which is Integer.MAX_VALUE.
VQueue(int maxSize)
          Constructs a queue with maximum size maxSize.
 
Method Summary
 boolean contains(Criterion c)
          Returns true if the queue contains one element that matches the criterion c.
 java.lang.Object get()
          Returns the first element in the queue.
 java.lang.Object get(Criterion c)
          Returns the first element in the queue that match the criterion c.
 java.util.Vector<java.lang.Object> getAllNoWait(Criterion c)
          Returns all elements in the queue that match the criterion c.
 int getMaxSize()
          Returns this queue maximum size.
 java.lang.Object getNoWait(Criterion c)
          Returns the first element in the queue that matches the criterion c.
 boolean isEmpty()
          Returns true if the queue is empty.
 void notifyAllGet()
          Do not use this method if your are not sure about what you are doing.
 void purge()
          Removes all elements from the queue.
 void put(java.lang.Object obj)
          Adds one element at the end of the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VQueue

public VQueue()
Constructs a queue with default maximum size which is Integer.MAX_VALUE.


VQueue

public VQueue(int maxSize)
Constructs a queue with maximum size maxSize.

Parameters:
maxSize - the max size
Method Detail

get

public java.lang.Object get()
                     throws java.lang.InterruptedException
Returns the first element in the queue. If the queue is empty, this method blocks until an element is available.

Returns:
the object
Throws:
java.lang.InterruptedException - the interrupted exception

get

public java.lang.Object get(Criterion c)
                     throws java.lang.InterruptedException
Returns the first element in the queue that match the criterion c. If the queue does not contain any element that match the criterion c, this method blocks until one element matching c becomes available.

Parameters:
c - the criterion
Returns:
the object
Throws:
java.lang.InterruptedException - the interrupted exception

getNoWait

public java.lang.Object getNoWait(Criterion c)
                           throws java.lang.InterruptedException
Returns the first element in the queue that matches the criterion c. If the queue does not contains any element that match the criterion c, this method returns null.

Parameters:
c - the criterion
Returns:
the no wait
Throws:
java.lang.InterruptedException - the interrupted exception

getAllNoWait

public java.util.Vector<java.lang.Object> getAllNoWait(Criterion c)
                                                throws java.lang.InterruptedException
Returns all elements in the queue that match the criterion c. If the queue does not contain any element that match the criterion c, this method returns null.

Parameters:
c - the criterion
Returns:
the all no wait
Throws:
java.lang.InterruptedException - the interrupted exception

put

public void put(java.lang.Object obj)
         throws java.lang.InterruptedException
Adds one element at the end of the queue. If the queue contains maxSize elements this method blocks until one element is consumed.

Parameters:
obj - the object
Throws:
java.lang.InterruptedException - the interrupted exception

isEmpty

public boolean isEmpty()
Returns true if the queue is empty.

Returns:
true, if is empty

contains

public boolean contains(Criterion c)
Returns true if the queue contains one element that matches the criterion c.

Parameters:
c - the criterion
Returns:
true, if an element is found

purge

public void purge()
Removes all elements from the queue.


getMaxSize

public int getMaxSize()
Returns this queue maximum size.

Returns:
the max size

notifyAllGet

public void notifyAllGet()
Do not use this method if your are not sure about what you are doing. It notifies all threads waiting on a new entry in the queue.