Class SimpleSourcingHandler<I,E>

java.lang.Object
org.axonframework.eventsourcing.handler.SimpleSourcingHandler<I,E>
Type Parameters:
I - the type of the entity identifier
E - the type of the entity
All Implemented Interfaces:
DescribableComponent, SourcingHandler<I,E>

@Internal public class SimpleSourcingHandler<I,E> extends Object implements SourcingHandler<I,E>
A simple implementation of SourcingHandler that reconstructs an entity by sourcing events directly from an EventStore.

This implementation retrieves all events for a given identifier according to the CriteriaResolver and applies them in order to construct or evolve the entity using the provided InitializingEntityEvolver.

This is a straightforward, non-snapshotting sourcing strategy and is suitable when all events must be applied sequentially from the event store.

Since:
5.1.0
Author:
John Hendrikx
  • Constructor Details

    • SimpleSourcingHandler

      public SimpleSourcingHandler(EventStore eventStore, CriteriaResolver<I> criteriaResolver)
      Creates a new SimpleSourcingHandler.
      Parameters:
      eventStore - the EventStore from which events are sourced, cannot be null
      criteriaResolver - the resolver to use to create the EventCriteria for sourcing, cannot be null
      Throws:
      NullPointerException - when any argument is null
  • Method Details

    • source

      public CompletableFuture<E> source(I identifier, InitializingEntityEvolver<I,E> evolver, ProcessingContext pc)
      Description copied from interface: SourcingHandler
      Sources the entity identified by the given identifier.

      The InitializingEntityEvolver is used to either create the entity (if it does not exist) or evolve it through the events retrieved from the underlying event stream.

      This method returns a CompletableFuture that completes when the entity has been fully reconstructed or evolved to its latest state.

      Specified by:
      source in interface SourcingHandler<I,E>
      Parameters:
      identifier - the identifier of the entity to source, cannot be null
      evolver - the InitializingEntityEvolver used to initialize and evolve the entity, cannot be null
      pc - the ProcessingContext associated with this sourcing operation, cannot be null
      Returns:
      a CompletableFuture that completes with the sourced entity, never null
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.