org.axonframework.test.utils
Class RecordingCommandBus

java.lang.Object
  extended by org.axonframework.test.utils.RecordingCommandBus
All Implemented Interfaces:
CommandBus

public class RecordingCommandBus
extends Object
implements CommandBus

CommandBus implementation that does not perform any actions on subscriptions or dispatched commands, but records them instead. This implementation is not a stand-in replacement for a mock, but might prove useful in many simple cases.

Since:
1.1
Author:
Allard Buijze

Constructor Summary
RecordingCommandBus()
           
 
Method Summary
 void clearCommands()
          Clears all the commands recorded by this Command Bus.
 void clearSubscriptions()
          Clears all subscribed handlers on this command bus.
 void dispatch(CommandMessage<?> command)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
<R> void
dispatch(CommandMessage<?> command, CommandCallback<R> callback)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
 List<CommandMessage<?>> getDispatchedCommands()
          Returns a list with all commands that have been dispatched by this command bus.
 Map<String,CommandHandler<?>> getSubscriptions()
          Returns a Map will all Command Names and their Command Handler that have been subscribed to this command bus.
 boolean isSubscribed(CommandHandler<?> commandHandler)
          Indicates whether the given commandHandler is subscribed to this command bus.
<C> boolean
isSubscribed(String commandName, CommandHandler<? super C> commandHandler)
          Indicates whether the given commandHandler is subscribed to commands of the given commandType on this command bus.
 void setCallbackBehavior(CallbackBehavior callbackBehavior)
          Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.
<C> void
subscribe(String commandName, CommandHandler<? super C> handler)
          Subscribe the given handler to commands of type commandType.
<C> boolean
unsubscribe(String commandName, CommandHandler<? super C> handler)
          Unsubscribe the given handler to commands of type commandType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordingCommandBus

public RecordingCommandBus()
Method Detail

dispatch

public void dispatch(CommandMessage<?> command)
Description copied from interface: CommandBus
Dispatch the given 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.

Specified by:
dispatch in interface CommandBus
Parameters:
command - The Command to dispatch
See Also:
GenericCommandMessage.asCommandMessage(Object)

dispatch

public <R> void dispatch(CommandMessage<?> command,
                         CommandCallback<R> callback)
Description copied from interface: CommandBus
Dispatch the given 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.

Specified by:
dispatch in interface CommandBus
Type Parameters:
R - The type of the expected result
Parameters:
command - The Command to dispatch
callback - The callback to invoke when command processing is complete
See Also:
GenericCommandMessage.asCommandMessage(Object)

subscribe

public <C> void subscribe(String commandName,
                          CommandHandler<? super C> handler)
Description copied from interface: CommandBus
Subscribe the given 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.

Specified by:
subscribe in interface CommandBus
Type Parameters:
C - The Type of command
Parameters:
commandName - The name of the command to subscribe the handler to
handler - The handler instance that handles the given type of command

unsubscribe

public <C> boolean unsubscribe(String commandName,
                               CommandHandler<? super C> handler)
Description copied from interface: CommandBus
Unsubscribe the given handler to commands of type commandType. If the handler is not currently assigned to that type of command, no action is taken.

Specified by:
unsubscribe in interface CommandBus
Type Parameters:
C - The Type of command
Parameters:
commandName - The name of the command the handler is subscribed to
handler - The handler instance to unsubscribe from the CommandBus
Returns:
true of this handler is successfully unsubscribed, false of the given handler was not the current handler for given commandType.

clearCommands

public void clearCommands()
Clears all the commands recorded by this Command Bus.


clearSubscriptions

public void clearSubscriptions()
Clears all subscribed handlers on this command bus.


isSubscribed

public boolean isSubscribed(CommandHandler<?> commandHandler)
Indicates whether the given commandHandler is subscribed to this command bus.

Parameters:
commandHandler - The command handler to verify the subscription for
Returns:
true if the handler is subscribed, otherwise false.

isSubscribed

public <C> boolean isSubscribed(String commandName,
                                CommandHandler<? super C> commandHandler)
Indicates whether the given commandHandler is subscribed to commands of the given commandType on this command bus.

Type Parameters:
C - The type of command to verify the subscription for
Parameters:
commandName - The name of the command to verify the subscription for
commandHandler - The command handler to verify the subscription for
Returns:
true if the handler is subscribed, otherwise false.

getSubscriptions

public Map<String,CommandHandler<?>> getSubscriptions()
Returns a Map will all Command Names and their Command Handler that have been subscribed to this command bus.

Returns:
a Map will all Command Names and their Command Handler

getDispatchedCommands

public List<CommandMessage<?>> getDispatchedCommands()
Returns a list with all commands that have been dispatched by this command bus.

Returns:
a list with all commands that have been dispatched

setCallbackBehavior

public void setCallbackBehavior(CallbackBehavior callbackBehavior)
Sets the instance that defines the behavior of the Command Bus when a command is dispatched with a callback.

Parameters:
callbackBehavior - The instance deciding to how the callback should be invoked.


Copyright © 2010-2016. All Rights Reserved.