public abstract class PGroup
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
A_SPLITTER_NEEDS_AN_INPUT_CHANNEL_AND_AT_LEAST_ONE_OUTPUT_CHANNEL_TO_BE_CREATED |
private Pool |
threadPool
Stores the group actors' thread pool
|
Modifier | Constructor and Description |
---|---|
protected |
PGroup(Pool threadPool)
Creates a group for actors, agents, tasks and operators.
|
Modifier and Type | Method and Description |
---|---|
DefaultActor |
actor(java.lang.Runnable handler)
Creates a new instance of DefaultActor, using the passed-in runnable/closure as the body of the actor's act() method.
|
<T> Agent<T> |
agent(T state)
Creates an agent instance initialized with the given state
|
<T> Agent<T> |
agent(T state,
groovy.lang.Closure copy)
Creates an agent instance initialized with the given state
|
BlockingActor |
blockingActor(java.lang.Runnable handler)
Creates a new instance of BlockingActor, using the passed-in closure as the body of the actor's act() method.
|
void |
execute(java.lang.Runnable task)
schedules a new task for processing with the pool
|
DefaultActor |
fairActor(java.lang.Runnable handler)
Creates a new instance of DefaultActor, using the passed-in runnable/closure as the body of the actor's act() method.
|
<T> Agent<T> |
fairAgent(T state)
Creates an agent instance initialized with the given state, which will cooperate in thread sharing with other agents and actors in a fair manner.
|
<T> Agent<T> |
fairAgent(T state,
groovy.lang.Closure copy)
Creates an agent instance initialized with the given state, which will cooperate in thread sharing with other agents and actors in a fair manner.
|
Actor |
fairMessageHandler(groovy.lang.Closure code)
Creates an instance of DynamicDispatchActor, which will cooperate in thread sharing with other actors sharing the same thread pool
|
Actor |
fairReactor(groovy.lang.Closure code)
Creates a reactor around the supplied code, which will cooperate in thread sharing with other actors sharing the same thread pool
When a reactor receives a message, the supplied block of code is run with the message
as a parameter and the result of the code is send in reply.
|
Actor |
fairStaticMessageHandler(groovy.lang.Closure code)
Creates an instance of StaticDispatchActor, which will cooperate in thread sharing with other actors sharing the same thread pool.
|
protected void |
finalize()
Shutdown the thread pool gracefully
|
int |
getPoolSize()
Retrieves the current thread pool size
|
Pool |
getThreadPool() |
private static <T> boolean |
isListAccepting(groovy.lang.Closure<T> code) |
<T> Promise<T> |
lazyTask(java.util.concurrent.Callable<T> callable)
Creates a new task assigned to a thread from the current parallel group.
|
<T> Promise<T> |
lazyTask(groovy.lang.Closure<T> code)
Creates a new task assigned to a thread from the current parallel group.
|
Actor |
messageHandler(groovy.lang.Closure code)
Creates an instance of DynamicDispatchActor.
|
DataflowProcessor |
operator(DataflowReadChannel input,
DataflowWriteChannel output,
groovy.lang.Closure code)
Creates an operator using the current parallel group
|
DataflowProcessor |
operator(DataflowReadChannel input,
DataflowWriteChannel output,
int maxForks,
groovy.lang.Closure code)
Creates an operator using the current parallel group
|
DataflowProcessor |
operator(java.util.List inputChannels,
java.util.List outputChannels,
groovy.lang.Closure code)
Creates an operator using the current parallel group
|
DataflowProcessor |
operator(java.util.List inputChannels,
java.util.List outputChannels,
int maxForks,
groovy.lang.Closure code)
Creates an operator using the current parallel group
|
DataflowProcessor |
operator(java.util.Map channels,
groovy.lang.Closure code)
Creates an operator using the current parallel group
|
DataflowProcessor |
prioritySelector(java.util.List inputChannels,
java.util.List outputChannels)
Creates a prioritizing selector using the default dataflow parallel group.
|
DataflowProcessor |
prioritySelector(java.util.List inputChannels,
java.util.List outputChannels,
groovy.lang.Closure code)
Creates a prioritizing selector using the default dataflow parallel group
Input with lower position index have higher priority.
|
DataflowProcessor |
prioritySelector(java.util.Map channels)
Creates a prioritizing selector using the default dataflow parallel group.
|
DataflowProcessor |
prioritySelector(java.util.Map channels,
groovy.lang.Closure code)
Creates a prioritizing selector using the default dataflow parallel group
Input with lower position index have higher priority.
|
Actor |
reactor(groovy.lang.Closure code)
Creates a reactor around the supplied code.
|
void |
resetDefaultSize()
Sets the pool size to the default
|
void |
resize(int poolSize)
Resizes the thread pool to the specified value
|
Select |
select(java.util.List<SelectableChannel> channels)
Creates a select using the current parallel group.
|
Select |
select(SelectableChannel... channels)
Creates a select using the current parallel group.
|
DataflowProcessor |
selector(java.util.List inputChannels,
java.util.List outputChannels)
Creates a selector using this parallel group.
|
DataflowProcessor |
selector(java.util.List inputChannels,
java.util.List outputChannels,
groovy.lang.Closure code)
Creates a selector using this parallel group
|
DataflowProcessor |
selector(java.util.Map channels)
Creates a selector using this parallel group.
|
DataflowProcessor |
selector(java.util.Map channels,
groovy.lang.Closure code)
Creates a selector using this parallel group
|
private <T> boolean |
shallHandle(groovy.lang.Closure<T> errorHandler,
java.lang.Throwable e) |
void |
shutdown()
Gently stops the pool
|
DataflowProcessor |
splitter(DataflowReadChannel inputChannel,
java.util.List<DataflowWriteChannel> outputChannels)
Creates a splitter copying its single input channel into all of its output channels.
|
DataflowProcessor |
splitter(DataflowReadChannel inputChannel,
java.util.List<DataflowWriteChannel> outputChannels,
int maxForks)
Creates a splitter copying its single input channel into all of its output channels.
|
Actor |
staticMessageHandler(groovy.lang.Closure code)
Creates an instance of StaticDispatchActor.
|
<T> Promise<T> |
task(java.util.concurrent.Callable<T> callable)
Creates a new task assigned to a thread from the current parallel group.
|
<T> Promise<T> |
task(groovy.lang.Closure<T> code)
Creates a new task assigned to a thread from the current parallel group.
|
Promise<java.lang.Object> |
task(java.lang.Runnable code)
Creates a new task assigned to a thread from the current parallel group.
|
<T> Promise<T> |
whenAllBound(java.util.List<Promise> promises,
groovy.lang.Closure<T> code)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(java.util.List<Promise> promises,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
private <T> void |
whenAllBound(java.util.List<Promise> promises,
int index,
java.util.List<java.lang.Object> values,
DataflowVariable<T> result,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Waits for the promise identified by the index to be bound and then passes on to the next promise in the list
|
<T> Promise<T> |
whenAllBound(Promise promise1,
groovy.lang.Closure<T> code)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
groovy.lang.Closure<T> code)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
Promise promise3,
groovy.lang.Closure<T> code)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
Promise promise3,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
Promise promise3,
Promise promise4,
groovy.lang.Closure<T> code)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
<T> Promise<T> |
whenAllBound(Promise promise1,
Promise promise2,
Promise promise3,
Promise promise4,
groovy.lang.Closure<T> code,
groovy.lang.Closure<T> errorHandler)
Without blocking the thread waits for all the promises to get bound and then passes them to the supplied closure.
|
protected static final java.lang.String A_SPLITTER_NEEDS_AN_INPUT_CHANNEL_AND_AT_LEAST_ONE_OUTPUT_CHANNEL_TO_BE_CREATED
private final Pool threadPool
protected PGroup(Pool threadPool)
threadPool
- The thread pool to use by the grouppublic Pool getThreadPool()
public final DefaultActor actor(@DelegatesTo(value=DefaultActor.class) java.lang.Runnable handler)
handler
- The body of the newly created actor's act method.public final BlockingActor blockingActor(@DelegatesTo(value=BlockingActor.class) java.lang.Runnable handler)
handler
- The body of the newly created actor's act method.public final DefaultActor fairActor(@DelegatesTo(value=DefaultActor.class) java.lang.Runnable handler)
handler
- The body of the newly created actor's act method.public final Actor reactor(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The code to invoke for each received messagepublic final Actor fairReactor(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The code to invoke for each received messagepublic final Actor messageHandler(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The closure specifying individual message handlers.public final Actor fairMessageHandler(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The closure specifying individual message handlers.public final Actor staticMessageHandler(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The closure specifying the only statically dispatched message handler.public final Actor fairStaticMessageHandler(@DelegatesTo(value=Actor.class) groovy.lang.Closure code)
code
- The closure specifying the only statically dispatched message handler.public final <T> Agent<T> agent(T state)
state
- The initial internal state of the new Agent instancepublic final <T> Agent<T> agent(T state, groovy.lang.Closure copy)
state
- The initial internal state of the new Agent instancecopy
- A closure to use to create a copy of the internal state when sending the internal state outpublic final <T> Agent<T> fairAgent(T state)
state
- The initial internal state of the new Agent instancepublic final <T> Agent<T> fairAgent(T state, groovy.lang.Closure copy)
copy
- A closure to use to create a copy of the internal state when sending the internal state outstate
- The initial internal state of the new Agent instancepublic final <T> Promise<T> task(groovy.lang.Closure<T> code)
code
- The task body to runpublic final <T> Promise<T> task(java.util.concurrent.Callable<T> callable)
callable
- The task body to runpublic final Promise<java.lang.Object> task(java.lang.Runnable code)
code
- The task body to runpublic final <T> Promise<T> lazyTask(groovy.lang.Closure<T> code)
code
- The task body to runpublic final <T> Promise<T> lazyTask(java.util.concurrent.Callable<T> callable)
callable
- The task body to runpublic final DataflowProcessor operator(java.util.Map channels, @DelegatesTo(value=DataflowOperator.class) groovy.lang.Closure code)
channels
- A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputscode
- The operator's body to run each time all inputs have a value to readpublic final DataflowProcessor operator(java.util.List inputChannels, java.util.List outputChannels, @DelegatesTo(value=DataflowOperator.class) groovy.lang.Closure code)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputcode
- The operator's body to run each time all inputs have a value to readpublic final DataflowProcessor operator(java.util.List inputChannels, java.util.List outputChannels, int maxForks, @DelegatesTo(value=DataflowOperator.class) groovy.lang.Closure code)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputmaxForks
- Number of parallel threads running operator's body, defaults to 1code
- The operator's body to run each time all inputs have a value to readpublic final DataflowProcessor operator(DataflowReadChannel input, DataflowWriteChannel output, @DelegatesTo(value=DataflowOperator.class) groovy.lang.Closure code)
input
- a dataflow channel to use for inputoutput
- a dataflow channel to use for outputcode
- The operator's body to run each time all inputs have a value to readpublic final DataflowProcessor operator(DataflowReadChannel input, DataflowWriteChannel output, int maxForks, @DelegatesTo(value=DataflowOperator.class) groovy.lang.Closure code)
input
- a dataflow channel to use for inputoutput
- a dataflow channel to use for outputmaxForks
- Number of parallel threads running operator's body, defaults to 1code
- The operator's body to run each time all inputs have a value to readpublic final DataflowProcessor selector(java.util.Map channels, @DelegatesTo(value=DataflowSelector.class) groovy.lang.Closure code)
channels
- A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputscode
- The selector's body to run each time a value is available in any of the inputs channelspublic final DataflowProcessor selector(java.util.List inputChannels, java.util.List outputChannels, @DelegatesTo(value=DataflowSelector.class) groovy.lang.Closure code)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputcode
- The selector's body to run each time a value is available in any of the inputs channelspublic final DataflowProcessor selector(java.util.Map channels)
channels
- A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputspublic final DataflowProcessor selector(java.util.List inputChannels, java.util.List outputChannels)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputpublic final DataflowProcessor prioritySelector(java.util.Map channels, @DelegatesTo(value=DataflowSelector.class) groovy.lang.Closure code)
channels
- A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputscode
- The selector's body to run each time a value is available in any of the inputs channelspublic final DataflowProcessor prioritySelector(java.util.List inputChannels, java.util.List outputChannels, @DelegatesTo(value=DataflowSelector.class) groovy.lang.Closure code)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputcode
- The selector's body to run each time a value is available in any of the inputs channelspublic final DataflowProcessor prioritySelector(java.util.Map channels)
channels
- A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputspublic final DataflowProcessor prioritySelector(java.util.List inputChannels, java.util.List outputChannels)
inputChannels
- dataflow channels to use for inputoutputChannels
- dataflow channels to use for outputpublic final DataflowProcessor splitter(DataflowReadChannel inputChannel, java.util.List<DataflowWriteChannel> outputChannels)
inputChannel
- The channel to read values fromoutputChannels
- A list of channels to output topublic final DataflowProcessor splitter(DataflowReadChannel inputChannel, java.util.List<DataflowWriteChannel> outputChannels, int maxForks)
inputChannel
- The channel to read values fromoutputChannels
- A list of channels to output tomaxForks
- Number of threads running the splitter's body, defaults to 1public final Select select(SelectableChannel... channels)
channels
- Dataflow variables or streams to wait for values onpublic final Select select(java.util.List<SelectableChannel> channels)
channels
- Dataflow variables or streams to wait for values onpublic final <T> Promise<T> whenAllBound(java.util.List<Promise> promises, groovy.lang.Closure<T> code)
T
- The type of the final resultpromises
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promisespublic final <T> Promise<T> whenAllBound(Promise promise1, groovy.lang.Closure<T> code)
T
- The type of the final resultpromise1
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promisespublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, groovy.lang.Closure<T> code)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promisespublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, Promise promise3, groovy.lang.Closure<T> code)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forpromise3
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promisespublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, Promise promise3, Promise promise4, groovy.lang.Closure<T> code)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forpromise3
- The promises to wait forpromise4
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promisespublic final <T> Promise<T> whenAllBound(java.util.List<Promise> promises, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromises
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promiseserrorHandler
- A closure handling an exception (an instance of Throwable), if it gets boundpublic final <T> Promise<T> whenAllBound(Promise promise1, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromise1
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promiseserrorHandler
- A closure handling an exception (an instance of Throwable), if if it gets boundpublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promiseserrorHandler
- A closure handling an exception (an instance of Throwable), if if it gets boundpublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, Promise promise3, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forpromise3
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promiseserrorHandler
- A closure handling an exception (an instance of Throwable), if if it gets boundpublic final <T> Promise<T> whenAllBound(Promise promise1, Promise promise2, Promise promise3, Promise promise4, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromise1
- The promises to wait forpromise2
- The promises to wait forpromise3
- The promises to wait forpromise4
- The promises to wait forcode
- A closure to execute with concrete values for each of the supplied promiseserrorHandler
- A closure handling an exception (an instance of Throwable), if if it gets boundprivate <T> void whenAllBound(java.util.List<Promise> promises, int index, java.util.List<java.lang.Object> values, DataflowVariable<T> result, groovy.lang.Closure<T> code, groovy.lang.Closure<T> errorHandler)
T
- The type of the final resultpromises
- A list of all promises that need to be waited forindex
- The index of the current promise to wait forvalues
- A list of values the so-far processed promises were bound tporesult
- The promise for the final result of the calculationcode
- The calculation to execute on the values once they are all boundprivate <T> boolean shallHandle(groovy.lang.Closure<T> errorHandler, java.lang.Throwable e)
private static <T> boolean isListAccepting(groovy.lang.Closure<T> code)
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void resize(int poolSize)
poolSize
- The new pool sizepublic void resetDefaultSize()
public int getPoolSize()
public void execute(java.lang.Runnable task)
task
- The task to schedulepublic void shutdown()