uk.org.ogsadai.engine
Class SynchronizedGrowablePipe

java.lang.Object
  |
  +--uk.org.ogsadai.engine.SynchronizedGrowablePipe
All Implemented Interfaces:
BlockReader, BlockWriter, Pipe

public class SynchronizedGrowablePipe
extends java.lang.Object
implements Pipe

This is a pipe designed to be shared between exactly two threads. One thread writes and one thread reads. It works by maintaining two discrete buffers, one for each thread. This is done in such a way that the only time synchronization is required is when the buffers are filled and need to be switched. This implementation is thread safe for a single producer and consumer only. More than one of either renders this implementation unsafe. While this class can be used in any situation where one thread is providing and another consuming, within the scope of the execution model this class is very tightly coupled with RunAheadHandler.

Author:
The OGSA-DAI Project Team

Constructor Summary
SynchronizedGrowablePipe()
           
 
Method Summary
 void close()
          Closes the block writer to indicate that there are no more blocks are to be written.
 boolean hasNext()
          Indicates whether or not there are any more blocks of data to be read from the block reader.
 java.lang.Object next()
          Gets the next block of data contained in the block reader.
 void put(java.lang.Object block)
          Writes the specified block of output data.
 void waitForBlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedGrowablePipe

public SynchronizedGrowablePipe()
Method Detail

next

public java.lang.Object next()
Description copied from interface: BlockReader
Gets the next block of data contained in the block reader.

Specified by:
next in interface BlockReader
Returns:
an Object
See Also:
BlockReader.next()

close

public void close()
Description copied from interface: BlockWriter
Closes the block writer to indicate that there are no more blocks are to be written. After close has been called, the put method should no longer be used.

Specified by:
close in interface BlockWriter
See Also:
BlockWriter.close()

put

public void put(java.lang.Object block)
Description copied from interface: BlockWriter
Writes the specified block of output data.

Specified by:
put in interface BlockWriter
Parameters:
block - the Object block to write
See Also:
BlockWriter.put(Object)

hasNext

public boolean hasNext()
Description copied from interface: BlockReader
Indicates whether or not there are any more blocks of data to be read from the block reader.

Specified by:
hasNext in interface BlockReader
Returns:
true if there are more blocks to be read or false otherwise

waitForBlock

public void waitForBlock()