org.openstreetmap.osmosis.core.store
Class DataPostbox<T>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.DataPostbox<T>
Type Parameters:
T - The type of data held in the postbox.

public class DataPostbox<T>
extends java.lang.Object

This class provides a mechanism for a thread to pass data to another thread. Both threads will block until the other is ready. It supports a single writing thread, and a single reading thread. Multiple reading or writing threads are NOT supported.


Constructor Summary
DataPostbox(int capacity)
          Creates a new instance.
 
Method Summary
 void complete()
          Marks input is complete.
 T getNext()
          Returns the next available object from the postbox.
 boolean hasNext()
          Indicates if data is available for output.
 void put(T o)
          Adds a new object to the postbox.
 void release()
          Must be called at the end of input processing regardless of whether errors have occurred.
 void setOutputError()
          Allows an output thread to signal that it has failed, this will cause exceptions to be thrown if more data is sent by input input threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataPostbox

public DataPostbox(int capacity)
Creates a new instance.

Parameters:
capacity - The maximum number of objects to hold in the postbox before blocking.
Method Detail

put

public void put(T o)
Adds a new object to the postbox.

Parameters:
o - The object to be added.

complete

public void complete()
Marks input is complete.


release

public void release()
Must be called at the end of input processing regardless of whether errors have occurred.


hasNext

public boolean hasNext()
Indicates if data is available for output. This will block until either data is available, input processing has completed, or an input error occurs.

Returns:
True if data is available.

getNext

public T getNext()
Returns the next available object from the postbox. This should be preceeded by a call to hasNext.

Returns:
The next available object.

setOutputError

public void setOutputError()
Allows an output thread to signal that it has failed, this will cause exceptions to be thrown if more data is sent by input input threads.