Package com.opencqrs.framework.command
Class CommandRouter
java.lang.Object
com.opencqrs.framework.command.CommandRouter
Command
router implementation providing CQRS-style command execution.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCommandRouter
(EventReader eventReader, ImmediateEventPublisher immediateEventPublisher, List<CommandHandlerDefinition> commandHandlerDefinitions, List<StateRebuildingHandlerDefinition> stateRebuildingHandlerDefinitions) Creates a pre-configured instance ofthis
with disabled meta-data propagation andNoStateRebuildingCache
.CommandRouter
(EventReader eventReader, ImmediateEventPublisher immediateEventPublisher, List<CommandHandlerDefinition> commandHandlerDefinitions, List<StateRebuildingHandlerDefinition> stateRebuildingHandlerDefinitions, StateRebuildingCache stateRebuildingCache, PropagationMode propagationMode, Set<String> propagationKeys) Creates a pre-configured instance ofthis
. -
Method Summary
Modifier and TypeMethodDescription<R> R
Sends the given command with empty meta-data to the appropriateCommandHandler
for execution.<R> R
Sends the given command and meta-data to the appropriateCommandHandler
for execution.
-
Constructor Details
-
CommandRouter
public CommandRouter(EventReader eventReader, ImmediateEventPublisher immediateEventPublisher, List<CommandHandlerDefinition> commandHandlerDefinitions, List<StateRebuildingHandlerDefinition> stateRebuildingHandlerDefinitions, StateRebuildingCache stateRebuildingCache, PropagationMode propagationMode, Set<String> propagationKeys) Creates a pre-configured instance ofthis
.- Parameters:
eventReader
- the event sourceimmediateEventPublisher
- the event sinkcommandHandlerDefinitions
- a non-empty list of command handler definitions to be executablestateRebuildingHandlerDefinitions
- a non-empty list of state rebuilding handler definitions used for event-sourcingstateRebuildingCache
- the cache to use for state rebuildingpropagationMode
- the propagation sourcingMode for command meta-datapropagationKeys
- the command meta-data keys to propagate, if necessary
-
CommandRouter
public CommandRouter(EventReader eventReader, ImmediateEventPublisher immediateEventPublisher, List<CommandHandlerDefinition> commandHandlerDefinitions, List<StateRebuildingHandlerDefinition> stateRebuildingHandlerDefinitions) Creates a pre-configured instance ofthis
with disabled meta-data propagation andNoStateRebuildingCache
.- Parameters:
eventReader
- the event sourceimmediateEventPublisher
- the event sinkcommandHandlerDefinitions
- a non-empty list of command handler definitions to be executablestateRebuildingHandlerDefinitions
- a non-empty list of state rebuilding handler definitions used for event-sourcing
-
-
Method Details
-
send
Sends the given command with empty meta-data to the appropriateCommandHandler
for execution. The command execution process involves the following:- the matching
CommandHandler
is determined - the instance type for state rebuilding is determined
- all matching
StateRebuildingHandler
s are determined - the
StateRebuildingCache
is fetched - newer (than cached) events are EventReader.consumeAsObject(EventReader.ClientRequestor, BiConsumer) read} from the underlying event store, upcasted and converted to Java objects
- the
Command.getSubjectCondition()
is checked - the events are applied to all matching
StateRebuildingHandler
s to reconstruct the instance state - the cache is updated with the reconstructed instance state
- the command is executed on the instance
- all events captured as part of the command execution are published atomically to the underlying event store
- the
CommandHandler
result is returned to the caller
- Type Parameters:
R
- the result type- Parameters:
command
- the command to be executed- Returns:
- the result from the
CommandHandler
, may benull
- the matching
-
send
Sends the given command and meta-data to the appropriateCommandHandler
for execution. The command execution process involves the following:- the matching
CommandHandler
is determined - the instance type for event-sourcing is determined
- all matching
StateRebuildingHandler
s are determined - the
StateRebuildingCache
is fetched - newer (than cached) events are EventReader.consumeAsObject(EventReader.ClientRequestor, BiConsumer) read} from the underlying event store, upcasted and converted to Java objects
- the
Command.getSubjectCondition()
is checked - the events are applied to all matching
StateRebuildingHandler
s to reconstruct the instance state - the cache is updated with the reconstructed instance state
- the command is executed on the instance
- all events captured as part of the command execution are applied with propagated command meta-data
- the events are published atomically to the underlying event store
- the
CommandHandler
result is returned to the caller
- Type Parameters:
R
- the result type- Parameters:
command
- the command to be executedmetaData
- the meta-data to be passed to the command handler- Returns:
- the result from the
CommandHandler
, may benull
- the matching
-