Groovy Documentation

gpars.dataflow
[Java] Class DataFlowExpression

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

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

The base class for all dataflow elements.

Authors:
Alex Tkachman, Vaclav Pech


Nested Class Summary
static class DataFlowExpression.BindDataFlow

Represents a remote message binding a value to a remoted DataFlowExpression

 
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 Object value

Holds the actual value.

protected static AtomicReferenceFieldUpdater waitingUpdater

Updater for the waiting field

 
Method Summary
protected def DataFlowExpression()

Creates a new unbound Dataflow Expression

void bind(Object value)

Assigns a value to the variable.

void bindSafely(Object value)

Assigns a value to the variable.

void doBindRemote(UUID hostId, Object message)

Binds the value after receiving a bing message over the wire

protected Object evaluate()

Evaluate expression after the ones we depend on are ready

groovy.lang.MetaClass getMetaClass()

Object getProperty(String propertyName)

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

Object getVal()

Reads the value of the variable.

Object getVal(long timeout, TimeUnit units)

Reads the value of the variable.

void getValAsync(MessageStream callback)

Asynchronously retrieves the value of the variable.

Object invokeMethod(String name, Object args)

boolean isBound()

Check if value has been set already for this expression

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

void setMetaClass(groovy.lang.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(DataFlowExpression.DataFlowExpressionsCollector listener)

String toString()

static DataFlowExpression transform(Object another, groovy.lang.Closure closure)

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


 
Method Detail

DataFlowExpression

protected def DataFlowExpression()
Creates a new unbound Dataflow Expression


bind

public void bind(Object 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.
Parameters:
value - The value to assign


bindSafely

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


doBindRemote

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


evaluate

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


getMetaClass

public groovy.lang.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
Parameters:
propertyName - The name of the property to retrieve
Returns:
The property value, instance of DataFlowGetPropertyExpression


getVal

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


getVal

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


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.
Parameters:
callback - An actor to send the bound value to.


invokeMethod

public Object invokeMethod(String name, Object args)


isBound

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


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


setMetaClass

public void setMetaClass(groovy.lang.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(DataFlowExpression.DataFlowExpressionsCollector listener)


toString

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


transform

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


whenBound

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


whenBound

public void whenBound(MessageStream stream)
Send the bound data to provided stream when it becomes available
Parameters:
stream - stream where to send result


 

Groovy Documentation