org.locomotive.util
Class FIFO

java.lang.Object
  |
  +--org.locomotive.util.FIFO

public class FIFO
extends java.lang.Object

A FIFO is essentially a variable length list. Trying to stuff another object onto a full FIFO will cause the calling thread to block until one of two things occurs: another thread removes an object, freeing space for another, or the FIFO is closed (also via another thread). If the FIFO is closed, any blocked callers will be thrown a run time exception - IndexOutOfBoundsException


Constructor Summary
FIFO()
          create a new empty FIFO with max size of 8.
FIFO(int msz)
          create a new FIFO, with the specified max size.
 
Method Summary
 void close()
          close the fifo.
 boolean hasContents()
          true if there are currently objects in the queue.
 int size()
          current size (number of objects in the FIFO).
 boolean stuff(java.lang.Object o)
          Stuffs an object into the FIFO.
 java.lang.Object yank()
          Grabs the next Object off the FIFO queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FIFO

public FIFO()
create a new empty FIFO with max size of 8.

FIFO

public FIFO(int msz)
create a new FIFO, with the specified max size.
Parameters:
msz - the maximum number of objects in the FIFO at once
Method Detail

close

public void close()
close the fifo. This will cause other thread who are trying to stuff new objects onto the FIFO to receive IndexOutOfBoundsExceptions Threads taking objects out of the FIFO can continue to do so until the FIFO is emptied, at which point any attempts to pull new objects will result in an IndexOutOfBoundsException being thrown

stuff

public boolean stuff(java.lang.Object o)
Stuffs an object into the FIFO. Will block if the FIFO is currently full and will complete when there is enough room. If the FIFO is closed or is closed by another thread while the caller is blocked, stuff will return with false.
Parameters:
o - the object to be stuffed into the FIFO

yank

public java.lang.Object yank()
                      throws java.lang.IndexOutOfBoundsException
Grabs the next Object off the FIFO queue. Will block until an object is available. An exception will be thrown if the FIFO is closed at the time of the call or if closed while the caller is blocked

hasContents

public boolean hasContents()
true if there are currently objects in the queue. Note that this state may change while the caller isn't looking if multiple threads are accesing the same FIFO.

size

public int size()
current size (number of objects in the FIFO). Like hasContents() this state may change if the FIFO is being accessed by multiple concurrent threads