org.codehaus.gpars

groovyx.gpars.dataflow
[Java] Class DataflowVariable

java.lang.Object
  groovyx.gpars.serial.WithSerialId
      groovyx.gpars.dataflow.expression.DataflowExpression
          groovyx.gpars.dataflow.DataflowVariable
All Implemented Interfaces:
DataflowChannel, Promise

@SuppressWarnings({"AccessingNonPublicFieldOfAnotherObject", "UnqualifiedStaticUsage"})
public class DataflowVariable
extends DataflowExpression

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.

Parameters:
- Type of values to bind with the DataflowVariable
Authors:
Vaclav Pech, Alex Tkachman Date: Jun 4, 2009


Nested Class Summary
static class DataflowVariable.RemoteDataflowVariable

 
Field Summary
private static long serialVersionUID

 
Fields inherited from class DataflowExpression
ATTACHMENT, RESULT, S_INITIALIZED, S_INITIALIZING, S_NOT_INITIALIZED, dummyWaitingThread, error, eventManager, metaClass, serialVersionUID, state, value, waiting
 
Fields inherited from class WithSerialId
serialHandle, serialVersionUID
 
Constructor Summary
DataflowVariable()

Creates a new unbound Dataflow Variable

 
Method Summary
private DataflowWriteChannel bindDFV(DataflowReadChannel ref)

java.lang.Object get()

Retrieves the value of the variable, blocking until a value is available

java.lang.Object 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.Throwable getError()

Returns the error bound to the promise

java.lang.Class getRemoteClass()

boolean isError()

Checks if the promise is bound to an error

DataflowWriteChannel leftShift(java.lang.Object value)

Assigns a value to the variable.

DataflowWriteChannel leftShift(DataflowReadChannel ref)

Assigns a value from one DataflowVariable instance to this variable.

boolean shouldThrowTimeout()

Promise then(groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data became available.

Promise then(Pool pool, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data becomes available.

Promise then(PGroup group, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data becomes available.

 
Methods inherited from class DataflowExpression
DataflowExpression, binaryChoice, binaryChoice, binaryChoice, binaryChoice, binaryChoice, binaryChoice, bind, bindError, bindSafely, bindUnique, chainWith, chainWith, chainWith, chainWith, chainWith, chainWith, choice, choice, choice, choice, choice, choice, doBind, doBindImpl, doBindRemote, evaluate, filter, filter, filter, filter, filter, filter, fireOnMessage, getEventManager, getMetaClass, getProperty, getVal, getVal, getValAsync, getValAsync, handleInterruption, into, into, into, into, into, into, invokeMethod, isBound, join, join, length, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, notifyRemote, or, or, poll, rightShift, scheduleCallback, separate, separate, separate, separate, separate, separate, setMetaClass, setProperty, split, split, split, split, split, split, split, split, split, split, split, split, subscribe, subscribe, tap, tap, tap, tap, tap, tap, then, then, then, toString, transform, whenBound, whenBound, whenBound, whenBound, wheneverBound, wheneverBound
 
Methods inherited from class WithSerialId
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace
 

Field Detail

serialVersionUID

private static final long serialVersionUID


 
Constructor Detail

DataflowVariable

public DataflowVariable()
Creates a new unbound Dataflow Variable


 
Method Detail

bindDFV

private DataflowWriteChannel bindDFV(DataflowReadChannel ref)


get

@Override
@SuppressWarnings({"ProhibitedExceptionDeclared"})
public java.lang.Object get()
Retrieves the value of the variable, blocking until a value is available
throws:
Throwable If the stored value is an exception instance it gets re-thrown
Returns:
The value stored in the variable


get

@Override
@SuppressWarnings({"ProhibitedExceptionDeclared"})
public final java.lang.Object 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.
throws:
Throwable If the stored value is an exception instance it gets re-thrown
Parameters:
timeout - The timeout value
units - Units for the timeout
Returns:
The value stored in the variable


getError

@Override
public final java.lang.Throwable getError()
Returns the error bound to the promise
throws:
IllegalStateException If not bound or not bound to an error
Returns:
The error


getRemoteClass

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public java.lang.Class getRemoteClass()


isError

@Override
public final boolean isError()
Checks if the promise is bound to an error
Returns:
True, if an error has been bound


leftShift

@Override
public DataflowWriteChannel leftShift(java.lang.Object value)
Assigns a value to the variable. Can only be invoked once on each instance of DataflowVariable
Parameters:
value - The value to assign


leftShift

@Override
public DataflowWriteChannel leftShift(DataflowReadChannel ref)
Assigns a value from one DataflowVariable instance to this variable. Can only be invoked once on each instance of DataflowVariable
Parameters:
ref - The DataflowVariable instance the value of which to bind


shouldThrowTimeout

boolean shouldThrowTimeout()


then

@Override
public final Promise then(groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data became available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled
Parameters:
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

@Override
public final Promise then(Pool pool, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
pool - The thread pool to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

@Override
public final Promise then(PGroup group, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
group - The PGroup to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


 

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