Type Parameters:
COMMAND - The type of Commands that the Handler.handle(Object, Object) can process
EVENT - The type of Events that can be returned by Handler.handle(Object, Object) and applied in the StateEvolver.applyEvent(Object, Object)
ERROR - The type of Error that can be returned by the Handler.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.

@FunctionalInterface public interface CommandHandler<COMMAND,EVENT,ERROR>
Command Handler which is responsible for loading any existing Aggregate 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 Type
    Method
    Description
    static <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 a CommandHandler that is responsible for loading any existing Aggregate STATE from the underlying EventStore 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
    The execute method is responsible for handling a COMMAND, which can either result in an ERROR or a list of EVENT's.
    Note: This method is called decide in the decider pattern
    Idempotent handling of a COMMAND will result in an empty list of EVENT's
  • Method Details

    • handle

      The execute method is responsible for handling a COMMAND, which can either result in an ERROR or a list of EVENT's.
      Note: This method is called decide in the decider pattern
      Idempotent handling of a COMMAND will result in an empty list of EVENT's
      Parameters:
      cmd - the command to handle
      Returns:
      either an ERROR or a list of EVENT's.
      Idempotent handling of a COMMAND will result in an empty list of EVENT's
    • deciderBasedCommandHandler

      static <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 a CommandHandler that is responsible for loading any existing Aggregate STATE from the underlying EventStore 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
      Type Parameters:
      CONFIG - The type of AggregateEventStreamConfiguration that the EventStore provided supports
      ID - the type of aggregate id that is associated with the AggregateType
      COMMAND - the type of COMMAND that the Decider instance supports
      EVENT - the type of EVENT that the Decider instance supports
      ERROR - the type of ERROR that the Decider instance supports
      STATE - the type of Aggregate STATE that the Decider instance supports
      Parameters:
      eventStore - the EventStore that provides persistence support for aggregate events
      aggregateType - the aggregate type that this command handler can support COMMAND's related to and which the Decider supports EVENT's related to
      aggregateIdType - the type of aggregate id that is associated with the AggregateType
      aggregateIdFromCommandResolver - resolver that can resolve the aggregate-id from a COMMAND object instance
      aggregateIdFromEventResolver - resolver that can resolve the aggregate-id from an EVENT object instance
      aggregateSnapshotRepository - optional AggregateSnapshotRepository for storing snapshots of the aggregate STATE for faster loading
      stateType - The type of aggregate STATE that the Decider instance works with
      decider - the Decider instance responsible for Aggregate logic
      Returns:
      a CommandHandler that is responsible for loading any existing Aggregate STATE from the underlying EventStore 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