Groovy Documentation

gpars.dataflow
Class DataFlowStream

java.lang.Object
  gpars.dataflow.DataFlowStream

@SuppressWarnings({"LawOfDemeter", "MethodReturnOfConcreteClass", "AnonymousInnerClass", "AnonymousInnerClassWithTooManyMethods"})
class DataFlowStream

Represents a thread-safe data flow stream. Values or DataFlowVariables are added using the '<<' operator and safely read once available using the 'val' property. The iterative methods like each(), collect(), iterator(), any(), all() or the for loops work with snapshots of the stream at the time of calling the particular method. For actors and Dataflow Operators the asynchronous non-blocking variants of the getValAsync() methods can be used. They register the request to read a value and will send a message to the actor or operator once the value is available.

author:
Vaclav Pech Date: Jun 5, 2009


Constructor Summary
DataFlowStream()

 
Method Summary
T getVal()

Retrieves the value at the head of the buffer.

void getValAsync(MessageStream messageStream)

Asynchronously retrieves the value at the head of the buffer.

void getValAsync(Object attachment, MessageStream messageStream)

Asynchronously retrieves the value at the head of the buffer.

Iterator iterator()

Returns an iterator over a current snapshot of the buffer's content.

void leftShift(DataFlowExpression ref)

Adds a DataFlowVariable to the buffer.

void leftShift(T value)

Adds a DataFlowVariable representing the passed in value to the buffer.

int length()

Returns the current size of the buffer

void rightShift(Closure closure)

Schedule closure to be executed by pooled actor after data became available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled

String toString()

void whenBound(Closure closure)

Schedule closure to be executed by pooled actor each time after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.

void whenBound(MessageStream stream)

Send all pieces of data bound in the future to the provided stream when it becomes available

void whenNextBound(Closure closure)

Schedule closure to be executed by pooled actor after the next data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.

void whenNextBound(MessageStream stream)

Send the next bound piece of data to the provided stream when it becomes available

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

DataFlowStream

DataFlowStream()


 
Method Detail

getVal

public T getVal()
Retrieves the value at the head of the buffer. Blocks until a value is available.
return:
The value bound to the DFV at the head of the stream
throws:
InterruptedException If the current thread is interrupted


getValAsync

public void getValAsync(MessageStream messageStream)
Asynchronously retrieves the value at the head of the buffer. Sends the actual value of the variable as a message back the the supplied actor once the value has been bound. The actor can perform other activities or release a thread back to the pool by calling react() waiting for the message with the value of the Dataflow Variable.
param:
messageStream The actor to notify when a value is bound


getValAsync

public void getValAsync(Object attachment, MessageStream messageStream)
Asynchronously retrieves the value at the head of the buffer. Sends a message back the the supplied actor / operator with a map holding the supplied index under the 'index' key and the actual value of the variable under the 'result' key once the value has been bound. The actor/operator can perform other activities or release a thread back to the pool by calling react() waiting for the message with the value of the Dataflow Variable.
param:
attachment An arbitrary value to identify operator channels and so match requests and replies
param:
messageStream The actor / operator to notify when a value is bound


iterator

public Iterator iterator()
Returns an iterator over a current snapshot of the buffer's content. The next() method returns actual values not the DataFlowVariables.
return:
AN iterator over all DFVs in the queue


leftShift

@SuppressWarnings("unchecked")
public void leftShift(DataFlowExpression ref)
Adds a DataFlowVariable to the buffer. Implementation detail - in fact another DFV is added to the buffer and an asynchronous 'whenBound' handler is registered with the supplied DFV to update the one stored in the buffer.
param:
ref The DFV to add to the stream


leftShift

public void leftShift(T value)
Adds a DataFlowVariable representing the passed in value to the buffer.
param:
value The value to bind to the head of the stream


length

public int length()
Returns the current size of the buffer
return:
Number of DFVs in the queue


rightShift

public void rightShift(Closure closure)
Schedule closure to be executed by pooled actor after data became available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled
param:
closure closure to execute when data available


toString

@Override
public String toString()


whenBound

public void whenBound(Closure closure)
Schedule closure to be executed by pooled actor each time after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.
param:
closure closure to execute when data available


whenBound

public void whenBound(MessageStream stream)
Send all pieces of data bound in the future to the provided stream when it becomes available
param:
stream stream where to send result


whenNextBound

public void whenNextBound(Closure closure)
Schedule closure to be executed by pooled actor after the next data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.
param:
closure closure to execute when data available


whenNextBound

public void whenNextBound(MessageStream stream)
Send the next bound piece of data to the provided stream when it becomes available
param:
stream stream where to send result


 

Groovy Documentation