Class BeforeAfterCaller<ValueT>

java.lang.Object
  extended by BeforeAfterCaller<ValueT>
Type Parameters:
ValueT - the type of the Future returned by submit().

public class BeforeAfterCaller<ValueT>
extends Object

Call the methods of a BeforeAfterCallable using an Executor. Uses a CyclicBarrier to synchronize the submitting thread with the worker thread when the chosen Executor uses a different thread.


Field Summary
static int DEFAULT_TIMEOUT
          Milliseconds to wait before the CyclicBarrier times out: 60000 milliseconds.
 
Constructor Summary
BeforeAfterCaller()
          Create with a simple Executor that creates a separate worker thread.
BeforeAfterCaller(Executor executor)
          Create with the given Executor.
BeforeAfterCaller(Executor executor, int timeoutMs)
          Create with the given Executor.
 
Method Summary
 Executor getExecutor()
          Returns the Executor.
 BeforeAfterFutureTask<ValueT> submit(BeforeAfterCallable<ValueT> task)
          Submit the BeforeAfterCallable to be executed by the Executor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
Milliseconds to wait before the CyclicBarrier times out: 60000 milliseconds.

See Also:
Constant Field Values
Constructor Detail

BeforeAfterCaller

public BeforeAfterCaller()
Create with a simple Executor that creates a separate worker thread.


BeforeAfterCaller

public BeforeAfterCaller(Executor executor)
Create with the given Executor.

Parameters:
executor - Executor

BeforeAfterCaller

public BeforeAfterCaller(Executor executor,
                         int timeoutMs)
Create with the given Executor.

Parameters:
executor - Executor
timeoutMs - how long to wait for submitting thread and worker thread to synchronize
Method Detail

submit

public BeforeAfterFutureTask<ValueT> submit(BeforeAfterCallable<ValueT> task)
                                     throws Exception
Submit the BeforeAfterCallable to be executed by the Executor. Multiple calls to submit() can execute concurrently. Throws an Error if proceed() was not called by the time before() returns. Throws an Exception if there was a problem coordinating with the worker thread; such an exception has as its cause the Exception thrown by CyclicBarrier.

Parameters:
task - what to run
Returns:
BeforeAfterFutureTask
Throws:
Exception - or Error

getExecutor

public Executor getExecutor()
Returns the Executor.

Returns:
Executor