Interface SagaRepository<T>

All Known Implementing Classes:
AnnotatedSagaRepository, LockingSagaRepository

public interface SagaRepository<T>
Interface towards the storage mechanism of Saga instances. Saga Repositories can find sagas either through the values they have been associated with (see AssociationValue) or via their unique identifier.

Every operation takes the ProcessingContext it is invoked in. Axon Framework 4 resolved the ambient unit of work from a thread local instead; Axon Framework 5 has no such global, so the context is passed explicitly. A repository never creates a context: it is created by the event processor and handed down through the component that invokes the Saga.

Since:
3.0
Author:
Allard Buijze
  • Method Details

    • find

      Set<String> find(AssociationValue associationValue, ProcessingContext context)
      Find saga instances of the given type that have been associated with the given associationValue.

      Parameters:
      associationValue - The value that the returned Sagas must be associated with
      context - the ProcessingContext this lookup is part of
      Returns:
      A Set containing the found Saga instances. If none are found, an empty Set is returned. Will never return null.
    • load

      @Nullable Saga<T> load(String sagaIdentifier, ProcessingContext context)
      Loads a known Saga instance by its unique identifier. Due to the concurrent nature of Sagas, it is not unlikely for a Saga to have ceased to exist after it has been found based on associations. Therefore, a repository should return null in case a Saga doesn't exists, as opposed to throwing an exception.
      Parameters:
      sagaIdentifier - The unique identifier of the Saga to load
      context - the ProcessingContext the loaded Saga is managed in
      Returns:
      The Saga instance, or null if no such saga exists
    • createInstance

      Saga<T> createInstance(String sagaIdentifier, Supplier<T> factoryMethod, ProcessingContext context)
      Creates a new Saga instance. The returned Saga will delegate event handling to the instance supplied by the given factoryMethod.
      Parameters:
      sagaIdentifier - the identifier to use for the new saga instance
      factoryMethod - Used to create a new Saga delegate
      context - the ProcessingContext the new Saga is managed in
      Returns:
      a new Saga instance wrapping an instance of type T