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.Modifier and Type | Class and Description |
---|---|
static class |
AsynchronousCommandBus.Builder
Builder class to instantiate a
AsynchronousCommandBus . |
Modifier | Constructor and Description |
---|---|
protected |
AsynchronousCommandBus(AsynchronousCommandBus.Builder builder)
Instantiate a
AsynchronousCommandBus based on the fields contained in the AsynchronousCommandBus.Builder . |
Modifier and Type | Method and Description |
---|---|
static AsynchronousCommandBus.Builder |
builder()
Instantiate a Builder to be able to create a
AsynchronousCommandBus . |
protected <C,R> void |
handle(CommandMessage<C> command,
MessageHandler<? super CommandMessage<?>> handler,
CommandCallback<? super C,? super R> callback)
Performs the actual handling logic.
|
void |
shutdown()
Shuts down the Executor used to asynchronously dispatch incoming commands.
|
dispatch, dispatch, doDispatch, intercept, registerDispatchInterceptor, registerHandlerInterceptor, setRollbackConfiguration, subscribe
protected AsynchronousCommandBus(AsynchronousCommandBus.Builder builder)
AsynchronousCommandBus
based on the fields contained in the AsynchronousCommandBus.Builder
.
Will assert that the TransactionManager
, MessageMonitor
, RollbackConfiguration
and
Executor
are not null
, and will throw an AxonConfigurationException
if any of them is
null
.
builder
- the AsynchronousCommandBus.Builder
used to instantiate a AsynchronousCommandBus
instancepublic static AsynchronousCommandBus.Builder builder()
AsynchronousCommandBus
.
The TransactionManager
is defaulted to a NoTransactionManager
, the MessageMonitor
is
defaulted to a NoOpMessageMonitor
, RollbackConfiguration
defaults to a
RollbackConfigurationType.UNCHECKED_EXCEPTIONS
, the DuplicateCommandHandlerResolver
defaults to
DuplicateCommandHandlerResolution.logAndOverride()
and the Executor
defaults to a
Executors.newCachedThreadPool()
. The defaultexecutor
uses an AxonThreadFactory
to create
threads with a sensible naming scheme. The TransactionManager, MessageMonitor, RollbackConfiguration and Executor
are hard requirements. Thus setting them to null
will result in an
AxonConfigurationException
.
AsynchronousCommandBus
protected <C,R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C,? super 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–2022. All rights reserved.