Class SagaLifecycle

java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.saga.SagaLifecycle
Direct Known Subclasses:
AnnotatedSaga

public abstract class SagaLifecycle extends Scope
Abstract base class of a component that models a saga's life cycle.
  • Constructor Details

    • SagaLifecycle

      public SagaLifecycle()
  • Method Details

    • associateWith

      public static void associateWith(String associationKey, String associationValue)
      Registers a AssociationValue with the currently active saga. When the saga is committed, it can be found using the registered property. If the saga already has the given association, nothing happens.
      Parameters:
      associationKey - The key of the association value to associate this saga with.
      associationValue - The value of the association value to associate this saga with.
    • associateWith

      public static void associateWith(String associationKey, Number associationValue)
      Registers a AssociationValue with the currently active saga. When the saga is committed, it can be found using the registered property. The number value will be converted to a string. If the saga already has the given association, nothing happens.
      Parameters:
      associationKey - The key of the association value to associate this saga with.
      associationValue - The value of the association value to associate this saga with.
    • associateWith

      public static void associateWith(AssociationValue associationValue)
      Registers a AssociationValue with the currently active saga. When the saga is committed, it can be found using the registered property. If the saga already has the given association, nothing happens.
      Parameters:
      associationValue - The association to associate this saga with.
    • removeAssociationWith

      public static void removeAssociationWith(String associationKey, String associationValue)
      Removes the given association from the currently active Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with given values, nothing happens.
      Parameters:
      associationKey - The key of the association value to remove from this saga.
      associationValue - The value of the association value to remove from this saga.
    • removeAssociationWith

      public static void removeAssociationWith(String associationKey, Number associationValue)
      Removes the given association from the currently active Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with given values, nothing happens. The number value will be converted to a string.
      Parameters:
      associationKey - The key of the association value to remove from this saga.
      associationValue - The value of the association value to remove from this saga.
    • end

      public static void end()
      Marks the saga as ended. Ended saga's may be cleaned up by the repository when they are committed.
    • associationValues

      public static Set<AssociationValue> associationValues()
      Retrieves the AssociationValues that have been associated with the current Saga so far. This includes the uncommitted ones, so adding or removing a
      invalid @link
      {@link @link
      AssociationValue} through associateWith(AssociationValue) or any other method will have an immediate effect.
      Returns:
      The AssociationValues that have been associated with the Saga so far
    • doEnd

      protected abstract void doEnd()
      SagaLifecycle instance method to mark the current saga as ended.
    • doRemoveAssociation

      protected abstract void doRemoveAssociation(AssociationValue associationValue)
      SagaLifecycle instance method to remove the given associationValue. If the current saga is not associated with given value, this should do nothing.
      Parameters:
      associationValue - the association value to remove
    • doAssociateWith

      protected abstract void doAssociateWith(AssociationValue associationValue)
      SagaLifecycle instance method to register the given associationValue. If the current saga is already associated with given value, this should do nothing.
      Parameters:
      associationValue - the association value to add
    • getAssociationValues

      protected abstract AssociationValues getAssociationValues()
      SagaLifecycle instance method to retrieve the AssociationValues of the currently active Saga.
      Returns:
      The AssociationValues of the current saga.
    • getInstance

      protected static SagaLifecycle getInstance()
      Get the current SagaLifecycle instance for the current thread. If none exists an IllegalStateException is thrown.
      Returns:
      the thread's current SagaLifecycle
    • execute

      protected void execute(Runnable task)
      SagaLifecycle instance method to execute given task in the context of this SagaLifeCycle. This updates the thread's current saga lifecycle before executing the task. If a lifecycle is already registered with the current thread that one will be temporarily replaced with this lifecycle until the task completes.
      Parameters:
      task - the task to execute
    • type

      protected abstract String type()
      Retrieve a String denoting the type of this Saga.
      Returns:
      a String denoting the type of this Saga
    • getSagaIdentifier

      protected abstract String getSagaIdentifier()
      Retrieve a String denoting the identifier of this Saga.
      Returns:
      a String denoting the identifier of this Saga
    • describeScope

      public ScopeDescriptor describeScope()
      Description copied from class: Scope
      Provide a description of this Scope.
      Specified by:
      describeScope in class Scope
      Returns:
      a ScopeDescriptor describing this Scope