|
||||||||||
| 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(Object command)
Dispatch the given command to the CommandHandler subscribed to that type of command. |
|
|
dispatch(Object command,
CommandCallback<R> callback)
Dispatch the given command to the CommandHandler subscribed to that type of command. |
|
|
subscribe(Class<C> commandType,
CommandHandler<? super C> handler)
Subscribe the given handler to commands of type commandType. |
|
|
unsubscribe(Class<C> commandType,
CommandHandler<? super C> handler)
Unsubscribe the given handler to commands of type commandType. |
|
| Method Detail |
|---|
void dispatch(Object 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.
<R> void dispatch(Object 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.
<C> void subscribe(Class<C> commandType,
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 commandcommandType - The type of command to subscribe the handler tohandler - The handler instance that handles the given type of command
<C> void unsubscribe(Class<C> commandType,
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 commandcommandType - The type of command the handler is subscribed tohandler - The handler instance to unsubscribe from the CommandBus
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||