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.
-
Queue()
- constructs an empty queue
-
Queue(int)
-
constructs a queue of the specified size
-
insert(Object)
-
inserts an object into the queue.
-
peek()
- returns a reference to the first element of the queue but does not remove the element
from the queue.
-
remove()
- removes the first element of the queue and returns it.
-
remove(long)
- removes the first element of the queue and returns it.
Queue
public Queue()
- constructs an empty queue
Queue
public Queue(int size)
- constructs a queue of the specified size
- Parameters:
- size - the initial size of the queue
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
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
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
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