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]
Modifiers | Name | Description |
---|---|---|
static int |
DEFAULT_CONCURRENCY_LEVEL |
|
static int |
DEFAULT_INITIAL_CAPACITY |
|
static float |
DEFAULT_LOAD_FACTOR |
|
private static DataflowVariable<java.lang.Object> |
DUMMY |
|
private java.lang.Object |
lock |
|
private java.util.concurrent.ConcurrentMap<java.lang.Object, DataflowVariable<java.lang.Object>> |
variables |
Constructor and description |
---|
Dataflows
(int initialCapacity, float loadFactor, int concurrencyLevel) Constructor that supports the various constructors of the underlying ConcurrentHashMap (unless the one with Map parameter). |
Dataflows
() Constructor with default values for building the underlying ConcurrentHashMap |
Type | Name and description |
---|---|
boolean |
contains(java.lang.Object name) Checks whether a certain key is contained in the map. |
private DataflowVariable<java.lang.Object> |
ensureToContainVariable(java.lang.Object name) The idea is following:
|
java.lang.Object |
getAt(int index) Retrieves the DFV associated with the given index |
java.lang.Object |
getProperty(java.lang.String property)
|
java.lang.Object |
invokeMethod(java.lang.String name, java.lang.Object args) Invokes the given method. |
java.util.Iterator<Map.Entry<java.lang.Object, DataflowVariable<java.lang.Object>>> |
iterator() Convenience method to play nicely with Groovy object iteration methods. |
void |
putAt(java.lang.Object index, java.lang.Object value) Binds the value to the DataflowVariable that is associated with the property "index". |
private DataflowVariable<java.lang.Object> |
putNewUnderLock(java.lang.Object name) Utility method extracted just to help JIT |
DataflowVariable<java.lang.Object> |
remove(java.lang.Object name) Removes a DFV from the map and binds it to null, if it has not been bound yet |
void |
setProperty(java.lang.String property, java.lang.Object newValue) Binds the value to the DataflowVariable that is associated with the property "name". |
Methods inherited from class | Name |
---|---|
class groovy.lang.GroovyObjectSupport |
groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll() |
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), 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() |
Constructor that supports the various constructors of the underlying ConcurrentHashMap (unless the one with Map parameter).
initialCapacity
- the initial capacity. The implementation
performs internal sizing to accommodate this many elements.loadFactor
- the load factor threshold, used to control resizing.
Resizing may be performed when the average number of elements per
bin exceeds this threshold.concurrencyLevel
- the estimated number of concurrently
updating threads. The implementation performs internal sizing
to try to accommodate this many threads.Constructor with default values for building the underlying ConcurrentHashMap
Checks whether a certain key is contained in the map. Doesn't check, whether the variable has already been bound.
name
- The name of the DFV to check.The idea is following:
Unfortunately we have to sync on this as there is no better option (God forbid to sync on name)
name
- The key to ensure has a DFV bound to itRetrieves the DFV associated with the given index
index
- The index to find a match for
Invokes the given method. Allows for invoking whenBound() on the dataflow variables.
def df = new Dataflows() df.var {* println "Variable bound to $it" }*
name
- the name of the method to call (the variable name)args
- the arguments to use for the method call (a closure to invoke when a value is bound)Convenience method to play nicely with Groovy object iteration methods. The iteration restrictions of ConcurrentHashMap concerning parallel access and ConcurrentModificationException apply.
Binds the value to the DataflowVariable that is associated with the property "index".
index
- The index to associate the value withvalue
- a scalar or a DataflowVariable that may block on value accessUtility method extracted just to help JIT
name
- The key to ensure has a DFV bound to itRemoves a DFV from the map and binds it to null, if it has not been bound yet
name
- The name of the DFV to remove.Binds the value to the DataflowVariable that is associated with the property "name".
newValue
- a scalar or a DataflowVariable that may block on value accessCopyright © 2008–2014 Václav Pech. All Rights Reserved.