Class ResourceOverridingProcessingContext<R>
- Type Parameters:
R- The type of the resource this resource-overridingProcessingContextoverrides.
- All Implemented Interfaces:
ApplicationContext,Context,ProcessingContext,ProcessingLifecycle
ProcessingContext implementation overriding a single resource from the wrapping ProcessingContext.
Should be used to instantiate a new ProcessingContext for which only a single resource should be adjusted
compared to its delegate.
- Since:
- 5.0.0
- Author:
- Allard Buijze
-
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 -
Constructor Summary
ConstructorsConstructorDescriptionResourceOverridingProcessingContext(ProcessingContext delegate, Context.ResourceKey<R> key, R resource) Constructs a resource-overridingProcessingContextusing the provided parameters. -
Method Summary
Modifier and TypeMethodDescription<C> CReturns the component declared under the giventypeor throws aComponentNotFoundExceptionif it does not exist.<C> CReturns the component declared under the giventypeandnameor throws aComponentNotFoundExceptionif it does not exist.<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.booleancontainsResource(Context.ResourceKey<?> key) Indicates whether a resource has been registered with the givenkeyin this Context.doFinally(Consumer<ProcessingContext> action) Registers the providedactionto be executedon errorof andwhen completingthisProcessingLifecycle.<T> TgetResource(Context.ResourceKey<T> key) Returns the resource currently registered under the givenkey, ornullif no resource is present.booleanbooleanbooleanisError()booleanon(ProcessingLifecycle.Phase phase, Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in the givenphase.onAfterCommit(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in theafter commit phase.onCommit(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in thecommit phase.Registers the providedactionto be executed when thisProcessingLifecycleencounters an error during the action of anyProcessingLifecycle.Phase.onInvocation(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in theinvocation phase.onPostInvocation(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in thepost invocation phase.onPreInvocation(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in thepre-invocation phase.onPrepareCommit(Function<ProcessingContext, CompletableFuture<?>> action) Registers the providedactionto be executed in theprepare commit phase.<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.Retrieves all resources contained within the currentContext.runOn(ProcessingLifecycle.Phase phase, Consumer<ProcessingContext> action) Registers the providedactionto be executed in the givenphase.runOnAfterCommit(Consumer<ProcessingContext> action) Registers the providedactionto be executed in theafter commit phase.runOnCommit(Consumer<ProcessingContext> action) Registers the providedactionto be executed in thecommit phase.runOnInvocation(Consumer<ProcessingContext> action) Registers the providedactionto be executed in theinvocation phase.runOnPostInvocation(Consumer<ProcessingContext> action) Registers the providedactionto be executed in thepost invocation phase.runOnPreInvocation(Consumer<ProcessingContext> action) Registers the providedactionto be executed in thepre-invocation phase.runOnPrepareCommit(Consumer<ProcessingContext> action) Registers the providedactionto be executed in theprepare commit phase.<T> TupdateResource(Context.ResourceKey<T> key, UnaryOperator<T> resourceUpdater) Update the resource with givenkeyusing the givenresourceUpdaterto describe the update.whenComplete(Consumer<ProcessingContext> action) Registers the providedactionto be executed when thisProcessingLifecyclecompletes all registered actions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.unitofwork.ProcessingContext
withResource
-
Constructor Details
-
ResourceOverridingProcessingContext
public ResourceOverridingProcessingContext(@Nonnull ProcessingContext delegate, @Nonnull Context.ResourceKey<R> key, R resource) Constructs a resource-overridingProcessingContextusing the provided parameters.- Parameters:
delegate- TheProcessingContextto only override the givenkeyfor.key- TheContext.ResourceKeyto override in thedelegateProcessingContext.resource- The resource of typeRthat's overridden with the givenkey.
-
-
Method Details
-
isStarted
public boolean isStarted()Description copied from interface:ProcessingLifecycle- Specified by:
isStartedin interfaceProcessingLifecycle- Returns:
truewhen thisProcessingLifecycleis started,falseotherwise.
-
isError
public boolean isError()Description copied from interface:ProcessingLifecycleReturnstruewhen thisProcessingLifecycleis in error,falseotherwise.When
true, theregistered ErrorHandlerswill be invoked.- Specified by:
isErrorin interfaceProcessingLifecycle- Returns:
truewhen thisProcessingLifecycleis in error,falseotherwise.
-
isCommitted
public boolean isCommitted()Description copied from interface:ProcessingLifecycle- Specified by:
isCommittedin interfaceProcessingLifecycle- Returns:
truewhen thisProcessingLifecycleis committed,falseotherwise.
-
isCompleted
public boolean isCompleted()Description copied from interface:ProcessingLifecycleReturnstruewhen thisProcessingLifecycleis completed,falseotherwise.Note that this
ProcessingLifecycleis marked as completed for a successful and failed completion.- Specified by:
isCompletedin interfaceProcessingLifecycle- Returns:
truewhen thisProcessingLifecycleis completed,falseotherwise.
-
on
public ProcessingLifecycle on(@Nonnull ProcessingLifecycle.Phase phase, @Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in the givenphase. Uses theCompletableFuturereturned by theactionto compose actions and to carry the action's result.Use this operation when the return value of the
actionis important.- Specified by:
onin interfaceProcessingLifecycle- Parameters:
phase- TheProcessingLifecycle.Phaseto execute the givenactionin.action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOn
public ProcessingLifecycle runOn(@Nonnull ProcessingLifecycle.Phase phase, @Nonnull Consumer<ProcessingContext> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in the givenphase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnin interfaceProcessingLifecycle- Parameters:
phase- TheProcessingLifecycle.Phaseto execute the givenactionin.action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onPreInvocation
public ProcessingLifecycle onPreInvocation(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thepre-invocation phase.Use this operation when the return value of the
actionis important.- Specified by:
onPreInvocationin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnPreInvocation
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thepre-invocation phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnPreInvocationin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onInvocation
public ProcessingLifecycle onInvocation(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theinvocation phase.Use this operation when the return value of the
actionis important.- Specified by:
onInvocationin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnInvocation
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theinvocation phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnInvocationin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onPostInvocation
public ProcessingLifecycle onPostInvocation(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thepost invocation phase.Use this operation when the return value of the
actionis important.- Specified by:
onPostInvocationin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnPostInvocation
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thepost invocation phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnPostInvocationin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onPrepareCommit
public ProcessingLifecycle onPrepareCommit(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theprepare commit phase.Use this operation when the return value of the
actionis important.- Specified by:
onPrepareCommitin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnPrepareCommit
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theprepare commit phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnPrepareCommitin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onCommit
public ProcessingLifecycle onCommit(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thecommit phase.Use this operation when the return value of the
actionis important.- Specified by:
onCommitin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnCommit
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in thecommit phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnCommitin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onAfterCommit
public ProcessingLifecycle onAfterCommit(@Nonnull Function<ProcessingContext, CompletableFuture<?>> action) Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theafter commit phase.Use this operation when the return value of the
actionis important.- Specified by:
onAfterCommitin interfaceProcessingLifecycle- Parameters:
action- TheFunctionthat's given the activeProcessingContextand returns aCompletableFuturefor chaining purposes and to carry the action's result.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
runOnAfterCommit
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed in theafter commit phase.Use this operation when there is no need for a return value of the registered
action.- Specified by:
runOnAfterCommitin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
onError
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed when thisProcessingLifecycleencounters an error during the action of anyProcessingLifecycle.Phase. This includes failures from actions registered throughProcessingLifecycle.whenComplete(Consumer).When the given
ErrorHandlersare invokedProcessingLifecycle.isError()andProcessingLifecycle.isCompleted()will returntrue.- Specified by:
onErrorin interfaceProcessingLifecycle- Parameters:
action- The error handler to execute when thisProcessingLifecycleencounters an error during phase execution.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
whenComplete
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executed when thisProcessingLifecyclecompletes all registered actions.- Specified by:
whenCompletein interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
doFinally
Description copied from interface:ProcessingLifecycleRegisters the providedactionto be executedon errorof andwhen completingthisProcessingLifecycle.Note that if the given
actionthrows an exception when completing thisProcessingLifecycleit will be invoked again as an onProcessingLifecycle.ErrorHandler.- Specified by:
doFinallyin interfaceProcessingLifecycle- Parameters:
action- AConsumerthat's given the activeProcessingContextto perform its action.- Returns:
- This
ProcessingLifecycleinstance for fluent interfacing.
-
containsResource
Description copied from interface:ContextIndicates whether a resource has been registered with the givenkeyin this Context.- Specified by:
containsResourcein interfaceContext- Parameters:
key- The key of the resource to check.- Returns:
trueif a resource is registered with thiskey, otherwisefalse.
-
getResource
Description copied from interface:ContextReturns the resource currently registered under the givenkey, ornullif no resource is present.- Specified by:
getResourcein interfaceContext- Type Parameters:
T- The type of resource registered under the givenkey.- Parameters:
key- The key to retrieve the resource for.- Returns:
- The resource currently registered under given
key, ornullif not present.
-
resources
Description copied from interface:ContextRetrieves all resources contained within the currentContext.Most of the time, none of the keys make any sense to the component that would retrieve them. Thus, this method is purely here for copying resources between
Contextinstances, not for retrieval. For that, there's theContext.getResource(ResourceKey)method. -
putResource
Description copied from interface:ProcessingContextRegister the givenresourceunder the givenkey.- Specified by:
putResourcein interfaceProcessingContext- 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
public <T> T updateResource(@Nonnull Context.ResourceKey<T> key, @Nonnull UnaryOperator<T> resourceUpdater) Description copied from interface:ProcessingContextUpdate 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.
- Specified by:
updateResourcein interfaceProcessingContext- 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.
-
computeResourceIfAbsent
public <T> T computeResourceIfAbsent(@Nonnull Context.ResourceKey<T> key, @Nonnull Supplier<T> resourceSupplier) Description copied from interface:ProcessingContextIf no resource is present for the givenkey, the givenresourceSupplieris used to supply the instance to register under thiskey.- Specified by:
computeResourceIfAbsentin interfaceProcessingContext- 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.
-
putResourceIfAbsent
Description copied from interface:ProcessingContextRegister the giveninstanceunder the givenkeyif no value is currently present.- Specified by:
putResourceIfAbsentin interfaceProcessingContext- 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.
-
removeResource
Description copied from interface:ProcessingContextRemoves the resource registered under givenkey.- Specified by:
removeResourcein interfaceProcessingContext- 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
Description copied from interface:ProcessingContextRemove the resource associated with givenkeyif the givenexpectedResourceis the currently associated value.- Specified by:
removeResourcein interfaceProcessingContext- 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.
-
component
Description copied from interface:ApplicationContextReturns the component declared under the giventypeor throws aComponentNotFoundExceptionif it does not exist.- Specified by:
componentin interfaceApplicationContext- Type Parameters:
C- The type of component.- Parameters:
type- The type of component, typically the interface the component implements.- Returns:
- The component registered for the given type.
-
component
Description copied from interface:ApplicationContextReturns the component declared under the giventypeandnameor throws aComponentNotFoundExceptionif it does not exist.- Specified by:
componentin interfaceApplicationContext- Type Parameters:
C- The type of component.- Parameters:
type- The type of component, typically the interface the component implements.name- The name of the component to retrieve. Usenullwhen there is no name or useApplicationContext.component(Class)instead.- Returns:
- The component registered for the given
typeandname.
-