S - The concrete type of the state object.public class DefaultCommandBus<S extends State> extends AbstractMessageBus<Command,CommandHandler<S,Command,Event>> implements CommandBus<S>
CommandBus.| Modifier and Type | Field and Description |
|---|---|
protected ExecutorService |
commandHandlerExecutor
Executor service that runs the async command handlers.
|
protected EventBus<S> |
eventBus
The event bus to pass generated events to.
|
protected CommandLoggerHelper |
loggerHelper
Used for logging the command handler operations.
|
protected StateObserver<S> |
stateObserver
Provides access to the current state.
|
protected static Set<Class<? extends CommandHandler>> |
SUPPORTED
Set of supported command handlers.
|
messageHandlerMap, messageStore, onMessageAddedToStore| Constructor and Description |
|---|
DefaultCommandBus(MessageStore messageStore,
EventBus<S> eventBus,
CommandLoggerHelper loggerHelper,
StateObserver<S> stateObserver) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCommandLogger(CommandLogger logger)
Add a command logger.
|
void |
dispose()
Hook for cleaning up: remove listeners, shutdown threads, etc.
|
protected void |
executeCommandHandler(S state,
Command command,
CommandHandler<S,Command,Event> handler)
Execute a command handler that produces 0 or 1 event.
|
protected void |
executeHandler(Command command,
CommandHandler<S,Command,Event> commandHandler)
Actually execute the message handler for this message.
|
protected void |
executeMultiCommandHandler(S state,
Command command,
MultiCommandHandler<S,Command,Event> handler)
Execute a command handler that produces a collection of events.
|
protected ExecutorService |
getCommandHandlerExecutor()
Returns the command handler executor.
|
void |
handleCommand(Command command)
Execute the command handler that is mapped to this command type.
|
protected void |
handleMultiResult(Throwable error,
Command command,
Collection<Event> events)
Handle result from a 'multi' command handler.
|
protected void |
handleResult(Throwable error,
Command command,
Event event)
Handle result from a 'single' command handler.
|
protected <C extends Command,E extends Event> |
isCommandHandlerSupported(CommandHandler<S,C,E> commandHandler)
Checks whether this command handler implementation is supported.
|
<C extends Command,E extends Event> |
mapCommandHandler(Class<C> commandClass,
CommandHandler<S,C,E> commandHandler)
Map a command handler for a concrete command type.
|
void |
removeCommandLogger(CommandLogger logger)
Remove a command logger.
|
void |
setCommandHandlerExecutor(ExecutorService executor)
Sets the executor service to use for executing async command handlers.
|
protected boolean |
shouldHandleMessageType(Message message)
Returns whether this message bus implementation should handle the concrete message object.
|
getMessageHandlers, handleMessage, mapMessageHandlerprotected static final Set<Class<? extends CommandHandler>> SUPPORTED
protected ExecutorService commandHandlerExecutor
protected final EventBus<S extends State> eventBus
protected final CommandLoggerHelper loggerHelper
protected final StateObserver<S extends State> stateObserver
public DefaultCommandBus(MessageStore messageStore, EventBus<S> eventBus, CommandLoggerHelper loggerHelper, StateObserver<S> stateObserver)
public void addCommandLogger(CommandLogger logger)
CommandLoggerAwareaddCommandLogger in interface CommandLoggerAwarelogger - The command logger to add.public void dispose()
Disposabledispose in interface Disposabledispose in class AbstractMessageBus<Command,CommandHandler<S extends State,Command,Event>>public void handleCommand(Command command)
CommandBushandleCommand in interface CommandBus<S extends State>command - The command to handle.CommandBus.mapCommandHandler(Class, CommandHandler)public <C extends Command,E extends Event> void mapCommandHandler(Class<C> commandClass, CommandHandler<S,C,E> commandHandler)
CommandBusmapCommandHandler in interface CommandBus<S extends State>C - The concrete command type that this handler will handle.E - The concrete event type that this handler will produce.commandClass - The concrete command type that this handler will handle.commandHandler - The handler that is executed when CommandBus.handleCommand(Command) is
called.public void removeCommandLogger(CommandLogger logger)
CommandLoggerAwareremoveCommandLogger in interface CommandLoggerAwarelogger - The command logger to remove.public void setCommandHandlerExecutor(ExecutorService executor)
setCommandHandlerExecutor in interface CommandBus<S extends State>executor - The executor service to use.protected void executeHandler(Command command, CommandHandler<S,Command,Event> commandHandler)
AbstractMessageBusexecuteHandler in class AbstractMessageBus<Command,CommandHandler<S extends State,Command,Event>>command - The message to handle.commandHandler - The message handler that is associated with this message.protected boolean shouldHandleMessageType(Message message)
AbstractMessageBusshouldHandleMessageType in class AbstractMessageBus<Command,CommandHandler<S extends State,Command,Event>>message - The concrete message object.Mprotected void executeCommandHandler(S state, Command command, CommandHandler<S,Command,Event> handler)
state - The current state object.command - The command object.handler - The handler to execute.protected void executeMultiCommandHandler(S state, Command command, MultiCommandHandler<S,Command,Event> handler)
state - The current state object.command - The command object.handler - The handler to execute.protected ExecutorService getCommandHandlerExecutor()
protected void handleResult(Throwable error, Command command, Event event)
error - (Optional) An error that occurred.command - The command that was handled.event - (Optional) The event that was produced by the command handler.protected void handleMultiResult(Throwable error, Command command, Collection<Event> events)
error - (Optional) An error that occurred.command - The command that was handled.events - (Optional) The events that were produced by the command handler.protected <C extends Command,E extends Event> void isCommandHandlerSupported(CommandHandler<S,C,E> commandHandler)
C - Concrete type of the command.E - Concrete type of the event.commandHandler - The command handler to check.UnsupportedCommandHandlerException - if the implementation is not supported.Copyright © 2016 Cooking Fox. All rights reserved.