public interface CommandBus
name
) on the command
bus. Only a single handler may be subscribed for a single command name at any time.Modifier and Type | Method and Description |
---|---|
default <C> void |
dispatch(CommandMessage<C> command)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
<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. |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> handler)
Subscribe the given
handler to commands with the given commandName . |
default <C> void dispatch(CommandMessage<C> command)
command
to the CommandHandler subscribed to the given command
's name.
No feedback is given about the status of the dispatching process. Implementations may return immediately after
asserting a valid handler is registered for the given command.C
- The payload type of the command to dispatchcommand
- The Command to dispatchNoHandlerForCommandException
- when no command handler is registered for the given command
's name.GenericCommandMessage.asCommandMessage(Object)
<C,R> void dispatch(CommandMessage<C> command, CommandCallback<? super C,R> callback)
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.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 completeNoHandlerForCommandException
- when no command handler is registered for the given command
.GenericCommandMessage.asCommandMessage(Object)
Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler)
handler
to commands with the given commandName
.
If a subscription already exists for the given name, the behavior is undefined. Implementations may throw an
Exception to refuse duplicate subscription or alternatively decide whether the existing or new
handler
gets the subscription.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.Copyright © 2010–2017. All rights reserved.