|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface CommandBus
The mechanism that dispatches Command objects to their appropriate CommandHandler. CommandHandlers can subscribe and unsubscribe to specific types of commands on the command bus. Only a single handler may be subscribed for a single type of command at any time.
Method Summary | ||
---|---|---|
void |
dispatch(CommandMessage<?> command)
Dispatch the given command to the CommandHandler subscribed to that type of command . |
|
|
dispatch(CommandMessage<?> command,
CommandCallback<R> callback)
Dispatch the given command to the CommandHandler subscribed to that type of command . |
|
|
subscribe(String commandName,
CommandHandler<? super C> handler)
Subscribe the given handler to commands of type commandType . |
|
|
unsubscribe(String commandName,
CommandHandler<? super C> handler)
Unsubscribe the given handler to commands of type commandType . |
Method Detail |
---|
void dispatch(CommandMessage<?> command)
command
to the CommandHandler subscribed to that type of command
.
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.
command
- The Command to dispatch
NoHandlerForCommandException
- when no command handler is registered for the given command
.GenericCommandMessage.asCommandMessage(Object)
<R> void dispatch(CommandMessage<?> command, CommandCallback<R> callback)
command
to the CommandHandler subscribed to that type of command
.
When the command is processed, on of the callback 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.
R
- The type of the expected resultcommand
- The Command to dispatchcallback
- The callback to invoke when command processing is complete
NoHandlerForCommandException
- when no command handler is registered for the given command
.GenericCommandMessage.asCommandMessage(Object)
<C> void subscribe(String commandName, CommandHandler<? super C> handler)
handler
to commands of type commandType
.
If a subscription already exists for the given type, 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.
C
- The Type of commandcommandName
- The name of the command to subscribe the handler tohandler
- The handler instance that handles the given type of command<C> boolean unsubscribe(String commandName, CommandHandler<? super C> handler)
handler
to commands of type commandType
. If the handler is not
currently assigned to that type of command, no action is taken.
C
- The Type of commandcommandName
- The name of the command the handler is subscribed tohandler
- The handler instance to unsubscribe from the CommandBus
true
of this handler is successfully unsubscribed, false
of the given
handler
was not the current handler for given commandType
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |