Class AbstractSagaManager<T>

java.lang.Object
org.axonframework.modelling.saga.AbstractSagaManager<T>
All Implemented Interfaces:
EventHandlerInvoker, ScopeAware
Direct Known Subclasses:
AnnotatedSagaManager

public abstract class AbstractSagaManager<T> extends Object implements EventHandlerInvoker, ScopeAware
Abstract implementation of the SagaManager interface that provides basic functionality required by most SagaManager implementations. Provides support for Saga lifecycle management and asynchronous handling of events.
Since:
0.7
Author:
Allard Buijze
  • Constructor Details

  • Method Details

    • handle

      public void handle(@Nonnull EventMessage<?> event, @Nonnull Segment segment) throws Exception
      Description copied from interface: EventHandlerInvoker
      Handle the given message for the given segment.

      Callers are recommended to invoke EventHandlerInvoker.canHandle(EventMessage, Segment) prior to invocation, but aren't required to do so. Implementations must ensure to take the given segment into account when processing messages.

      Specified by:
      handle in interface EventHandlerInvoker
      Parameters:
      event - The message to handle
      segment - The segment for which to handle the message
      Throws:
      Exception - when an exception occurs while handling the message
    • createSagaIdentifier

      protected String createSagaIdentifier(Segment segment)
      Creates a Saga identifier that will cause a Saga instance to be considered part of the given segment.
      Parameters:
      segment - The segment the identifier must match with
      Returns:
      an identifier for a newly created Saga
      Implementation Requirements:
      This implementation will repeatedly generate identifier using the IdentifierFactory, until one is returned that matches the given segment. See matchesSegment(Segment, String).
    • matchesSegment

      protected boolean matchesSegment(Segment segment, String sagaId)
      Checks whether the given sagaId matches with the given segment.

      For any complete set of segments, exactly one segment matches with any value.

      Parameters:
      segment - The segment to validate the identifier for
      sagaId - The identifier to test
      Returns:
      true if the identifier matches the segment, otherwise false
      Implementation Requirements:
      This implementation uses the Segment.matches(Object) to match against the Saga identifier
    • getSagaCreationPolicy

      protected abstract SagaInitializationPolicy getSagaCreationPolicy(EventMessage<?> event)
      Returns the Saga Initialization Policy for a Saga of the given sagaType and event. This policy provides the conditions to create new Saga instance, as well as the initial association of that saga.
      Parameters:
      event - The Event that is being dispatched to Saga instances
      Returns:
      the initialization policy for the Saga
    • extractAssociationValues

      protected abstract Set<AssociationValue> extractAssociationValues(EventMessage<?> event)
      Extracts the AssociationValues from the given event as relevant for a Saga of given sagaType. A single event may be associated with multiple values.
      Parameters:
      event - The event containing the association information
      Returns:
      the AssociationValues indicating which Sagas should handle given event
    • getSagaType

      public Class<T> getSagaType()
      Returns the class of Saga managed by this SagaManager
      Returns:
      the managed saga type
    • supportsReset

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

      public void performReset()
      Description copied from interface: EventHandlerInvoker
      Performs any activities that are required to reset the state managed by handlers assigned to this invoker.
      Specified by:
      performReset in interface EventHandlerInvoker
    • performReset

      public void performReset(Object resetContext)
      Description copied from interface: EventHandlerInvoker
      Performs any activities that are required to reset the state managed by handlers assigned to this invoker.
      Specified by:
      performReset in interface EventHandlerInvoker
      Parameters:
      resetContext - a R used to support the reset operation
    • send

      public void send(Message<?> message, ScopeDescriptor scopeDescription) throws Exception
      Description copied from interface: ScopeAware
      Send a Message to a Scope which is described by the given scopeDescription.
      Specified by:
      send in interface ScopeAware
      Parameters:
      message - a Message to be send to a Scope
      scopeDescription - a D extending ScopeDescriptor, describing the Scope to send the given message to
      Throws:
      Exception - if sending the message failed. Might occur if the message handling process throws an exception
    • canResolve

      public boolean canResolve(ScopeDescriptor scopeDescription)
      Description copied from interface: ScopeAware
      Check whether this implementation can resolve a Scope object based on the provided scopeDescription. Will return true in case it should be able to resolve the Scope and false if it cannot.
      Specified by:
      canResolve in interface ScopeAware
      Parameters:
      scopeDescription - a ScopeDescriptor describing the Scope to be resolved
      Returns:
      true in case it should be able to resolve the Scope and false if it cannot