de.unkrig.commons.util.concurrent
Class SquadExecutor<T>

java.lang.Object
  extended by de.unkrig.commons.util.concurrent.SquadExecutor<T>
Type Parameters:
T - The futures' result type
All Implemented Interfaces:
java.util.concurrent.Executor

public class SquadExecutor<T>
extends java.lang.Object
implements java.util.concurrent.Executor

An Executor which executes tasks through a delegate ExecutorService. The awaitCompletion() methods waits until all tasks of the squad are complete.


Constructor Summary
SquadExecutor(java.util.concurrent.ExecutorService delegate)
           
 
Method Summary
 java.util.List<java.util.concurrent.Future<T>> awaitCompletion()
          Returns when all tasks that were previously submitted with submit(Callable), submit(Runnable, Object), submit(Runnable, Object) and execute(Runnable) have completed.
 java.util.List<java.util.concurrent.Future<T>> awaitCompletion(long timeout, java.util.concurrent.TimeUnit unit)
          Returns when all tasks that were previously submitted with submit(Callable), submit(Runnable, Object), submit(Runnable, Object) and execute(Runnable) have completed, or when then timeout expires.
 void execute(java.lang.Runnable command)
           
 java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
          Submits a value-returning task for execution.
 java.util.concurrent.Future<T> submit(java.lang.Runnable task)
          Submits a Runnable task for execution.
 java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
          Submits a Runnable task for execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SquadExecutor

public SquadExecutor(java.util.concurrent.ExecutorService delegate)
See Also:
SquadExecutor
Method Detail

execute

public void execute(java.lang.Runnable command)
Specified by:
execute in interface java.util.concurrent.Executor

submit

public java.util.concurrent.Future<T> submit(java.lang.Runnable task)
Submits a Runnable task for execution.

Parameters:
task - The task to submit
Returns:
A future representing pending completion of the task

submit

public java.util.concurrent.Future<T> submit(java.lang.Runnable task,
                                             T result)
Submits a Runnable task for execution.

Parameters:
task - The task to submit
result - The result to return
Returns:
A future representing pending completion of the task

submit

public java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
Submits a value-returning task for execution.

Parameters:
task - The task to submit
Returns:
A future representing pending completion of the task

awaitCompletion

public java.util.List<java.util.concurrent.Future<T>> awaitCompletion()
                                                               throws java.lang.InterruptedException,
                                                                      java.util.concurrent.ExecutionException,
                                                                      java.util.concurrent.CancellationException
Returns when all tasks that were previously submitted with submit(Callable), submit(Runnable, Object), submit(Runnable, Object) and execute(Runnable) have completed.

Returns:
The futures of the tasks
Throws:
java.util.concurrent.CancellationException - One of the tasks was cancelled
java.util.concurrent.ExecutionException - One of the tasks threw an exception
java.lang.InterruptedException - The current thread was interrupted while waiting

awaitCompletion

public java.util.List<java.util.concurrent.Future<T>> awaitCompletion(long timeout,
                                                                      java.util.concurrent.TimeUnit unit)
                                                               throws java.util.concurrent.CancellationException,
                                                                      java.util.concurrent.ExecutionException,
                                                                      java.lang.InterruptedException
Returns when all tasks that were previously submitted with submit(Callable), submit(Runnable, Object), submit(Runnable, Object) and execute(Runnable) have completed, or when then timeout expires.

Returns:
The futures of the tasks
Throws:
java.util.concurrent.CancellationException - One of the tasks was cancelled
java.util.concurrent.ExecutionException - One of the tasks threw an exception
java.lang.InterruptedException - The current thread was interrupted while waiting