public class RecordingCommandBus extends Object implements CommandBus
Constructor and Description |
---|
RecordingCommandBus() |
Modifier and Type | Method and Description |
---|---|
void |
clearCommands()
Clears all the commands recorded by this Command Bus.
|
void |
clearSubscriptions()
Clears all subscribed handlers on this command bus.
|
<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,? super R> callback)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
List<CommandMessage<?>> |
getDispatchedCommands()
Returns a list with all commands that have been dispatched by this command bus.
|
Map<String,MessageHandler<? super CommandMessage<?>>> |
getSubscriptions()
Returns a Map will all Command Names and their Command Handler that have been subscribed to this command bus.
|
boolean |
isSubscribed(MessageHandler<? super CommandMessage<?>> commandHandler)
Indicates whether the given
commandHandler is subscribed to this command bus. |
<C> boolean |
isSubscribed(String commandName,
MessageHandler<? super CommandMessage<?>> commandHandler)
Indicates whether the given
commandHandler is subscribed to commands of the given
commandType on this command bus. |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
Register the given DispatchInterceptor.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
Register the given
handlerInterceptor . |
void |
setCallbackBehavior(CallbackBehavior callbackBehavior)
Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.
|
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> handler)
Subscribe the given
handler to commands with the given commandName . |
public <C> void dispatch(@Nonnull CommandMessage<C> command)
CommandBus
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.dispatch
in interface CommandBus
C
- The payload type of the command to dispatchcommand
- The Command to dispatchGenericCommandMessage.asCommandMessage(Object)
public <C,R> void dispatch(@Nonnull CommandMessage<C> command, @Nonnull 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.
There are no guarantees about the successful completion of command dispatching or handling after the method
returns. 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)
public Registration subscribe(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> handler)
CommandBus
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.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 void clearCommands()
public void clearSubscriptions()
public boolean isSubscribed(MessageHandler<? super CommandMessage<?>> commandHandler)
commandHandler
is subscribed to this command bus.commandHandler
- The command handler to verify the subscription fortrue
if the handler is subscribed, otherwise false
.public <C> boolean isSubscribed(String commandName, MessageHandler<? super CommandMessage<?>> commandHandler)
commandHandler
is subscribed to commands of the given
commandType
on this command bus.C
- The type of command to verify the subscription forcommandName
- The name of the command to verify the subscription forcommandHandler
- The command handler to verify the subscription fortrue
if the handler is subscribed, otherwise false
.public Map<String,MessageHandler<? super CommandMessage<?>>> getSubscriptions()
public List<CommandMessage<?>> getDispatchedCommands()
public void setCallbackBehavior(CallbackBehavior callbackBehavior)
callbackBehavior
- The instance deciding to how the callback should be invoked.public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
MessageDispatchInterceptorSupport
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
dispatchInterceptor
- The interceptor to registerpublic Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
MessageHandlerInterceptorSupport
handlerInterceptor
. After registration, the interceptor will be invoked for each
handled Message on the messaging component that it was registered to, prior to invoking the message's handler.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<CommandMessage<?>>
handlerInterceptor
- The interceptor to registerCopyright © 2010–2023. All rights reserved.