All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class magician.Node.Queue

java.lang.Object
   |
   +----magician.Utils.UnsynchVector
           |
           +----magician.Node.Queue

public class Queue
extends UnsynchVector
A blocking queue of elements. Readers of the queue block when attempting to read when the queue is empty. The readers are woken up when an element is inserted into the queue.


Constructor Index

 o Queue()
constructs an empty queue
 o Queue(int)
constructs a queue of the specified size

Method Index

 o insert(Object)
inserts an object into the queue.
 o peek()
returns a reference to the first element of the queue but does not remove the element from the queue.
 o remove()
removes the first element of the queue and returns it.
 o remove(long)
removes the first element of the queue and returns it.

Constructors

 o Queue
 public Queue()
constructs an empty queue

 o Queue
 public Queue(int size)
constructs a queue of the specified size

Parameters:
size - the initial size of the queue

Methods

 o insert
 public synchronized void insert(Object element)
inserts an object into the queue. If the queue was previously empty, wakes up any sleeping readers

Parameters:
element - the data object to be placed on the queue
 o remove
 public synchronized Object remove() throws InterruptedException
removes the first element of the queue and returns it. If the queue is empty, this method blocks until one is available. To prevent blocking reads, use peek to test if queue is empty.

Returns:
s the first element of the queue
Throws: InterruptedException
if operation is interrupted
 o remove
 public synchronized Object remove(long timeout) throws InterruptedException
removes the first element of the queue and returns it. If the queue is empty, this method blocks until one is available. To prevent blocking reads, use peek to test if queue is empty or use timeout.

Parameters:
timeout - the time period to wait for
Returns:
s the first element of the queue
Throws: InterruptedException
if operation is interrupted
 o peek
 public Object peek()
returns a reference to the first element of the queue but does not remove the element from the queue. If the queue is empty, it returns null.

Returns:
s the first element or null if the queue is empty

All Packages  Class Hierarchy  This Package  Previous  Next  Index
1