Groovy Documentation

gpars.dataflow
Class DataFlowExpression

java.lang.Object
  groovyx.gpars.serial.WithSerialId
      gpars.dataflow.DataFlowExpression
All Implemented Interfaces:
groovy.lang.GroovyObject

@SuppressWarnings({"UnqualifiedStaticUsage", "CallToSimpleGetterFromWithinClass"})
class DataFlowExpression
extends WithSerialId

The base class for all dataflow elements.

author:
Alex Tkachman, Vaclav Pech


Nested Class Summary
class DataFlowExpression.BindDataFlow

Represents a remote message binding a value to a remoted DataFlowExpression

class DataFlowExpression.DataFlowExpressionsCollector

Listener for availability of data flow expressions we depend from

class DataFlowExpression.TransformMany

class DataFlowExpression.TransformOne

class DataFlowExpression.WaitingThread

A logical representation of a synchronous or asynchronous request to read the value once it is bound.

 
Field Summary
protected static int S_INITIALIZED

protected static int S_INITIALIZING

protected static int S_NOT_INITIALIZED

Possible states

protected int state

Holds the current state of the variable

protected static AtomicIntegerFieldUpdater stateUpdater

Updater for the state field

protected T value

Holds the actual value.

protected static AtomicReferenceFieldUpdater waitingUpdater

Updater for the waiting field

 
Constructor Summary
DataFlowExpression()

 
Method Summary
protected def DataFlowExpression()

Creates a new unbound Dataflow Expression

void bind(T value)

Assigns a value to the variable.

void bindSafely(T value)

Assigns a value to the variable.

void doBindRemote(UUID hostId, T message)

Binds the value after receiving a bing message over the wire

protected T evaluate()

Evaluate expression after the ones we depend on are ready

MetaClass getMetaClass()

Object getProperty(String propertyName)

Returns either standard property of expression or creates expression, which will request given property when receiver became available

T getVal()

Reads the value of the variable.

T getVal(long timeout, TimeUnit units)

Reads the value of the variable.

void getValAsync(MessageStream callback)

Asynchronously retrieves the value of the variable.

void getValAsync(Object attachment, MessageStream callback)

Used by Dataflow operators.

Object invokeMethod(String name, Object args)

boolean isBound()

Check if value has been set already for this expression

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

void setMetaClass(MetaClass metaClass)

void setProperty(String propertyName, Object newValue)

protected void subscribe()

Utility method to call at the very end of constructor of derived expressions.

protected void subscribe(DataFlowExpressionsCollector listener)

String toString()

static DataFlowExpression transform(Object another, Closure closure)

void whenBound(Closure closure)

Schedule closure to be executed by pooled actor 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 the bound data to provided stream when it becomes available

 

Field Detail

S_INITIALIZED

protected static final int S_INITIALIZED


S_INITIALIZING

protected static final int S_INITIALIZING


S_NOT_INITIALIZED

protected static final int S_NOT_INITIALIZED
Possible states


state

protected int state
Holds the current state of the variable


stateUpdater

protected static final AtomicIntegerFieldUpdater stateUpdater
Updater for the state field


value

@SuppressWarnings({"InstanceVariableMayNotBeInitialized"})
protected T value
Holds the actual value. Is null before a concrete value is bound to it.


waitingUpdater

protected static final AtomicReferenceFieldUpdater waitingUpdater
Updater for the waiting field


 
Constructor Detail

DataFlowExpression

DataFlowExpression()


 
Method Detail

DataFlowExpression

protected def DataFlowExpression()
Creates a new unbound Dataflow Expression


bind

public void bind(T value)
Assigns a value to the variable. Can only be invoked once on each instance of DataFlowVariable Throws exception if invoked on an already bound variable.
param:
value The value to assign


bindSafely

public void bindSafely(T value)
Assigns a value to the variable. Returns silently if invoked on an already bound variable.
param:
value The value to assign


doBindRemote

public void doBindRemote(UUID hostId, T message)
Binds the value after receiving a bing message over the wire
param:
hostId Id of the bind originator host
param:
message The value to bind


evaluate

protected T evaluate()
Evaluate expression after the ones we depend on are ready
return:
value to bind


getMetaClass

public MetaClass getMetaClass()


getProperty

public Object getProperty(String propertyName)
Returns either standard property of expression or creates expression, which will request given property when receiver became available
param:
propertyName The name of the property to retrieve
return:
The property value, instance of DataFlowGetPropertyExpression


getVal

public T getVal()
Reads the value of the variable. Blocks, if the value has not been assigned yet.
return:
The actual value
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound


getVal

public T getVal(long timeout, TimeUnit units)
Reads the value of the variable. Blocks up to given timeout, if the value has not been assigned yet.
param:
timeout The timeout value
param:
units Units for the timeout
return:
The actual value
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound


getValAsync

public void getValAsync(MessageStream callback)
Asynchronously retrieves the value of the variable. 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:
callback An actor to send the bound value to.


getValAsync

public void getValAsync(Object attachment, MessageStream callback)
Used by Dataflow operators. Asynchronously retrieves the value of the variable. Sends a message back the the supplied MessageStream with a map holding the supplied attachment under the 'attachment' key and the actual value of the variable under the 'result' key once the value has been bound. Attachment is an arbitrary value helping the actor.operator match its request with the reply. 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 arbitrary non-null attachment if reader needs better identification of result
param:
callback An actor to send the bound value plus the supplied index to.


invokeMethod

public Object invokeMethod(String name, Object args)


isBound

public boolean isBound()
Check if value has been set already for this expression
return:
true if bound already


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


setMetaClass

public void setMetaClass(MetaClass metaClass)


setProperty

public void setProperty(String propertyName, Object newValue)


subscribe

protected final void subscribe()
Utility method to call at the very end of constructor of derived expressions. Create and subscribe listener


subscribe

protected void subscribe(DataFlowExpressionsCollector listener)


toString

@SuppressWarnings({"ArithmeticOnVolatileField"})
@Override
public String toString()


transform

@SuppressWarnings("unchecked")
public static DataFlowExpression transform(Object another, Closure closure)


whenBound

public void whenBound(Closure closure)
Schedule closure to be executed by pooled actor 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 the bound data to provided stream when it becomes available
param:
stream stream where to send result


 

Groovy Documentation