Groovy Documentation

gpars.dataflow
Class DataFlows

java.lang.Object
  gpars.dataflow.DataFlows

class DataFlows

Convenience class that makes working with DataFlowVariables more comfortable. See the implementation of groovyx.gpars.samples.dataflow.DemoDataFlows for a full example. A DataFlows instance is a bean with properties of type DataFlowVariable. Property access is relayed to the access methods of DataFlowVariable. Each property is initialized lazily the first time it is accessed. Non-String named properties can be also accessed using array-like indexing syntax This allows a rather compact usage of DataFlowVariables like

 final df = new DataFlows()
 start { df[0] = df.x + df.y }
 start { df.x = 10 }
 start { df.y = 5 }
 assert 15 == df[0]
 
author:
Vaclav Pech, Dierk Koenig, Alex Tkachman Date: Sep 3, 2009


Property Summary
static int DEFAULT_CONCURRENCY_LEVEL

static int DEFAULT_INITIAL_CAPACITY

static float DEFAULT_LOAD_FACTOR

static int MAX_SEGMENTS

 
Constructor Summary
DataFlows(int initialCapacity = DEFAULT_INITIAL_CAPACITY, float loadFactor = DEFAULT_LOAD_FACTOR, int concurrencyLevel = DEFAULT_CONCURRENCY_LEVEL)

Constructor that supports the various constructors of the underlying ConcurrentHashMap (unless the one with Map parameter).

 
Method Summary
def contains(def name)

Checks whether a certain key is contained in the map.

def getAt(def index)

def getProperty(String name)

def invokeMethod(String name, Object args)

Invokes the given method.

Iterator iterator()

Convenience method to play nicely with Groovy object iteration methods.

void putAt(def index, def value)

Binds the value to the DataFlowVariable that is associated with the property "index".

def remove(def name)

Removes a DFV from the map and binds it to null, if it has not been bound yet

void setProperty(String name, def value)

Binds the value to the DataFlowVariable that is associated with the property "name".

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Property Detail

DEFAULT_CONCURRENCY_LEVEL

static final int DEFAULT_CONCURRENCY_LEVEL


DEFAULT_INITIAL_CAPACITY

static final int DEFAULT_INITIAL_CAPACITY


DEFAULT_LOAD_FACTOR

static final float DEFAULT_LOAD_FACTOR


MAX_SEGMENTS

static final int MAX_SEGMENTS


 
Constructor Detail

DataFlows

public DataFlows(int initialCapacity = DEFAULT_INITIAL_CAPACITY, float loadFactor = DEFAULT_LOAD_FACTOR, int concurrencyLevel = DEFAULT_CONCURRENCY_LEVEL)
Constructor that supports the various constructors of the underlying ConcurrentHashMap (unless the one with Map parameter).
see:
ConcurrentHashMap


 
Method Detail

contains

public def contains(def name)
Checks whether a certain key is contained in the map. Doesn't check, whether the variable has already been bound.
param:
name The name of the DFV to check.


getAt

public def getAt(def index)
return:
the value of the DataFlowVariable associated with the property "name". May block if the value is not scalar.
see:
DataFlowVariable#getVal


getProperty

public def getProperty(String name)
return:
the value of the DataFlowVariable associated with the property "name". May block if the value is not scalar.
see:
DataFlowVariable#getVal


invokeMethod

public def invokeMethod(String name, Object args)
Invokes the given method. Allows for invoking whenBound() on the dataflow variables.
 def df = new DataFlows()
 df.var {*     println "Variable bound to $it"
}* 
param:
name the name of the method to call (the variable name)
param:
args the arguments to use for the method call (a closure to invoke when a value is bound)
return:
the result of invoking the method (void)


iterator

public Iterator iterator()
Convenience method to play nicely with Groovy object iteration methods. The iteration restrictions of ConcurrentHashMap concerning parallel access and ConcurrentModificationException apply.
return:
iterator over the stored key:DataFlowVariable value pairs
see:
DataFlowsTest#testIterator


putAt

void putAt(def index, def value)
Binds the value to the DataFlowVariable that is associated with the property "index".
param:
value a scalar or a DataFlowVariable that may block on value access
see:
DataFlowVariable#bind


remove

public def remove(def name)
Removes a DFV from the map and binds it to null, if it has not been bound yet
param:
name The name of the DFV to remove.


setProperty

void setProperty(String name, def value)
Binds the value to the DataFlowVariable that is associated with the property "name".
param:
value a scalar or a DataFlowVariable that may block on value access
see:
DataFlowVariable#bind


 

Groovy Documentation