Interface CommandHandler<COMMAND,EVENT,ERROR>
- Type Parameters:
COMMAND- The type of Commands that theHandler.handle(Object, Object)can processEVENT- The type of Events that can be returned byHandler.handle(Object, Object)and applied in theStateEvolver.applyEvent(Object, Object)ERROR- The type of Error that can be returned by theHandler.handle(Object, Object)method
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Command Handler which is responsible for loading any existing Aggregate
The actual logic is delegated to an instance of a
STATE from the underlying EventStore
(see deciderBasedCommandHandler(ConfigurableEventStore, AggregateType, Class, AggregateIdResolver, AggregateIdResolver, AggregateSnapshotRepository, Class, Decider))
and coordinate persisting any changes to the Aggregate, in the form of EVENT's, to the EventStore as part of an active UnitOfWork (if one exists)The actual logic is delegated to an instance of a
Decider-
Method Summary
Modifier and TypeMethodDescriptionstatic <CONFIG extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration,ID, COMMAND, EVENT, ERROR, STATE>
CommandHandler<COMMAND,EVENT, ERROR> deciderBasedCommandHandler(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<CONFIG> eventStore, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, Class<ID> aggregateIdType, AggregateIdResolver<COMMAND, ID> aggregateIdFromCommandResolver, AggregateIdResolver<EVENT, ID> aggregateIdFromEventResolver, AggregateSnapshotRepository aggregateSnapshotRepository, Class<STATE> stateType, Decider<COMMAND, EVENT, ERROR, STATE> decider) Create an instance of aCommandHandlerthat is responsible for loading any existing AggregateSTATEfrom the underlyingEventStoreand coordinate persisting any changes to the Aggregate, in the form ofEVENT's, to theEventStoreas part of an activeUnitOfWork(if one exists)
The actual logic is delegated to an instance of aDeciderTheexecutemethod is responsible for handling aCOMMAND, which can either result in anERRORor a list ofEVENT's.
Note: This method is calleddecidein the decider pattern
Idempotent handling of aCOMMANDwill result in an empty list ofEVENT's
-
Method Details
-
handle
Theexecutemethod is responsible for handling aCOMMAND, which can either result in anERRORor a list ofEVENT's.
Note: This method is calleddecidein the decider pattern
Idempotent handling of aCOMMANDwill result in an empty list ofEVENT's- Parameters:
cmd- the command to handle- Returns:
- either an
ERRORor a list ofEVENT's.
Idempotent handling of aCOMMANDwill result in an empty list ofEVENT's
-
deciderBasedCommandHandler
static <CONFIG extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration,ID, CommandHandler<COMMAND,COMMAND, EVENT, ERROR, STATE> EVENT, deciderBasedCommandHandlerERROR> (dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<CONFIG> eventStore, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, Class<ID> aggregateIdType, AggregateIdResolver<COMMAND, ID> aggregateIdFromCommandResolver, AggregateIdResolver<EVENT, ID> aggregateIdFromEventResolver, AggregateSnapshotRepository aggregateSnapshotRepository, Class<STATE> stateType, Decider<COMMAND, EVENT, ERROR, STATE> decider) Create an instance of aCommandHandlerthat is responsible for loading any existing AggregateSTATEfrom the underlyingEventStoreand coordinate persisting any changes to the Aggregate, in the form ofEVENT's, to theEventStoreas part of an activeUnitOfWork(if one exists)
The actual logic is delegated to an instance of aDecider- Type Parameters:
CONFIG- The type ofAggregateEventStreamConfigurationthat theEventStoreprovided supportsID- the type of aggregate id that is associated with theAggregateTypeCOMMAND- the type ofCOMMANDthat theDeciderinstance supportsEVENT- the type ofEVENTthat theDeciderinstance supportsERROR- the type ofERRORthat theDeciderinstance supportsSTATE- the type of AggregateSTATEthat theDeciderinstance supports- Parameters:
eventStore- theEventStorethat provides persistence support for aggregate eventsaggregateType- the aggregate type that this command handler can supportCOMMAND's related to and which theDecidersupportsEVENT's related toaggregateIdType- the type of aggregate id that is associated with theAggregateTypeaggregateIdFromCommandResolver- resolver that can resolve theaggregate-idfrom aCOMMANDobject instanceaggregateIdFromEventResolver- resolver that can resolve theaggregate-idfrom anEVENTobject instanceaggregateSnapshotRepository- optionalAggregateSnapshotRepositoryfor storing snapshots of the aggregateSTATEfor faster loadingstateType- The type of aggregateSTATEthat theDeciderinstance works withdecider- theDeciderinstance responsible for Aggregate logic- Returns:
- a
CommandHandlerthat is responsible for loading any existing AggregateSTATEfrom the underlyingEventStoreand coordinate persisting any changes to the Aggregate, in the form ofEVENT's, to theEventStoreas part of an activeUnitOfWork(if one exists)
The actual logic is delegated to an instance of aDecider
-