groovyx.gpars.dataflow.operator
Class Pipeline

java.lang.Object
  extended by groovyx.gpars.dataflow.operator.Pipeline

public final class Pipeline
extends java.lang.Object

A builder for operator pipelines. The greatest benefit of using the Pipeline class compared to chaining the channels directly is the ease with which a custom thread pool/group can be applied to all the operators along the constructed chain.

Author:
Vaclav Pech

Field Summary
private  boolean complete
           
private  PGroup group
           
private  DataflowReadChannel output
           
 
Constructor Summary
Pipeline(DataflowReadChannel output)
           
Pipeline(PGroup group, DataflowReadChannel output)
           
Pipeline(Pool pool, DataflowReadChannel output)
           
 
Method Summary
<T> void
binaryChoice(DataflowWriteChannel<T> trueBranch, DataflowWriteChannel<T> falseBranch, groovy.lang.Closure<java.lang.Boolean> code)
          Directs the output to one of the two output channels depending on the boolean result of the provided closure.
<T> void
binaryChoice(java.util.Map<java.lang.String,java.lang.Object> params, DataflowWriteChannel<T> trueBranch, DataflowWriteChannel<T> falseBranch, groovy.lang.Closure<java.lang.Boolean> code)
          Directs the output to one of the two output channels depending on the boolean result of the provided closure.
 Pipeline filter(groovy.lang.Closure<java.lang.Boolean> closure)
          Creates and attaches a new operator that will filter data using the provided closure
 Pipeline filter(java.util.Map<java.lang.String,java.lang.Object> params, groovy.lang.Closure<java.lang.Boolean> closure)
          Creates and attaches a new operator that will filter data using the provided closure
 PGroup getGroup()
           
 DataflowReadChannel getOutput()
           
<V> Pipeline
chainWith(groovy.lang.Closure<V> closure)
          Creates and attaches a new operator
<V> Pipeline
chainWith(java.util.Map<java.lang.String,java.lang.Object> params, groovy.lang.Closure<V> closure)
          Creates and attaches a new operator
private  void checkState()
           
<T> void
choice(java.util.List<DataflowWriteChannel<T>> outputs, groovy.lang.Closure<java.lang.Integer> code)
          Directs the output to one of the output channels depending on the int result of the provided closure.
<T> void
choice(java.util.Map<java.lang.String,java.lang.Object> params, java.util.List<DataflowWriteChannel<T>> outputs, groovy.lang.Closure<java.lang.Integer> code)
          Directs the output to one of the output channels depending on the int result of the provided closure.
<V> void
into(DataflowWriteChannel<V> target)
          Makes the output of the pipeline to be an input for the specified channel
<V> void
into(java.util.Map<java.lang.String,java.lang.Object> params, DataflowWriteChannel<V> target)
          Makes the output of the pipeline to be an input for the specified channel
 boolean isComplete()
           
(package private)  Pipeline merge(DataflowReadChannel<java.lang.Object> other, groovy.lang.Closure closure)
          Merges channels together as inputs for a single dataflow operator.
(package private)  Pipeline merge(java.util.List<DataflowReadChannel<java.lang.Object>> others, groovy.lang.Closure closure)
          Merges channels together as inputs for a single dataflow operator.
(package private)  Pipeline merge(java.util.Map<java.lang.String,java.lang.Object> params, DataflowReadChannel<java.lang.Object> other, groovy.lang.Closure closure)
          Merges channels together as inputs for a single dataflow operator.
(package private)  Pipeline merge(java.util.Map<java.lang.String,java.lang.Object> params, java.util.List<DataflowReadChannel<java.lang.Object>> others, groovy.lang.Closure closure)
          Merges channels together as inputs for a single dataflow operator.
<V> Pipeline
or(groovy.lang.Closure<V> closure)
          Creates and attaches a new operator
<V> void
or(DataflowWriteChannel<V> target)
          Makes the output of the pipeline to be an input for the specified channel
 void separate(java.util.List<DataflowWriteChannel<?>> outputs, groovy.lang.Closure<java.util.List<java.lang.Object>> code)
          Allows the closure to output different values to different output channels.
 void separate(java.util.Map<java.lang.String,java.lang.Object> params, java.util.List<DataflowWriteChannel<?>> outputs, groovy.lang.Closure<java.util.List<java.lang.Object>> code)
          Allows the closure to output different values to different output channels.
<V> void
split(DataflowWriteChannel<V> target1, DataflowWriteChannel<V> target2)
          Splits the output of the pipeline to be an input for the specified channels
<V> void
split(java.util.List<DataflowWriteChannel<V>> targets)
          Makes the output of the pipeline to be an input for the specified channels
<V> void
split(java.util.Map<java.lang.String,java.lang.Object> params, DataflowWriteChannel<V> target1, DataflowWriteChannel<V> target2)
          Splits the output of the pipeline to be an input for the specified channels
<V> void
split(java.util.Map<java.lang.String,java.lang.Object> params, java.util.List<DataflowWriteChannel<V>> targets)
          Makes the output of the pipeline to be an input for the specified channels
<V> Pipeline
tap(DataflowWriteChannel<V> target)
          Taps into the pipeline at the current position, sending all data that pass through the pipeline also to the channel specified.
<V> Pipeline
tap(java.util.Map<java.lang.String,java.lang.Object> params, DataflowWriteChannel<V> target)
          Taps into the pipeline at the current position, sending all data that pass through the pipeline also to the channel specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

group

private final PGroup group

output

private DataflowReadChannel output

complete

private boolean complete
Constructor Detail

Pipeline

public Pipeline(DataflowReadChannel output)

Pipeline

public Pipeline(Pool pool,
                DataflowReadChannel output)

Pipeline

public Pipeline(PGroup group,
                DataflowReadChannel output)
Method Detail

getGroup

public PGroup getGroup()

getOutput

public DataflowReadChannel getOutput()

isComplete

public boolean isComplete()

checkState

private void checkState()

chainWith

public <V> Pipeline chainWith(groovy.lang.Closure<V> closure)
Creates and attaches a new operator

Type Parameters:
V - The type of values returned from the supplied closure
Parameters:
closure - The function to invoke on all incoming values as part of the new operator's body
Returns:
This Pipeline instance

chainWith

public <V> Pipeline chainWith(java.util.Map<java.lang.String,java.lang.Object> params,
                              groovy.lang.Closure<V> closure)
Creates and attaches a new operator

Type Parameters:
V - The type of values returned from the supplied closure
Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
closure - The function to invoke on all incoming values as part of the new operator's body
Returns:
This Pipeline instance

or

public <V> Pipeline or(groovy.lang.Closure<V> closure)
Creates and attaches a new operator

Type Parameters:
V - The type of values returned from the supplied closure
Parameters:
closure - The function to invoke on all incoming values as part of the new operator's body
Returns:
This Pipeline instance

filter

public Pipeline filter(groovy.lang.Closure<java.lang.Boolean> closure)
Creates and attaches a new operator that will filter data using the provided closure

Parameters:
closure - The filter function to invoke on all incoming values to decide whether to pass the value on or not
Returns:
This Pipeline instance

filter

public Pipeline filter(java.util.Map<java.lang.String,java.lang.Object> params,
                       groovy.lang.Closure<java.lang.Boolean> closure)
Creates and attaches a new operator that will filter data using the provided closure

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
closure - The filter function to invoke on all incoming values to decide whether to pass the value on or not
Returns:
This Pipeline instance

into

public <V> void into(DataflowWriteChannel<V> target)
Makes the output of the pipeline to be an input for the specified channel

Type Parameters:
V - The type of values passed between the channels
Parameters:
target - The channel to copy data into

into

public <V> void into(java.util.Map<java.lang.String,java.lang.Object> params,
                     DataflowWriteChannel<V> target)
Makes the output of the pipeline to be an input for the specified channel

Type Parameters:
V - The type of values passed between the channels
Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
target - The channel to copy data into

or

public <V> void or(DataflowWriteChannel<V> target)
Makes the output of the pipeline to be an input for the specified channel

Type Parameters:
V - The type of values passed between the channels
Parameters:
target - The channel to copy data into

split

public <V> void split(DataflowWriteChannel<V> target1,
                      DataflowWriteChannel<V> target2)
Splits the output of the pipeline to be an input for the specified channels

Type Parameters:
V - The type of values passed between the channels
Parameters:
target1 - The first channel to copy data into
target2 - The second channel to copy data into

split

public <V> void split(java.util.List<DataflowWriteChannel<V>> targets)
Makes the output of the pipeline to be an input for the specified channels

Type Parameters:
V - The type of values passed between the channels
Parameters:
targets - The channels to copy data into

split

public <V> void split(java.util.Map<java.lang.String,java.lang.Object> params,
                      DataflowWriteChannel<V> target1,
                      DataflowWriteChannel<V> target2)
Splits the output of the pipeline to be an input for the specified channels

Type Parameters:
V - The type of values passed between the channels
Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
target1 - The first channel to copy data into
target2 - The second channel to copy data into

split

public <V> void split(java.util.Map<java.lang.String,java.lang.Object> params,
                      java.util.List<DataflowWriteChannel<V>> targets)
Makes the output of the pipeline to be an input for the specified channels

Type Parameters:
V - The type of values passed between the channels
Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
targets - The channels to copy data into

tap

public <V> Pipeline tap(DataflowWriteChannel<V> target)
Taps into the pipeline at the current position, sending all data that pass through the pipeline also to the channel specified.

Type Parameters:
V - The type of values passed between the channels
Parameters:
target - The channel to tap data into
Returns:
This Pipeline instance

tap

public <V> Pipeline tap(java.util.Map<java.lang.String,java.lang.Object> params,
                        DataflowWriteChannel<V> target)
Taps into the pipeline at the current position, sending all data that pass through the pipeline also to the channel specified.

Type Parameters:
V - The type of values passed between the channels
Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
target - The channel to tap data into
Returns:
This Pipeline instance

merge

Pipeline merge(DataflowReadChannel<java.lang.Object> other,
               groovy.lang.Closure closure)
Merges channels together as inputs for a single dataflow operator.

Parameters:
other - The channel to merge with
closure - The function to invoke on all incoming values as part of the new operator's body. The number of arguments to the closure must match the number of input channels.
Returns:
A channel of the same type as this channel, which the new operator will output into.

merge

Pipeline merge(java.util.List<DataflowReadChannel<java.lang.Object>> others,
               groovy.lang.Closure closure)
Merges channels together as inputs for a single dataflow operator.

Parameters:
others - The channels to merge with
closure - The function to invoke on all incoming values as part of the new operator's body. The number of arguments to the closure must match the number of input channels.
Returns:
A channel of the same type as this channel, which the new operator will output into.

merge

Pipeline merge(java.util.Map<java.lang.String,java.lang.Object> params,
               DataflowReadChannel<java.lang.Object> other,
               groovy.lang.Closure closure)
Merges channels together as inputs for a single dataflow operator.

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
other - The channel to merge with
closure - The function to invoke on all incoming values as part of the new operator's body. The number of arguments to the closure must match the number of input channels.
Returns:
A channel of the same type as this channel, which the new operator will output into.

merge

Pipeline merge(java.util.Map<java.lang.String,java.lang.Object> params,
               java.util.List<DataflowReadChannel<java.lang.Object>> others,
               groovy.lang.Closure closure)
Merges channels together as inputs for a single dataflow operator.

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
others - The channels to merge with
closure - The function to invoke on all incoming values as part of the new operator's body. The number of arguments to the closure must match the number of input channels.
Returns:
A channel of the same type as this channel, which the new operator will output into.

binaryChoice

public <T> void binaryChoice(DataflowWriteChannel<T> trueBranch,
                             DataflowWriteChannel<T> falseBranch,
                             groovy.lang.Closure<java.lang.Boolean> code)
Directs the output to one of the two output channels depending on the boolean result of the provided closure.

Parameters:
trueBranch - The channel to send data to if the closure returns true
falseBranch - The channel to send data to if the closure returns true
code - A closure directing data to either the true or the false output branch

binaryChoice

public <T> void binaryChoice(java.util.Map<java.lang.String,java.lang.Object> params,
                             DataflowWriteChannel<T> trueBranch,
                             DataflowWriteChannel<T> falseBranch,
                             groovy.lang.Closure<java.lang.Boolean> code)
Directs the output to one of the two output channels depending on the boolean result of the provided closure.

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
trueBranch - The channel to send data to if the closure returns true
falseBranch - The channel to send data to if the closure returns true
code - A closure directing data to either the true or the false output branch

choice

public <T> void choice(java.util.List<DataflowWriteChannel<T>> outputs,
                       groovy.lang.Closure<java.lang.Integer> code)
Directs the output to one of the output channels depending on the int result of the provided closure.

Parameters:
outputs - The channels to send data to.
code - A closure returning an index of the output channel to direct the data to

choice

public <T> void choice(java.util.Map<java.lang.String,java.lang.Object> params,
                       java.util.List<DataflowWriteChannel<T>> outputs,
                       groovy.lang.Closure<java.lang.Integer> code)
Directs the output to one of the output channels depending on the int result of the provided closure.

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
outputs - The channels to send data to.
code - A closure returning an index of the output channel to direct the data to

separate

public void separate(java.util.List<DataflowWriteChannel<?>> outputs,
                     groovy.lang.Closure<java.util.List<java.lang.Object>> code)
Allows the closure to output different values to different output channels.

Parameters:
outputs - The channels to send data to.
code - A closure returning a list of values to pass to the output channels. Values are output to the output channels with identical index.

separate

public void separate(java.util.Map<java.lang.String,java.lang.Object> params,
                     java.util.List<DataflowWriteChannel<?>> outputs,
                     groovy.lang.Closure<java.util.List<java.lang.Object>> code)
Allows the closure to output different values to different output channels.

Parameters:
params - Additional parameters to initialize the operator with (e.g. listeners or maxForks)
outputs - The channels to send data to.
code - A closure returning a list of values to pass to the output channels. Values are output to the output channels with identical index.

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