public class CallbackExecutor extends Object implements Runnable
callbackExecutorService is where the callbacks get run.
handlerExecutorService listens to results from callbackExecutorService (using completionService)
and, when needed, submits any followup callbacks to callbackExecutorService
Modifier and Type | Field and Description |
---|---|
protected ExecutorService |
callbackExecutorService |
protected CompletionService<com.flyingspaniel.nava.callback.CallbackAnd.Input> |
completionService |
AtomicInteger |
exceptionCount |
protected ExecutorService |
handlerExecutorService |
AtomicReference<Object> |
lastResultOrException |
Constructor and Description |
---|
CallbackExecutor(int callbackThreads,
int handlerThreads)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
handleNormalCallbackException(Exception urException)
Handle a normal callback exception.
|
void |
run() |
void |
shutdown(long waitMS)
Mainly for unit tests, but performs an orderly shutdown
|
void |
submitCallback(Callback first,
Object inData,
Object... more)
Submit a callback (generally the first of a chain)
|
protected void |
submitMultiple(com.flyingspaniel.nava.callback.CallbackAnd.Output cao) |
protected final ExecutorService callbackExecutorService
protected final CompletionService<com.flyingspaniel.nava.callback.CallbackAnd.Input> completionService
protected final ExecutorService handlerExecutorService
public final AtomicInteger exceptionCount
public final AtomicReference<Object> lastResultOrException
public CallbackExecutor(int callbackThreads, int handlerThreads)
callbackThreads
- should generally be >= handlerThreadshandlerThreads
- must be > 0public void submitCallback(Callback first, Object inData, Object... more)
first
- should be non-nullinData
- passed to first callbackpublic void shutdown(long waitMS) throws InterruptedException
waitMS
- milliseconds, if > 0, will put in three waits along the wayInterruptedException
protected void submitMultiple(com.flyingspaniel.nava.callback.CallbackAnd.Output cao)
protected void handleNormalCallbackException(Exception urException)
urException
- the original exception (not wrapped in any of our constructs)