Interface SagaLifecycle

All Known Implementing Classes:
AnnotatedSaga

public interface SagaLifecycle
Component giving a Saga's event handler methods access to lifecycle operations, such as managing AssociationValues and ending the Saga.

A SageLifecycle is a ProcessingContext-scoped replacement for the Axon Framework 4 SagaLifecycle, which exposed the very same operations as static methods resolved through a ThreadLocal. A SagaLifecycle instance is only reachable through the ProcessingContext that is active while a specific Saga instance handles a specific event.

To access the SageLifecycle, declare a SagaLifecycle-typed parameter on a @SagaEventHandler method:


 @SagaEventHandler(associationProperty = "orderId")
 public void on(OrderShippedEvent event, SagaLifecycle lifecycle) {
     lifecycle.associateWith("shipmentId", event.getShipmentId());
     lifecycle.end();
 }
 
Since:
3.0.0
Author:
Allard Buijze, Steven van Beelen
  • Field Details

  • Method Details

    • forContext

      static SagaLifecycle forContext(ProcessingContext context)
      Retrieves the SagaLifecycle registered for the given context.
      Parameters:
      context - the ProcessingContext to retrieve the active SagaLifecycle for
      Returns:
      the SagaLifecycle active for the given context
      Throws:
      IllegalStateException - if no SagaLifecycle is registered for the given context
    • associateWith

      default void associateWith(String associationKey, String associationValue)
      Registers an AssociationValue with the current 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

      default void associateWith(String associationKey, Number associationValue)
      Registers an AssociationValue with the current 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

      void associateWith(AssociationValue associationValue)
      Registers the given associationValue with the current 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

      default void removeAssociationWith(String associationKey, String associationValue)
      Removes the given association from the current 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

      default void removeAssociationWith(String associationKey, Number associationValue)
      Removes the given association from the current 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
    • removeAssociationWith

      void removeAssociationWith(AssociationValue associationValue)
      Removes the given associationValue from the current 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 the given value, nothing happens.
      Parameters:
      associationValue - the association value to remove from this saga
    • end

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

      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 an 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