groovyx.gpars.dataflow
Class DataflowVariable<T>

java.lang.Object
  extended by groovyx.gpars.serial.WithSerialId
      extended by groovyx.gpars.dataflow.DataflowExpression<T>
          extended by 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

Nested Class Summary
static class DataflowVariable.RemoteDataflowVariable<T>
           
 
Nested classes/interfaces inherited from class groovyx.gpars.dataflow.DataflowExpression
DataflowExpression.BindDataflow<T>, DataflowExpression.DataflowExpressionsCollector
 
Field Summary
private static long serialVersionUID
           
 
Fields inherited from class groovyx.gpars.dataflow.DataflowExpression
S_INITIALIZED, S_INITIALIZING, S_NOT_INITIALIZED, state, stateUpdater, value, waitingUpdater
 
Fields inherited from class groovyx.gpars.serial.WithSerialId
serialHandle
 
Constructor Summary
DataflowVariable()
          Creates a new unbound Dataflow Variable
 
Method Summary
private  DataflowWriteChannel<T> bindDFV(DataflowReadChannel<T> ref)
           
 T get()
          Retrieves the value of the variable, blocking until a value is available
 T get(long timeout, java.util.concurrent.TimeUnit units)
          Retrieves the value of the variable, blocking up to given timeout, if the value has not been assigned yet.
 java.lang.Class<DataflowVariable.RemoteDataflowVariable> getRemoteClass()
          Class of remote object to be created
 DataflowWriteChannel<T> leftShift(DataflowReadChannel<T> ref)
          Assigns a value from one DataflowVariable instance to this variable.
 DataflowWriteChannel<T> leftShift(T value)
          Assigns a value to the variable.
 
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 groovyx.gpars.serial.WithSerialId
createRemoteHandle, getOrCreateSerialHandle, writeReplace
 
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
 
Methods inherited from interface groovyx.gpars.dataflow.DataflowWriteChannel
bind
 
Methods inherited from interface groovyx.gpars.dataflow.Promise
getVal, getVal, getValAsync, getValAsync, isBound, rightShift, whenBound, whenBound, whenBound, whenBound
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

DataflowVariable

public DataflowVariable()
Creates a new unbound Dataflow Variable

Method Detail

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

Copyright © 2008–2010 Václav Pech. All Rights Reserved.