Package org.axonframework.modelling.saga
Class AnnotatedSaga<T>
java.lang.Object
org.axonframework.messaging.Scope
org.axonframework.modelling.saga.SagaLifecycle
org.axonframework.modelling.saga.AnnotatedSaga<T>
- All Implemented Interfaces:
EventMessageHandler,MessageHandler<EventMessage<?>>,Saga<T>
Implementation of the
interface that allows for a POJO instance with annotated message handlers to act
as a Saga. The POJO instance can access static methods on SagaLifecycle as long as it is access via the
execute(Consumer) or invoke(Function) methods.- Since:
- 3.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotatedSaga(String sagaId, Set<AssociationValue> associationValues, T annotatedSaga, SagaModel<T> metaModel, MessageHandlerInterceptorMemberChain<T> chainedInterceptor) Creates an AnnotatedSaga instance to wrap the givenannotatedSaga, identifier with the givensagaIdand associated with the givenassociationValues. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancanHandle(EventMessage<?> event) Indicates whether this handler can handle the given messageprotected voiddoAssociateWith(AssociationValue property) Registers a AssociationValue with the given saga.protected voiddoEnd()Marks the saga as ended.protected voiddoRemoveAssociation(AssociationValue property) Removes the given association from this Saga.voidExecute the giveninvocationagainst the root object of this Saga instance.SagaLifecycleinstance method to retrieve theAssociationValuesof the currently active Saga.Retrieve aStringdenoting the identifier of this Saga.final Objecthandle(EventMessage<?> event) Process the given event.<R> RExecute the giveninvocationagainst the root object of this Saga instance.booleanisActive()Indicates whether or not this saga is active.root()Returns the (annotated) Saga instance.protected Stringtype()Retrieve aStringdenoting the type of this Saga.Methods inherited from class org.axonframework.modelling.saga.SagaLifecycle
associateWith, associateWith, associateWith, associationValues, describeScope, end, execute, getInstance, removeAssociationWith, removeAssociationWithMethods inherited from class org.axonframework.messaging.Scope
describeCurrentScope, endScope, executeWithResult, getCurrentScope, startScopeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.MessageHandler
canHandleType, getTargetTypeMethods inherited from interface org.axonframework.modelling.saga.Saga
prepareReset, prepareReset, supportsReset
-
Constructor Details
-
AnnotatedSaga
public AnnotatedSaga(String sagaId, Set<AssociationValue> associationValues, T annotatedSaga, SagaModel<T> metaModel, MessageHandlerInterceptorMemberChain<T> chainedInterceptor) Creates an AnnotatedSaga instance to wrap the givenannotatedSaga, identifier with the givensagaIdand associated with the givenassociationValues. ThemetaModelprovides the description of the structure of the Saga.- Parameters:
sagaId- The identifier of this Saga instanceassociationValues- The current associations of this SagaannotatedSaga- The object instance representing the SagametaModel- The model describing Saga structurechainedInterceptor- The interceptor to be used for this Saga
-
-
Method Details
-
getSagaIdentifier
Description copied from class:SagaLifecycleRetrieve aStringdenoting the identifier of this Saga.- Specified by:
getSagaIdentifierin interfaceSaga<T>- Specified by:
getSagaIdentifierin classSagaLifecycle- Returns:
- a
Stringdenoting the identifier of this Saga
-
getAssociationValues
Description copied from class:SagaLifecycleSagaLifecycleinstance method to retrieve theAssociationValuesof the currently active Saga.- Specified by:
getAssociationValuesin interfaceSaga<T>- Specified by:
getAssociationValuesin classSagaLifecycle- Returns:
- The
AssociationValuesof the current saga.
-
invoke
Description copied from interface:SagaExecute the giveninvocationagainst the root object of this Saga instance. -
execute
Description copied from interface:SagaExecute the giveninvocationagainst the root object of this Saga instance. -
canHandle
Description copied from interface:MessageHandlerIndicates whether this handler can handle the given message- Specified by:
canHandlein interfaceMessageHandler<T>- Parameters:
event- The message to verify- Returns:
trueif this handler can handle the message, otherwisefalse
-
handle
Description copied from interface:EventMessageHandlerProcess the given event. The implementation may decide to process or skip the given event. It is highly unrecommended to throw any exception during the event handling process.- Specified by:
handlein interfaceEventMessageHandler- Specified by:
handlein interfaceMessageHandler<T>- Parameters:
event- the event to handle- Returns:
- the result of the event handler invocation. Is generally ignored
-
isActive
public boolean isActive()Description copied from interface:SagaIndicates whether or not this saga is active. A Saga is active when its life cycle has not been ended. -
root
Returns the (annotated) Saga instance. This method should not be used to modify the Saga's state, as it doesn't allow the instance to access the static methods onSagaLifecycle.- Returns:
- the Saga instance
-
doEnd
protected void doEnd()Marks the saga as ended. Ended saga's may be cleaned up by the repository when they are committed.- Specified by:
doEndin classSagaLifecycle
-
doAssociateWith
Registers a AssociationValue with the given saga. When the saga is committed, it can be found using the registered property.- Specified by:
doAssociateWithin classSagaLifecycle- Parameters:
property- The value to associate this saga with.
-
type
Description copied from class:SagaLifecycleRetrieve aStringdenoting the type of this Saga.- Specified by:
typein classSagaLifecycle- Returns:
- a
Stringdenoting the type of this Saga
-
doRemoveAssociation
Removes the given association from this Saga. When the saga is committed, it can no longer be found using the given association. If the given property wasn't registered with the saga, nothing happens.- Specified by:
doRemoveAssociationin classSagaLifecycle- Parameters:
property- the association value to remove from the saga.
-