Groovy Documentation

gpars.dataflow
[Java] Class DataFlowStream

java.lang.Object
  gpars.dataflow.DataFlowStream

@SuppressWarnings({"LawOfDemeter", "MethodReturnOfConcreteClass", "AnonymousInnerClass", "AnonymousInnerClassWithTooManyMethods"})
public final 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.

Authors:
Vaclav Pech Date: Jun 5, 2009


Method Summary
Object 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(Object value)

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

int length()

Returns the current size of the buffer

void rightShift(groovy.lang.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(groovy.lang.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(groovy.lang.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
 

Method Detail

getVal

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


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.
Parameters:
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.
Parameters:
attachment - An arbitrary value to identify operator channels and so match requests and replies
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.
Returns:
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.
Parameters:
ref - The DFV to add to the stream


leftShift

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


length

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


rightShift

public void rightShift(groovy.lang.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
Parameters:
closure - closure to execute when data available


toString

@Override
public String toString()


whenBound

public void whenBound(groovy.lang.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.
Parameters:
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
Parameters:
stream - stream where to send result


whenNextBound

public void whenNextBound(groovy.lang.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.
Parameters:
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
Parameters:
stream - stream where to send result


 

Groovy Documentation