Class ContextAwareScope
Scope that also carries the ProcessingContext of the invocation it is started for.
Axon Framework 4 had two pieces of ambient state while a handler ran: the current Scope and the current
unit of work. Code reached from that handler, such as a DeadlineManager, used the first to learn which
Saga it was called from and the second to defer its work to the unit of work's prepare-commit phase. Axon
Framework 5 hands the ProcessingContext to the handler explicitly and keeps no ambient unit of work. A
ContextAwareScope brings both back for exactly the duration of one synchronous handler invocation, so
that such code keeps working without a ProcessingContext parameter of its own.
Marked Internal because it only exists to bridge Axon Framework 4 APIs in this module. Axon Framework 5
components receive their ProcessingContext as a parameter and should never look it up through a
Scope.
- Since:
- 5.4.0
- Author:
- Mateusz Nowak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ProcessingContext> Returns theProcessingContextcarried by thecurrent scope.abstract ProcessingContextReturns theProcessingContextof the invocation this scope was started for.Methods inherited from class org.axonframework.messaging.Scope
describeCurrentScope, describeScope, endScope, executeWithResult, getCurrentScope, startScope
-
Constructor Details
-
ContextAwareScope
public ContextAwareScope()
-
-
Method Details
-
processingContext
Returns theProcessingContextof the invocation this scope was started for.- Returns:
- the
ProcessingContextof the invocation this scope was started for
-
currentProcessingContext
Returns theProcessingContextcarried by thecurrent scope.Unlike
Scope.getCurrentScope(), this never throws: it returns an emptyOptionalwhen no scope is active, and also when the current scope is not aContextAwareScope.- Returns:
- the
ProcessingContextof the current scope, or an emptyOptionalif there is none
-