org.codehaus.gpars

groovyx.gpars.dataflow
[Java] Class DataflowExpression

java.lang.Object
  groovyx.gpars.serial.WithSerialId
      groovyx.gpars.dataflow.DataflowExpression
All Implemented Interfaces:
groovy.lang.GroovyObject, DataflowReadChannel

@SuppressWarnings({"UnqualifiedStaticUsage", "CallToSimpleGetterFromWithinClass", "ConstantDeclaredInAbstractClass"})
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

class DataflowExpression.DataflowExpressionsCollector

Listener for availability of data flow expressions we depend from

private static class DataflowExpression.TransformMany

private static class DataflowExpression.TransformOne

private static class DataflowExpression.WaitingThread

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

 
Field Summary
private static java.lang.String ATTACHMENT

private static java.lang.String RESULT

protected static int S_INITIALIZED

protected static int S_INITIALIZING

protected static int S_NOT_INITIALIZED

Possible states

private static DataflowExpression.WaitingThread dummyWaitingThread

A request chain terminator

private groovy.lang.MetaClass metaClass

The current metaclass

private static long serialVersionUID

protected int state

Holds the current state of the variable

protected static java.util.concurrent.atomic.AtomicIntegerFieldUpdater stateUpdater

Updater for the state field

protected T value

Holds the actual value.

private DataflowExpression.WaitingThread waiting

Points to the head of the chain of requests waiting for a value to be bound

protected static java.util.concurrent.atomic.AtomicReferenceFieldUpdater waitingUpdater

Updater for the waiting field

 
Fields inherited from class WithSerialId
serialHandle, serialVersionUID
 
Constructor Summary
DataflowExpression()

 
Method Summary
protected java.lang.Object 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 bindUnique(T value)

Assigns a value to the variable.

private void doBind(T value)

Performs the actual bind operation, unblocks all blocked threads and informs all asynchronously waiting actors.

private void doBindImpl(T value)

void doBindRemote(java.util.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

groovy.lang.MetaClass getMetaClass()

java.lang.Object getProperty(java.lang.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, java.util.concurrent.TimeUnit units)

Reads the value of the variable.

void getValAsync(MessageStream callback)

Asynchronously retrieves the value of the variable.

void getValAsync(java.lang.Object attachment, MessageStream callback)

Used by Dataflow operators.

private static void handleInterruption(java.util.concurrent.atomic.AtomicBoolean newWaiting)

java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)

boolean isBound()

Check if value has been set already for this expression

void join()

Blocks, if the value has not been assigned yet to the DataflowVariable

void join(long timeout, java.util.concurrent.TimeUnit units)

Blocks, if the value has not been assigned yet to the DataflowVariable

private void notifyRemote(java.util.UUID hostId)

Sends notifications to all subscribers

DataflowExpression poll()

Retrieves the bound value.

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

private void scheduleCallback(java.lang.Object attachment, MessageStream callback)

Sends the result back to the actor, which is waiting asynchronously for the value to be bound.

void setMetaClass(groovy.lang.MetaClass metaClass)

void setProperty(java.lang.String propertyName, java.lang.Object newValue)

protected void subscribe()

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

protected void subscribe(DataflowExpression.DataflowExpressionsCollector listener)

java.lang.String toString()

static DataflowExpression transform(java.lang.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(Pool pool, 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(PGroup group, 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

void wheneverBound(groovy.lang.Closure closure)

Send all pieces of data bound in the future to the provided stream when it becomes available *

void wheneverBound(MessageStream stream)

Send all pieces of data bound in the future to the provided stream when it becomes available

 
Methods inherited from class WithSerialId
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

ATTACHMENT

private static final java.lang.String ATTACHMENT


RESULT

private static final java.lang.String RESULT


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


dummyWaitingThread

private static final DataflowExpression.WaitingThread dummyWaitingThread
A request chain terminator


metaClass

private groovy.lang.MetaClass metaClass
The current metaclass


serialVersionUID

private static final long serialVersionUID


state

protected int state
Holds the current state of the variable


stateUpdater

@SuppressWarnings({"rawtypes", "RawUseOfParameterizedType"})
protected static final java.util.concurrent.atomic.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.


waiting

@SuppressWarnings({"UnusedDeclaration"})
    //modified through stateUpdater
private DataflowExpression.WaitingThread waiting
Points to the head of the chain of requests waiting for a value to be bound


waitingUpdater

@SuppressWarnings({"rawtypes", "RawUseOfParameterizedType"})
protected static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater waitingUpdater
Updater for the waiting field


 
Constructor Detail

DataflowExpression

DataflowExpression()


 
Method Detail

DataflowExpression

protected java.lang.Object DataflowExpression()
Creates a new unbound Dataflow Expression


bind

public final void bind(T value)
Assigns a value to the variable. Can only be invoked once on each instance of DataflowVariable. Allows attempts to bind to equal values. Throws exception if invoked on an already bound variable.
Parameters:
value - The value to assign


bindSafely

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


bindUnique

public final void bindUnique(T value)
Assigns a value to the variable. Can only be invoked once on each instance of DataflowVariable Doesn't allow attempts to bind to equal values. Throws exception if invoked on an already bound variable.
Parameters:
value - The value to assign


doBind

private void doBind(T value)
Performs the actual bind operation, unblocks all blocked threads and informs all asynchronously waiting actors.
Parameters:
value - The value to assign


doBindImpl

private void doBindImpl(T value)


doBindRemote

public final void doBindRemote(java.util.UUID hostId, T 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 T evaluate()
Evaluate expression after the ones we depend on are ready
Returns:
value to bind


getMetaClass

@Override
public final groovy.lang.MetaClass getMetaClass()


getProperty

@Override
public final java.lang.Object getProperty(java.lang.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

@Override
public final T 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

@Override
public final T getVal(long timeout, java.util.concurrent.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

@Override
public final 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.


getValAsync

@Override
public final void getValAsync(java.lang.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.
Parameters:
attachment - arbitrary non-null attachment if reader needs better identification of result
callback - An actor to send the bound value plus the supplied index to.


handleInterruption

private static void handleInterruption(java.util.concurrent.atomic.AtomicBoolean newWaiting)


invokeMethod

@Override
public final java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)


isBound

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


join

public final void join()
Blocks, if the value has not been assigned yet to the DataflowVariable
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound


join

public final void join(long timeout, java.util.concurrent.TimeUnit units)
Blocks, if the value has not been assigned yet to the DataflowVariable
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


notifyRemote

private void notifyRemote(java.util.UUID hostId)
Sends notifications to all subscribers
Parameters:
hostId - The local host id


poll

@Override
public final DataflowExpression poll()
Retrieves the bound value. Returns null, if no value is available.
throws:
InterruptedException If the current thread is interrupted
Returns:
The value bound to the DFV or null


rightShift

@Override
public final 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


scheduleCallback

@SuppressWarnings({"TypeMayBeWeakened"})
private void scheduleCallback(java.lang.Object attachment, MessageStream callback)
Sends the result back to the actor, which is waiting asynchronously for the value to be bound. The message will either be a map holding the attachment under the 'attachment' key and the actual bound value under the 'result' key, or it will be the result itself if the callback doesn't care about the index.
Parameters:
attachment - An arbitrary object identifying the request
callback - The actor to send the message to


setMetaClass

@Override
public final void setMetaClass(groovy.lang.MetaClass metaClass)


setProperty

@Override
public final void setProperty(java.lang.String propertyName, java.lang.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 java.lang.String toString()


transform

public static DataflowExpression transform(java.lang.Object another, groovy.lang.Closure closure)


whenBound

@Override
public final 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

@Override
public void whenBound(Pool pool, 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:
pool - The thread pool to use for task scheduling for asynchronous message delivery
closure - closure to execute when data available


whenBound

@Override
public final void whenBound(PGroup group, 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:
group - The PGroup to use for task scheduling for asynchronous message delivery
closure - closure to execute when data available


whenBound

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


wheneverBound

@Override
public final void wheneverBound(groovy.lang.Closure closure)
Send all pieces of data bound in the future to the provided stream when it becomes available *
Parameters:
closure - closure to execute when data available


wheneverBound

@Override
public final void wheneverBound(MessageStream stream)
Send all pieces of data bound in the future to the provided stream when it becomes available
Parameters:
stream - stream where to send result


 

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