Interface Saga<T>

All Superinterfaces:
EventMessageHandler, MessageHandler<EventMessage<?>>
All Known Implementing Classes:
AnnotatedSaga

public interface Saga<T> extends EventMessageHandler
Interface describing an implementation of a Saga. Sagas are instances that handle events and may possibly produce new commands or have other side effects. Typically, Sagas are used to manage long running business transactions.

Multiple instances of a single type of Saga may exist. In that case, each Saga will be managing a different transaction. Sagas need to be associated with concepts in order to receive specific events. These associations are managed through AssociationValues. For example, to associate a saga with an Order with ID 1234, this saga needs an association value with key "orderId" and value "1234".

Since:
0.7
Author:
Allard Buijze
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(Consumer<T> invocation)
    Execute the given invocation against the root object of this Saga instance.
    Returns a view on the Association Values for this saga instance.
    Returns the unique identifier of this saga.
    <R> R
    invoke(Function<T,R> invocation)
    Execute the given invocation against the root object of this Saga instance.
    boolean
    Indicates whether or not this saga is active.
    default void
    Performs any activities that are required to reset the state managed by handlers assigned to this handler.
    default void
    prepareReset(Object resetContext)
    Performs any activities that are required to reset the state managed by handlers assigned to this handler.
    default boolean
    Indicates whether the handlers managed by this invoker support a reset.

    Methods inherited from interface org.axonframework.eventhandling.EventMessageHandler

    handle

    Methods inherited from interface org.axonframework.messaging.MessageHandler

    canHandle, canHandleType, getTargetType
  • Method Details

    • getSagaIdentifier

      String getSagaIdentifier()
      Returns the unique identifier of this saga.
      Returns:
      the unique identifier of this saga
    • getAssociationValues

      AssociationValues getAssociationValues()
      Returns a view on the Association Values for this saga instance. The returned instance is mutable.
      Returns:
      a view on the Association Values for this saga instance
    • invoke

      <R> R invoke(Function<T,R> invocation)
      Execute the given invocation against the root object of this Saga instance.
      Type Parameters:
      R - The type of return value expected
      Parameters:
      invocation - the function to invoke. The root object of the Saga is input to the function, the result is the result of the execution.
      Returns:
      The result of the invocation on the Saga.
    • execute

      void execute(Consumer<T> invocation)
      Execute the given invocation against the root object of this Saga instance.
      Parameters:
      invocation - the function to invoke. The root object of the Saga is input to the function.
    • isActive

      boolean isActive()
      Indicates whether or not this saga is active. A Saga is active when its life cycle has not been ended.
      Returns:
      true if this saga is active, false otherwise.
    • supportsReset

      default boolean supportsReset()
      Description copied from interface: EventMessageHandler
      Indicates whether the handlers managed by this invoker support a reset.
      Specified by:
      supportsReset in interface EventMessageHandler
      Returns:
      true if a reset is supported, otherwise false
    • prepareReset

      default void prepareReset()
      Description copied from interface: EventMessageHandler
      Performs any activities that are required to reset the state managed by handlers assigned to this handler.
      Specified by:
      prepareReset in interface EventMessageHandler
    • prepareReset

      default void prepareReset(Object resetContext)
      Description copied from interface: EventMessageHandler
      Performs any activities that are required to reset the state managed by handlers assigned to this handler.
      Specified by:
      prepareReset in interface EventMessageHandler
      Parameters:
      resetContext - a R used to support the reset operation