groovyx.gpars.group
Class PGroup

java.lang.Object
  extended by groovyx.gpars.group.PGroup
Direct Known Subclasses:
DefaultPGroup, NonDaemonPGroup

public abstract class PGroup
extends java.lang.Object

Provides a common super class of pooled parallel groups.

Author:
Vaclav Pech, Alex Tkachman Date: May 8, 2009

Field Summary
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
 
Constructor Summary
protected PGroup(Pool threadPool)
          Creates a group for actors, agents, tasks and operators.
 
Method Summary
 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)
           
 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(DataflowReadChannel... channels)
          Creates a select using the current parallel group.
 Select select(java.util.List<DataflowReadChannel> 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
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A_SPLITTER_NEEDS_AN_INPUT_CHANNEL_AND_AT_LEAST_ONE_OUTPUT_CHANNEL_TO_BE_CREATED

protected static final java.lang.String A_SPLITTER_NEEDS_AN_INPUT_CHANNEL_AND_AT_LEAST_ONE_OUTPUT_CHANNEL_TO_BE_CREATED
See Also:
Constant Field Values

threadPool

private final Pool threadPool
Stores the group actors' thread pool

Constructor Detail

PGroup

protected PGroup(Pool threadPool)
Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.

Parameters:
threadPool - The thread pool to use by the group
Method Detail

getThreadPool

public Pool getThreadPool()

actor

public final 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. The created actor will belong to the pooled parallel group.

Parameters:
handler - The body of the newly created actor's act method.
Returns:
A newly created instance of the DefaultActor class

blockingActor

public final 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. The created actor will be part of the default actor group.

Parameters:
handler - The body of the newly created actor's act method.
Returns:
A newly created instance of the BlockingActor class

fairActor

public final 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. The actor will cooperate in thread sharing with other actors sharing the same thread pool in a fair manner. The created actor will belong to the pooled parallel group.

Parameters:
handler - The body of the newly created actor's act method.
Returns:
A newly created instance of the DefaultActor class

reactor

public final Actor reactor(groovy.lang.Closure code)
Creates a reactor around the supplied code. 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.

Parameters:
code - The code to invoke for each received message
Returns:
A new instance of ReactiveEventBasedThread

fairReactor

public final 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.

Parameters:
code - The code to invoke for each received message
Returns:
A new instance of ReactiveEventBasedThread

messageHandler

public final Actor messageHandler(groovy.lang.Closure code)
Creates an instance of DynamicDispatchActor.

Parameters:
code - The closure specifying individual message handlers.
Returns:
The new started actor

fairMessageHandler

public final 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

Parameters:
code - The closure specifying individual message handlers.
Returns:
The new started actor

staticMessageHandler

public final Actor staticMessageHandler(groovy.lang.Closure code)
Creates an instance of StaticDispatchActor.

Parameters:
code - The closure specifying the only statically dispatched message handler.
Returns:
The new started actor

fairStaticMessageHandler

public final 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.

Parameters:
code - The closure specifying the only statically dispatched message handler.
Returns:
The new started actor

agent

public final <T> Agent<T> agent(T state)
Creates an agent instance initialized with the given state

Parameters:
state - The initial internal state of the new Agent instance
Returns:
The created instance

agent

public final <T> Agent<T> agent(T state,
                                groovy.lang.Closure copy)
Creates an agent instance initialized with the given state

Parameters:
state - The initial internal state of the new Agent instance
copy - A closure to use to create a copy of the internal state when sending the internal state out
Returns:
The created instance

fairAgent

public final <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.

Parameters:
state - The initial internal state of the new Agent instance
Returns:
The created instance

fairAgent

public final <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.

Parameters:
copy - A closure to use to create a copy of the internal state when sending the internal state out
state - The initial internal state of the new Agent instance
Returns:
The created instance

task

public final <T> Promise<T> task(groovy.lang.Closure<T> code)
Creates a new task assigned to a thread from the current parallel group. Tasks are a lightweight version of dataflow operators, which do not define their communication channels explicitly, but can only exchange data using explicit DataflowVariables and Streams. Registers itself with Dataflow for nested 'whenBound' handlers to use the same group.

Parameters:
code - The task body to run
Returns:
A DataflowVariable, which gets assigned the value returned from the supplied code

task

public final <T> Promise<T> task(java.util.concurrent.Callable<T> callable)
Creates a new task assigned to a thread from the current parallel group. Tasks are a lightweight version of dataflow operators, which do not define their communication channels explicitly, but can only exchange data using explicit DataflowVariables and Streams. Registers itself with Dataflow for nested 'whenBound' handlers to use the same group.

Parameters:
callable - The task body to run
Returns:
A DataflowVariable, which gets assigned the value returned from the supplied code

task

public final Promise<java.lang.Object> task(java.lang.Runnable code)
Creates a new task assigned to a thread from the current parallel group. Tasks are a lightweight version of dataflow operators, which do not define their communication channels explicitly, but can only exchange data using explicit DataflowVariables and Streams. Registers itself with Dataflow for nested 'whenBound' handlers to use the same group.

Parameters:
code - The task body to run
Returns:
A DataflowVariable, which gets bound to null once the supplied code finishes

operator

public final DataflowProcessor operator(java.util.Map channels,
                                        groovy.lang.Closure code)
Creates an operator using the current parallel group

Parameters:
channels - A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputs
code - The operator's body to run each time all inputs have a value to read
Returns:
A new started operator instance with all the channels set

operator

public final DataflowProcessor operator(java.util.List inputChannels,
                                        java.util.List outputChannels,
                                        groovy.lang.Closure code)
Creates an operator using the current parallel group

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
code - The operator's body to run each time all inputs have a value to read
Returns:
A new started operator instance with all the channels set

operator

public final DataflowProcessor operator(java.util.List inputChannels,
                                        java.util.List outputChannels,
                                        int maxForks,
                                        groovy.lang.Closure code)
Creates an operator using the current parallel group

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
maxForks - Number of parallel threads running operator's body, defaults to 1
code - The operator's body to run each time all inputs have a value to read
Returns:
A new started operator instance with all the channels set

operator

public final DataflowProcessor operator(DataflowReadChannel input,
                                        DataflowWriteChannel output,
                                        groovy.lang.Closure code)
Creates an operator using the current parallel group

Parameters:
input - a dataflow channel to use for input
output - a dataflow channel to use for output
code - The operator's body to run each time all inputs have a value to read
Returns:
A new started operator instance with all the channels set

operator

public final DataflowProcessor operator(DataflowReadChannel input,
                                        DataflowWriteChannel output,
                                        int maxForks,
                                        groovy.lang.Closure code)
Creates an operator using the current parallel group

Parameters:
input - a dataflow channel to use for input
output - a dataflow channel to use for output
maxForks - Number of parallel threads running operator's body, defaults to 1
code - The operator's body to run each time all inputs have a value to read
Returns:
A new started operator instance with all the channels set

selector

public final DataflowProcessor selector(java.util.Map channels,
                                        groovy.lang.Closure code)
Creates a selector using this parallel group

Parameters:
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 a value is available in any of the inputs channels
Returns:
A new started selector instance with all the channels set

selector

public final DataflowProcessor selector(java.util.List inputChannels,
                                        java.util.List outputChannels,
                                        groovy.lang.Closure code)
Creates a selector using this parallel group

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
code - The selector's body to run each time a value is available in any of the inputs channels
Returns:
A new started selector instance with all the channels set

selector

public final DataflowProcessor selector(java.util.Map channels)
Creates a selector using this parallel group. Since no body is provided, the selector will simply copy the incoming values to all output channels.

Parameters:
channels - A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputs
Returns:
A new started selector instance with all the channels set

selector

public final DataflowProcessor selector(java.util.List inputChannels,
                                        java.util.List outputChannels)
Creates a selector using this parallel group. Since no body is provided, the selector will simply copy the incoming values to all output channels.

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
Returns:
A new started selector instance with all the channels set

prioritySelector

public final 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.

Parameters:
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 a value is available in any of the inputs channels
Returns:
A new started selector instance with all the channels set

prioritySelector

public final 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.

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
code - The selector's body to run each time a value is available in any of the inputs channels
Returns:
A new started selector instance with all the channels set

prioritySelector

public final DataflowProcessor prioritySelector(java.util.Map channels)
Creates a prioritizing selector using the default dataflow parallel group. Since no body is provided, the selector will simply copy the incoming values to all output channels. Input with lower position index have higher priority.

Parameters:
channels - A map specifying "inputs" and "outputs" - dataflow channels (instances of the DataflowQueue or DataflowVariable classes) to use for inputs and outputs
Returns:
A new started selector instance with all the channels set

prioritySelector

public final DataflowProcessor prioritySelector(java.util.List inputChannels,
                                                java.util.List outputChannels)
Creates a prioritizing selector using the default dataflow parallel group. Since no body is provided, the selector will simply copy the incoming values to all output channels. Input with lower position index have higher priority.

Parameters:
inputChannels - dataflow channels to use for input
outputChannels - dataflow channels to use for output
Returns:
A new started selector instance with all the channels set

splitter

public final DataflowProcessor splitter(DataflowReadChannel inputChannel,
                                        java.util.List<DataflowWriteChannel> outputChannels)
Creates a splitter copying its single input channel into all of its output channels. The created splitter will be part of this parallel group

Parameters:
inputChannel - The channel to read values from
outputChannels - A list of channels to output to
Returns:
A new started splitter instance with all the channels set

splitter

public final 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. The created splitter will be part of this parallel group

Parameters:
inputChannel - The channel to read values from
outputChannels - A list of channels to output to
maxForks - Number of threads running the splitter's body, defaults to 1
Returns:
A new started splitter instance with all the channels set

select

public final Select select(DataflowReadChannel... channels)
Creates a select using the current parallel group. The returns Select instance will allow the user to obtain values from the supplied dataflow variables or streams as they become available.

Parameters:
channels - Dataflow variables or streams to wait for values on

select

public final Select select(java.util.List<DataflowReadChannel> channels)
Creates a select using the current parallel group. The returns Select instance will allow the user to obtain values from the supplied dataflow variables or streams as they become available.

Parameters:
channels - Dataflow variables or streams to wait for values on

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promises - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
promise3 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
promise3 - The promises to wait for
promise4 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promises - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
errorHandler - A closure handling an exception (an instance of Throwable), if if it gets bound
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
errorHandler - A closure handling an exception (an instance of Throwable), if if it gets bound
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
errorHandler - A closure handling an exception (an instance of Throwable), if if it gets bound
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
promise3 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
errorHandler - A closure handling an exception (an instance of Throwable), if if it gets bound
Returns:
A promise for the final result

whenAllBound

public final <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.

Type Parameters:
T - The type of the final result
Parameters:
promise1 - The promises to wait for
promise2 - The promises to wait for
promise3 - The promises to wait for
promise4 - The promises to wait for
code - A closure to execute with concrete values for each of the supplied promises
errorHandler - A closure handling an exception (an instance of Throwable), if if it gets bound
Returns:
A promise for the final result

whenAllBound

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

Type Parameters:
T - The type of the final result
Parameters:
promises - A list of all promises that need to be waited for
index - The index of the current promise to wait for
values - A list of values the so-far processed promises were bound tpo
result - The promise for the final result of the calculation
code - The calculation to execute on the values once they are all bound

isListAccepting

private static <T> boolean isListAccepting(groovy.lang.Closure<T> code)

finalize

protected void finalize()
                 throws java.lang.Throwable
Shutdown the thread pool gracefully

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

resize

public void resize(int poolSize)
Resizes the thread pool to the specified value

Parameters:
poolSize - The new pool size

resetDefaultSize

public void resetDefaultSize()
Sets the pool size to the default


getPoolSize

public int getPoolSize()
Retrieves the current thread pool size

Returns:
The pool size

execute

public void execute(java.lang.Runnable task)
schedules a new task for processing with the pool

Parameters:
task - The task to schedule

shutdown

public void shutdown()
Gently stops the pool


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