public class SimpleCommandBus extends Object implements CommandBus
Constructor and Description |
---|
SimpleCommandBus()
Initializes the SimpleCommandBus.
|
SimpleCommandBus(TransactionManager transactionManager,
MessageMonitor<? super CommandMessage<?>> messageMonitor)
Initializes the SimpleCommandBus with the given
transactionManager and messageMonitor |
Modifier and Type | Method and Description |
---|---|
<C,R> void |
dispatch(CommandMessage<C> command,
CommandCallback<? super C,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,R> callback)
Performs the actual dispatching logic.
|
protected <C,R> void |
handle(CommandMessage<C> command,
MessageHandler<? super CommandMessage<?>> handler,
CommandCallback<? super C,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 committed.
|
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
public SimpleCommandBus()
public SimpleCommandBus(TransactionManager transactionManager, MessageMonitor<? super CommandMessage<?>> messageMonitor)
transactionManager
and messageMonitor
transactionManager
- The transactionManager to manage transaction withmessageMonitor
- the message monitor to monitor the command buspublic <C,R> void dispatch(CommandMessage<C> command, CommandCallback<? super C,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,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,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
- The RollbackConfiguration.Copyright © 2010–2018. All rights reserved.