Class LockingSagaRepository<T>

java.lang.Object
org.axonframework.modelling.saga.repository.LockingSagaRepository<T>
All Implemented Interfaces:
SagaRepository<T>
Direct Known Subclasses:
AnnotatedSagaRepository

public abstract class LockingSagaRepository<T> extends Object implements SagaRepository<T>
Abstract implementation of a saga repository that locks access to a saga while the saga is being operated on.
Since:
3.0
Author:
Rene de Waele
  • Constructor Details

  • Method Details

    • load

      public Saga<T> load(String sagaIdentifier)
      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.

      This implementation locks access to sagas with the given sagaIdentifier and releases the lock in the clean-up phase of the current UnitOfWork.

      Specified by:
      load in interface SagaRepository<T>
      Parameters:
      sagaIdentifier - The unique identifier of the Saga to load
      Returns:
      The Saga instance, or null if no such saga exists
    • createInstance

      public Saga<T> createInstance(String sagaIdentifier, Supplier<T> factoryMethod)
      Creates a new Saga instance. The returned Saga will delegate event handling to the instance supplied by the given factoryMethod.

      This implementation locks access to sagas with the given sagaIdentifier and releases the lock in the clean-up phase of the current UnitOfWork.

      Specified by:
      createInstance in interface SagaRepository<T>
      Parameters:
      sagaIdentifier - the identifier to use for the new saga instance
      factoryMethod - Used to create a new Saga delegate
      Returns:
      a new Saga instance wrapping an instance of type T
    • doLoad

      protected abstract Saga<T> doLoad(String sagaIdentifier)
      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
      Returns:
      The Saga instance, or null if no such saga exists
    • doCreateInstance

      protected abstract Saga<T> doCreateInstance(String sagaIdentifier, Supplier<T> factoryMethod)
      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
      Returns:
      a new Saga instance wrapping an instance of type T