org.codehaus.gpars

groovyx.gpars.dataflow.operator
[Groovy] Class DataflowSelector

java.lang.Object
  groovyx.gpars.dataflow.operator.DataflowProcessor
      groovyx.gpars.dataflow.operator.DataflowSelector

class DataflowSelector
extends DataflowProcessor

Dataflow selectors and operators (processors) form the basic units in dataflow networks. They are typically combined into oriented graphs that transform data. They accept a set of input and output dataflow channels so that once values are available to be consumed in any of the input channels the selector's body is triggered on the values, potentially generating values to be written into the output channels. The output channels at the same time are suitable to be used as input channels by some other dataflow processors. The channels allow processors to communicate. Dataflow selectors and operators enable creation of highly concurrent applications yet the abstraction hides the low-level concurrency primitives and exposes much friendlier API. Since selectors and operators internally leverage the actor implementation, they reuse a pool of threads and so the actual number of threads used by the calculation can be kept much lower than the actual number of processors used in the network. Selectors select a random value from the values available in the input channels. Optionally the selector's guards mask can be altered to limit the number of channels considered for selection.

Authors:
Vaclav Pech Date: Sep 9, 2009


Field Summary
protected java.util.List guards

protected Select select

 
Fields inherited from class DataflowProcessor
actor
 
Constructor Summary
protected DataflowSelector(PGroup group, java.util.Map channels, groovy.lang.Closure code)

Creates a selector After creation the selector needs to be started using the start() method.

 
Method Summary
protected void doSelect()

Ask for another select operation on the internal select instance.

protected void reportError(java.lang.Throwable e)

Is invoked in case the actor throws an exception.

void setGuard(int index, boolean flag)

Used to enable/disable individual input channels from next selections

void setGuards(java.util.List flags)

Used to enable/disable individual input channels from next selections

private boolean verifyChannelParameters(java.util.Map channels, int parameters)

 
Methods inherited from class DataflowProcessor
bindAllOutputValues, bindAllOutputValuesAtomically, bindAllOutputs, bindAllOutputsAtomically, bindOutput, bindOutput, getOutput, getOutputs, getOutputs, join, reportError, shouldBeMultiThreaded, start, start, stop
 
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

guards

protected final java.util.List guards


select

protected final Select select


 
Constructor Detail

DataflowSelector

protected DataflowSelector(PGroup group, java.util.Map channels, groovy.lang.Closure code)
Creates a selector After creation the selector needs to be started using the start() method.
Parameters:
group - A parallel group to use threads from in the internal actor
channels - A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputs
code - The selector's body to run each time all inputs have a value to read


 
Method Detail

doSelect

protected void doSelect()
Ask for another select operation on the internal select instance. The selector's guards are applied to the selection.


reportError

protected final void reportError(java.lang.Throwable e)
Is invoked in case the actor throws an exception.


setGuard

final void setGuard(int index, boolean flag)
Used to enable/disable individual input channels from next selections
Parameters:
index - The index of the channel to enable/disable
flag - True, if the channel should be included in selection, false otherwise


setGuards

final void setGuards(java.util.List flags)
Used to enable/disable individual input channels from next selections
Parameters:
index - The index of the channel to enable/disable
flag - True, if the channel should be included in selection, false otherwise


verifyChannelParameters

private boolean verifyChannelParameters(java.util.Map channels, int parameters)


 

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