groovyx.gpars.dataflow
Class DataflowVariable<T>
java.lang.Object
groovyx.gpars.serial.WithSerialId
groovyx.gpars.dataflow.DataflowExpression<T>
groovyx.gpars.dataflow.DataflowVariable<T>
- Type Parameters:
T
- Type of values to bind with the DataflowVariable
- All Implemented Interfaces:
- groovy.lang.GroovyObject, DataflowChannel<T>, DataflowReadChannel<T>, DataflowWriteChannel<T>, Promise<T>, java.io.Serializable
- Direct Known Subclasses:
- DataflowVariable.RemoteDataflowVariable
public class DataflowVariable<T>
- extends DataflowExpression<T>
- implements DataflowChannel<T>, Promise<T>
Represents a thread-safe single-assignment, multi-read variable.
Each instance of DataflowVariable can be read repeatedly any time using the 'val' property and assigned once
in its lifetime using the '<<' operator. Reads preceding assignment will be blocked until the value
is assigned.
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, Alex Tkachman
Date: Jun 4, 2009
- See Also:
- Serialized Form
Methods inherited from class groovyx.gpars.dataflow.DataflowExpression |
bind, bindSafely, bindUnique, doBindRemote, evaluate, getMetaClass, getProperty, getVal, getVal, getValAsync, getValAsync, invokeMethod, isBound, join, join, poll, rightShift, setMetaClass, setProperty, subscribe, subscribe, toString, transform, whenBound, whenBound, whenBound, whenBound, wheneverBound, wheneverBound |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface groovyx.gpars.dataflow.DataflowReadChannel |
getVal, getVal, getValAsync, getValAsync, isBound, poll, rightShift, whenBound, whenBound, whenBound, whenBound, wheneverBound, wheneverBound |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
DataflowVariable
public DataflowVariable()
- Creates a new unbound Dataflow Variable
leftShift
public DataflowWriteChannel<T> leftShift(T value)
- Assigns a value to the variable. Can only be invoked once on each instance of DataflowVariable
- Specified by:
leftShift
in interface DataflowWriteChannel<T>
- Parameters:
value
- The value to assign
- Returns:
- The current channel instance
leftShift
public DataflowWriteChannel<T> leftShift(DataflowReadChannel<T> ref)
- Assigns a value from one DataflowVariable instance to this variable.
Can only be invoked once on each instance of DataflowVariable
- Specified by:
leftShift
in interface DataflowWriteChannel<T>
- Parameters:
ref
- The DataflowVariable instance the value of which to bind
- Returns:
- The current channel instance
bindDFV
private DataflowWriteChannel<T> bindDFV(DataflowReadChannel<T> ref)
get
public T get()
throws java.lang.Throwable
- Retrieves the value of the variable, blocking until a value is available
- Specified by:
get
in interface Promise<T>
- Returns:
- The value stored in the variable
- Throws:
java.lang.Throwable
- If the stored value is an exception instance it gets re-thrown
get
public T get(long timeout,
java.util.concurrent.TimeUnit units)
throws java.lang.Throwable
- Retrieves the value of the variable, blocking up to given timeout, if the value has not been assigned yet.
- Specified by:
get
in interface Promise<T>
- Parameters:
timeout
- The timeout valueunits
- Units for the timeout
- Returns:
- The value stored in the variable
- Throws:
java.lang.Throwable
- If the stored value is an exception instance it gets re-thrown
getRemoteClass
public java.lang.Class<DataflowVariable.RemoteDataflowVariable> getRemoteClass()
- Description copied from class:
WithSerialId
- Class of remote object to be created
- Overrides:
getRemoteClass
in class WithSerialId
- Returns:
- Throws UnsupportedOperationException