ibis.util
Class Queue

java.lang.Object
  extended byibis.util.Queue

public class Queue
extends java.lang.Object

A simple queue class. Objects can be enqueued, dequeued, or dequeued with a deadline.


Constructor Summary
Queue()
          Constructs a new queue.
 
Method Summary
 java.lang.Object dequeue()
          Dequeues the head of the queue.
 java.lang.Object dequeue(long deadline)
          Dequeues the head of the queue.
 void enqueue(java.lang.Object o)
          Enqueues the specified object, and notifies: if there are threads waiting, a single one is notified.
 int size()
          Returns the length of the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructs a new queue.

Method Detail

enqueue

public void enqueue(java.lang.Object o)
Enqueues the specified object, and notifies: if there are threads waiting, a single one is notified.

Parameters:
o - the object to be enqueued.

dequeue

public java.lang.Object dequeue()
Dequeues the head of the queue. If the queue is empty it will wait until something is added to the queue.

Returns:
the dequeued object.

dequeue

public java.lang.Object dequeue(long deadline)
Dequeues the head of the queue. If the queue is empty it will wait until something is added to the queue, or the deadline has passed.

Parameters:
deadline - the deadline expressed in milliseconds since 1-1-1970. a value of "0" will cause this function to wait forever, on -1 it will not wait at all.
Returns:
the dequeued object, or null if the deadline passed

size

public int size()
Returns the length of the queue.

Returns:
the length of the queue.


The Ibis project