Interface ProcessingContext
- All Superinterfaces:
ApplicationContext,Context,ProcessingLifecycle
- All Known Implementing Classes:
LegacyMessageSupportingContext,ResourceOverridingProcessingContext
Implementation of the
ProcessingLifecycle adding mutable resource management operations by
implementing Context.
It is recommended to construct a Context.ResourceKey instance when adding/updating/removing resources from the
ProcessingContext to allow cross-referral by sharing the key or personalization when the resource should be
private to a specific service.
- Since:
- 5.0.0
- Author:
- Allard Buijze, Gerard Klijs, Milan Savić, Mitchell Herrijgers, Sara Pellegrini, Steven van Beelen
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.messaging.core.Context
Context.ResourceKey<T>Nested classes/interfaces inherited from interface org.axonframework.messaging.core.unitofwork.ProcessingLifecycle
ProcessingLifecycle.DefaultPhases, ProcessingLifecycle.ErrorHandler, ProcessingLifecycle.Phase -
Method Summary
Modifier and TypeMethodDescription<T> TcomputeResourceIfAbsent(Context.ResourceKey<T> key, Supplier<T> resourceSupplier) If no resource is present for the givenkey, the givenresourceSupplieris used to supply the instance to register under thiskey.<T> TputResource(Context.ResourceKey<T> key, T resource) Register the givenresourceunder the givenkey.<T> TputResourceIfAbsent(Context.ResourceKey<T> key, T resource) Register the giveninstanceunder the givenkeyif no value is currently present.<T> TremoveResource(Context.ResourceKey<T> key) Removes the resource registered under givenkey.<T> booleanremoveResource(Context.ResourceKey<T> key, T expectedResource) Remove the resource associated with givenkeyif the givenexpectedResourceis the currently associated value.<T> TupdateResource(Context.ResourceKey<T> key, UnaryOperator<T> resourceUpdater) Update the resource with givenkeyusing the givenresourceUpdaterto describe the update.default <T> ProcessingContextwithResource(Context.ResourceKey<T> key, T resource) Methods inherited from interface org.axonframework.messaging.core.ApplicationContext
component, componentMethods inherited from interface org.axonframework.messaging.core.Context
containsResource, getResource, resourcesMethods inherited from interface org.axonframework.messaging.core.unitofwork.ProcessingLifecycle
doFinally, isCommitted, isCompleted, isError, isStarted, on, onAfterCommit, onCommit, onError, onInvocation, onPostInvocation, onPreInvocation, onPrepareCommit, runOn, runOnAfterCommit, runOnCommit, runOnInvocation, runOnPostInvocation, runOnPreInvocation, runOnPrepareCommit, whenComplete
-
Method Details
-
withResource
default <T> ProcessingContext withResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource) Constructs a newProcessingContext, branching off fromthisProcessingContext.The given
resourceas added to the branchedProcessingContextunder the givenkey.- Specified by:
withResourcein interfaceContext- Type Parameters:
T- The type of resource associated with thekey.- Parameters:
key- The key under which to register theresourcein the branchedProcessingContext.resource- The resource to register in the branchedProcessingContext.- Returns:
- A new
ProcessingContext, branched off fromthisProcessingContext.
-
putResource
Register the givenresourceunder the givenkey.- Type Parameters:
T- The type ofresourceto register under given @code.- Parameters:
key- The key under which to register theresource.resource- The resource to register.- Returns:
- The previously registered
resource, ornullif none was present.
-
updateResource
<T> T updateResource(@Nonnull Context.ResourceKey<T> key, @Nonnull UnaryOperator<T> resourceUpdater) Update the resource with givenkeyusing the givenresourceUpdaterto describe the update. If no resource is registered with the givenkey, theresourceUpdateris invoked withnull. Otherwise, the function is called with the currently registered resource under that key.The resource is replaced with the return value of the function, or removed when the function returns
null.If the function throws an exception, the exception is rethrown to the caller.
- Type Parameters:
T- The type of resource to update.- Parameters:
key- The key to update the resource for.resourceUpdater- The function performing the update itself.- Returns:
- The new value associated with the
key, ornullwhen removed.
-
putResourceIfAbsent
Register the giveninstanceunder the givenkeyif no value is currently present.- Type Parameters:
T- The type ofresourceto register under givenkey.- Parameters:
key- The key under which to register the resource.resource- The resource to register when nothing is present for the givenkey.- Returns:
- The resource previously associated with given
key.
-
computeResourceIfAbsent
<T> T computeResourceIfAbsent(@Nonnull Context.ResourceKey<T> key, @Nonnull Supplier<T> resourceSupplier) If no resource is present for the givenkey, the givenresourceSupplieris used to supply the instance to register under thiskey.- Type Parameters:
T- The type of resource registered under givenkey.- Parameters:
key- The key to register the resource for.resourceSupplier- The function to supply the resource to register.- Returns:
- The resource associated with the
key.
-
removeResource
Removes the resource registered under givenkey.- Type Parameters:
T- The type of resource associated with thekey.- Parameters:
key- The key to remove the registered resource for.- Returns:
- The value previously associated with the
key.
-
removeResource
Remove the resource associated with givenkeyif the givenexpectedResourceis the currently associated value.- Type Parameters:
T- The type of resource associated with thekey.- Parameters:
key- The key to remove the registered resource for.expectedResource- The expected resource to remove.- Returns:
trueif the resource has been removed, otherwisefalse.
-