fipaos.util
Class Queue

java.lang.Object
  |
  +--fipaos.util.Queue
Direct Known Subclasses:
FIFOQueue, LIFOQueue

public abstract class Queue
extends java.lang.Object

This is a simple class which defines methods which all queues should implement


Field Summary
protected  java.util.Vector _queue
          Vector containing the message queue
 
Constructor Summary
protected Queue(int max_size)
          Stores information such as maximum size of the queue
 
Method Summary
 void addItem(java.lang.Object obj)
          Adds an object to the queue
 void flush()
          Method to flush the contents of the queue
 java.lang.Object getItem()
          Get the next message from the queue.
 java.lang.Object getItemWithoutBlocking()
          Get the next message from the queue.
protected abstract  java.lang.Object getNextItem()
          Method to get the next element from the queue It is down to the queue implementation to determine which item in the queue to retreive
 boolean isEmpty()
          Method to determine if the queue is empty
 boolean isFull()
          Method to determine if the queue is full
static void main(java.lang.String[] args)
          Test harness for the various Queue implementations
 int queueLength()
          Returns the number of items currently in the queue.
 void releaseBlock()
          Method to release all blocked threads within the queue - once invoked, getItem() will never block again
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_queue

protected java.util.Vector _queue
Vector containing the message queue
Constructor Detail

Queue

protected Queue(int max_size)
Stores information such as maximum size of the queue
Parameters:
max_size - The most elements that can be contained within the queue at once, or -1 for no limit
Method Detail

queueLength

public int queueLength()
Returns the number of items currently in the queue.

addItem

public void addItem(java.lang.Object obj)
Adds an object to the queue
Parameters:
obj - The object to add, given that the queue is not full

getItem

public java.lang.Object getItem()
Get the next message from the queue. If the queue is empty, the thread will block until a message is added.
Returns:
The next message in the queue, or null if the thread is interrupted

getItemWithoutBlocking

public java.lang.Object getItemWithoutBlocking()
Get the next message from the queue. If the queue is empty, return null immediately.
Returns:
The next message in the queue or null

isFull

public boolean isFull()
Method to determine if the queue is full
Returns:
True if the queue is at full capacity

isEmpty

public boolean isEmpty()
Method to determine if the queue is empty
Returns:
True if the queue is empty

flush

public void flush()
Method to flush the contents of the queue

releaseBlock

public void releaseBlock()
Method to release all blocked threads within the queue - once invoked, getItem() will never block again

getNextItem

protected abstract java.lang.Object getNextItem()
Method to get the next element from the queue It is down to the queue implementation to determine which item in the queue to retreive
Returns:
The next item from the queue

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Test harness for the various Queue implementations