com.mindbright.util
Class Queue

java.lang.Object
  extended by com.mindbright.util.Queue

public final class Queue
extends java.lang.Object

A queue of objects. New objects can be inserted first or last. The depth of the queue can be controlled and put operations will hang if there is no room. If the queue is full then any put operation will hang until the number of objects in the queue has sunk below the hiwater mark.


Constructor Summary
Queue()
          Constructs a new queue with the default depth (64) and hiwater (32) levels.
Queue(int depth, int hiwater)
          Constructs a new queue with custom depth and hiwater levels.
 
Method Summary
 void disable()
          Disable the queue.
 void enable()
          Enable a disabled queue.
 java.lang.Object getFirst()
          Get the first object on the queue.
 java.lang.Object getFirst(long ms)
          Get the first object on the queue, optionally with a timeout.
 boolean isEmpty()
          Check if the queue is empty
 void putFirst(java.lang.Object obj)
          insert an object at the head of the queue.
 void putLast(java.lang.Object obj)
          Append an object to the queue.
 void release()
          Release any blocked object.
 void setBlocking(boolean block)
          Controls if the getFirst call should block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructs a new queue with the default depth (64) and hiwater (32) levels.


Queue

public Queue(int depth,
             int hiwater)
Constructs a new queue with custom depth and hiwater levels.

Method Detail

putLast

public void putLast(java.lang.Object obj)
Append an object to the queue. This function will hang until there is room in the queue.

Parameters:
obj - the object to append

putFirst

public void putFirst(java.lang.Object obj)
insert an object at the head of the queue. This function will hang until there is room in the queue.

Parameters:
obj - the object to insert

release

public void release()
Release any blocked object. That is eventual calls to get are unblocked.


disable

public void disable()
Disable the queue. A disabled queue will not accept any new objects


enable

public void enable()
Enable a disabled queue.


setBlocking

public void setBlocking(boolean block)
Controls if the getFirst call should block. The default is that calls are blocking.

Parameters:
block - true if calls to getFirst should block

isEmpty

public boolean isEmpty()
Check if the queue is empty

Returns:
true if the queue is empty

getFirst

public java.lang.Object getFirst(long ms)
Get the first object on the queue, optionally with a timeout.

Parameters:
ms - how long, in milliseconds, to wait, if the queue is blocking, for a new object.

getFirst

public java.lang.Object getFirst()
Get the first object on the queue.

Returns:
the first object of the queue or null if the queue is empty