Class AsynchronousCommandBus
- All Implemented Interfaces:
CommandBus,MessageDispatchInterceptorSupport<CommandMessage<?>>,MessageHandlerInterceptorSupport<CommandMessage<?>>
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.- Since:
- 1.3.4
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aAsynchronousCommandBus. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAsynchronousCommandBusbased on the fields contained in theAsynchronousCommandBus.Builder. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Instantiate a Builder to be able to create aAsynchronousCommandBus.protected <C,R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C, ? super R> callback) Performs the actual handling logic.voidshutdown()Shuts down the Executor used to asynchronously dispatch incoming commands.Methods inherited from class org.axonframework.commandhandling.SimpleCommandBus
dispatch, dispatch, doDispatch, intercept, registerDispatchInterceptor, registerHandlerInterceptor, setRollbackConfiguration, subscribe
-
Constructor Details
-
AsynchronousCommandBus
Instantiate aAsynchronousCommandBusbased on the fields contained in theAsynchronousCommandBus.Builder.Will assert that the
TransactionManager,MessageMonitor,RollbackConfigurationandExecutorare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theAsynchronousCommandBus.Builderused to instantiate aAsynchronousCommandBusinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aAsynchronousCommandBus.The
TransactionManageris defaulted to aNoTransactionManager, theMessageMonitoris defaulted to aNoOpMessageMonitor,RollbackConfigurationdefaults to aRollbackConfigurationType.UNCHECKED_EXCEPTIONS, theDuplicateCommandHandlerResolverdefaults toDuplicateCommandHandlerResolution.logAndOverride(), theExecutordefaults to aExecutors.newCachedThreadPool()and theCommandBusSpanFactorydefaults to aDefaultCommandBusSpanFactorybacked by aNoOpSpanFactory. The defaultexecutoruses anAxonThreadFactoryto create threads with a sensible naming scheme. The TransactionManager, MessageMonitor, RollbackConfiguration and Executor are hard requirements. Thus setting them tonullwill result in anAxonConfigurationException.- Returns:
- a Builder to be able to create a
AsynchronousCommandBus
-
handle
protected <C,R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C, ? super R> callback) Description copied from class:SimpleCommandBusPerforms the actual handling logic.- Overrides:
handlein classSimpleCommandBus- Type Parameters:
C- The type of payload of the commandR- The type of result expected from the command handler- Parameters:
command- The actual command to handlehandler- The handler that must be invoked for this commandcallback- The callback to notify of the result
-
shutdown
public void shutdown()Shuts down the Executor used to asynchronously dispatch incoming commands. If theExecutorprovided in the constructor does not implementExecutorService, this method does nothing.
-