public class AsynchronousCommandBus extends SimpleCommandBus
Executors.newCachedThreadPool()
). It will reuse threads while possible, and shut them
down after 60 seconds of inactivity.
Each Command is dispatched in a separate task, which is processed by the Executor.
Note that you should call shutdown()
to stop any threads waiting for new tasks. Failure to do so may cause
the JVM to hang for up to 60 seconds on JVM shutdown.Constructor and Description |
---|
AsynchronousCommandBus()
Initialize the AsynchronousCommandBus, using a Cached Thread Pool.
|
AsynchronousCommandBus(Executor executor)
Initialize the AsynchronousCommandBus using the given
executor . |
AsynchronousCommandBus(Executor executor,
TransactionManager transactionManager,
MessageMonitor<? super CommandMessage<?>> messageMonitor)
Initialize the AsynchronousCommandBus using the given
executor , transactionManager and
messageMonitor . |
Modifier and Type | Method and Description |
---|---|
protected <C,R> void |
handle(CommandMessage<C> command,
MessageHandler<? super CommandMessage<?>> handler,
CommandCallback<? super C,R> callback)
Performs the actual handling logic.
|
void |
shutdown()
Shuts down the Executor used to asynchronously dispatch incoming commands.
|
dispatch, doDispatch, intercept, registerDispatchInterceptor, registerHandlerInterceptor, setRollbackConfiguration, subscribe
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dispatch
public AsynchronousCommandBus()
public AsynchronousCommandBus(Executor executor)
executor
.executor
- The executor that processes Command dispatching threadspublic AsynchronousCommandBus(Executor executor, TransactionManager transactionManager, MessageMonitor<? super CommandMessage<?>> messageMonitor)
executor
, transactionManager
and
messageMonitor
.executor
- The executor that processes Command dispatching threadstransactionManager
- The transactionManager to manage transaction withmessageMonitor
- The message monitor to monitor the command busprotected <C,R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C,R> callback)
SimpleCommandBus
handle
in class SimpleCommandBus
C
- The type of payload of the commandR
- The type of result expected from the command handlercommand
- The actual command to handlehandler
- The handler that must be invoked for this commandcallback
- The callback to notify of the resultpublic void shutdown()
Executor
provided
in the constructor does not implement ExecutorService
, this method does nothing.Copyright © 2010–2017. All rights reserved.