autohit.utils
Class LockedQueue

java.lang.Object
  |
  +--autohit.utils.LockedQueue

public class LockedQueue
extends java.lang.Object

A locked queue. This will allow one thread to safely enqueue objects for other threads. All of the methods are thread-safe.


Constructor Summary
LockedQueue()
          Constructor.
 
Method Summary
 void block(boolean set)
          Blocks until an object is enqueued by another thread.
 java.lang.Object get()
          Get an object from the queue.
 boolean hasObject()
          Asks if the queue has any objects.
 void put(java.lang.Object c)
          Put an object in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockedQueue

public LockedQueue()
Constructor.
Method Detail

get

public java.lang.Object get()
Get an object from the queue. This method will block if other threads are enqueuing items, so watch out in 'real-time' threads.
Returns:
an Object reference or null if the queue is empty.

put

public void put(java.lang.Object c)
Put an object in the queue.
Parameters:
c - the object to enqueue.

hasObject

public boolean hasObject()
Asks if the queue has any objects.
Returns:
true if there is an object in the queue, otherwise false.

block

public void block(boolean set)
Blocks until an object is enqueued by another thread. Being released fromt he block is no guarentee that an object available for the thread, if it is possible for another thread to swoop in an unenqueue one.
Parameters:
set - pass true to block. Passing false will unblock any waiting threads, so be careful!