Interface SagaStore<T>

Type Parameters:
T - The saga type
All Known Implementing Classes:
CachingSagaStore, InMemorySagaStore, JdbcSagaStore, JpaSagaStore, MongoSagaStore

public interface SagaStore<T>
Provides a mechanism to find, load update and delete sagas of type T from an underlying storage like a database.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Interface describing a Saga entry fetched from a SagaStore.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    deleteSaga(Class<? extends T> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues)
    Deletes a Saga with given sagaType and sagaIdentifier and all its associations.
    findSagas(Class<? extends T> sagaType, AssociationValue associationValue)
    Returns identifiers of saga instances of the given sagaType that have been associated with the given associationValue.
    void
    insertSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, Set<AssociationValue> associationValues)
    Adds a new Saga and its initial association values to the store.
    <S extends T>
    @Nullable SagaStore.Entry<S>
    loadSaga(Class<S> sagaType, String sagaIdentifier)
    Loads a known saga SagaStore.Entry instance with given sagaType and unique sagaIdentifier.
    void
    updateSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, AssociationValues associationValues)
    Updates a given Saga after its state was modified, applying the association values added and removed since it was last stored.
  • Method Details

    • findSagas

      Set<String> findSagas(Class<? extends T> sagaType, AssociationValue associationValue)
      Returns identifiers of saga instances of the given sagaType that have been associated with the given associationValue.
      Parameters:
      sagaType - The type of the returned sagas
      associationValue - The value that the returned sagas must be associated with
      Returns:
      A set of identifiers of sagas having the correct type and association value
    • loadSaga

      <S extends T> @Nullable SagaStore.Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier)
      Loads a known saga SagaStore.Entry instance with given sagaType and unique sagaIdentifier.

      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.

      Type Parameters:
      S - the specific saga type returned
      Parameters:
      sagaType - The type of the returned saga entry
      sagaIdentifier - The unique identifier of the returned saga entry
      Returns:
      The saga entry, or null if no such saga exists
    • deleteSaga

      void deleteSaga(Class<? extends T> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues)
      Deletes a Saga with given sagaType and sagaIdentifier and all its associations. For convenience all known association values are passed along as well, which has the advantage that the saga store is not required to keep an index of association value to saga identifier.
      Parameters:
      sagaType - The type of saga to delete
      sagaIdentifier - The identifier of the saga to delete
      associationValues - The known associations of the saga
    • insertSaga

      void insertSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, Set<AssociationValue> associationValues)
      Adds a new Saga and its initial association values to the store.
      Parameters:
      sagaType - The type of the Saga
      sagaIdentifier - The identifier of the Saga
      saga - The Saga instance
      associationValues - The initial association values of the Saga
    • updateSaga

      void updateSaga(Class<? extends T> sagaType, String sagaIdentifier, T saga, AssociationValues associationValues)
      Updates a given Saga after its state was modified, applying the association values added and removed since it was last stored.
      Parameters:
      sagaType - The type of the Saga
      sagaIdentifier - The identifier of the Saga
      saga - The Saga instance
      associationValues - The association values of the Saga, carrying the additions and removals to apply