public class SimpleCommandBus extends Object implements CommandBus
Modifier and Type | Class and Description |
---|---|
static class |
SimpleCommandBus.Builder
Builder class to instantiate a
SimpleCommandBus . |
Modifier | Constructor and Description |
---|---|
protected |
SimpleCommandBus(SimpleCommandBus.Builder builder)
Instantiate a
SimpleCommandBus based on the fields contained in the SimpleCommandBus.Builder . |
Modifier and Type | Method and Description |
---|---|
static SimpleCommandBus.Builder |
builder()
Instantiate a Builder to be able to create a
SimpleCommandBus . |
<C,R> void |
dispatch(CommandMessage<C> command,
CommandCallback<? super C,? super R> callback)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
protected <C,R> void |
doDispatch(CommandMessage<C> command,
CommandCallback<? super C,? super R> callback)
Performs the actual dispatching logic.
|
protected <C,R> void |
handle(CommandMessage<C> command,
MessageHandler<? super CommandMessage<?>> handler,
CommandCallback<? super C,? super R> callback)
Performs the actual handling logic.
|
protected <C> CommandMessage<C> |
intercept(CommandMessage<C> command)
Invokes all the dispatch interceptors.
|
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
Registers the given list of dispatch interceptors to the command bus.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
Registers the given interceptor to the command bus.
|
void |
setRollbackConfiguration(RollbackConfiguration rollbackConfiguration)
Sets the
RollbackConfiguration that allows you to change when the UnitOfWork is rolled back. |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> handler)
Subscribe the given
handler to commands with given commandName . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dispatch
protected SimpleCommandBus(SimpleCommandBus.Builder builder)
SimpleCommandBus
based on the fields contained in the SimpleCommandBus.Builder
.
Will assert that the TransactionManager
, MessageMonitor
and RollbackConfiguration
are not
null
, and will throw an AxonConfigurationException
if any of them is null
.
builder
- the SimpleCommandBus.Builder
used to instantiate a SimpleCommandBus
instancepublic static SimpleCommandBus.Builder builder()
SimpleCommandBus
.
The TransactionManager
is defaulted to a NoTransactionManager
, the MessageMonitor
is
defaulted to a NoOpMessageMonitor
and the RollbackConfiguration
defaults to a
RollbackConfigurationType.UNCHECKED_EXCEPTIONS
.
The TransactionManager
, MessageMonitor
and RollbackConfiguration
are hard
requirements. Thus setting them to null
will result in an AxonConfigurationException
.
SimpleCommandBus
public <C,R> void dispatch(CommandMessage<C> command, CommandCallback<? super C,? super R> callback)
CommandBus
command
to the CommandHandler subscribed to the given command
's name.
When the command is processed, one of the callback's methods is called, depending on the result of the processing.
When the method returns, the only guarantee provided by the CommandBus implementation is that the command has
been successfully received. Implementations are highly recommended to perform basic validation of the command
before returning from this method call.
Implementations must start a UnitOfWork when before dispatching the command, and either commit or rollback after
a successful or failed execution, respectively.dispatch
in interface CommandBus
C
- The payload type of the command to dispatchR
- The type of the expected resultcommand
- The Command to dispatchcallback
- The callback to invoke when command processing is completeGenericCommandMessage.asCommandMessage(Object)
protected <C> CommandMessage<C> intercept(CommandMessage<C> command)
command
- The original command being dispatchedprotected <C,R> void doDispatch(CommandMessage<C> command, CommandCallback<? super C,? super R> callback)
C
- The type of payload of the commandR
- The type of result expected from the command handlercommand
- The actual command to dispatch to the handlercallback
- The callback to notify of the resultprotected <C,R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C,? super R> callback)
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 Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler)
handler
to commands with given commandName
. If a subscription already
exists for the given name, then the new handler takes over the subscription.subscribe
in interface CommandBus
commandName
- The name of the command to subscribe the handler tohandler
- The handler instance that handles the given type of commandhandler
. When unsubscribed it will no longer receive commands.public Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<CommandMessage<?>>
handlerInterceptor
- The interceptor to invoke when commands are handledpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
dispatchInterceptor
- The interceptors to invoke when commands are dispatchedpublic void setRollbackConfiguration(RollbackConfiguration rollbackConfiguration)
RollbackConfiguration
that allows you to change when the UnitOfWork
is rolled back. If
not set the, RollbackConfigurationType.UNCHECKED_EXCEPTIONS
will be used, which triggers a rollback on
all unchecked exceptions.rollbackConfiguration
- a RollbackConfiguration
specifying when a UnitOfWork
should be
rolled backCopyright © 2010–2019. All rights reserved.