Record Class UnitOfWorkConfiguration
java.lang.Object
java.lang.Record
org.axonframework.messaging.core.unitofwork.UnitOfWorkConfiguration
- Record Components:
workScheduler- TheExecutorfor processing unit of work actions.allowAsyncProcessing- Whether the unit of work should allow fully asynchronous processing.processingLifecycleEnhancers- The enhancers that are applied to the processing lifecycle for each created unit of work.lifecycleInterceptor- TheProcessingLifecycleInterceptorinvoked immediately around every action and handler dispatch executed by the unit of work, ornullwhen no interceptor is installed (the direct, zero-overhead path).
public record UnitOfWorkConfiguration(Executor workScheduler, boolean allowAsyncProcessing, List<Consumer<ProcessingLifecycle>> processingLifecycleEnhancers, @Nullable ProcessingLifecycleInterceptor lifecycleInterceptor)
extends Record
Configuration used for the
UnitOfWork creation in the UnitOfWorkFactory.
Defines the work scheduler used during unit of work processing, and allows registering possible enhancers for a unit of work's lifecycle.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak, John Hendrikx
-
Constructor Summary
ConstructorsConstructorDescriptionUnitOfWorkConfiguration(Executor workScheduler, boolean allowAsyncProcessing, List<Consumer<ProcessingLifecycle>> processingLifecycleEnhancers) Creates aUnitOfWorkConfigurationwithout aProcessingLifecycleInterceptor.UnitOfWorkConfiguration(Executor workScheduler, boolean allowAsyncProcessing, List<Consumer<ProcessingLifecycle>> processingLifecycleEnhancers, @Nullable ProcessingLifecycleInterceptor lifecycleInterceptor) Creates an instance of aUnitOfWorkConfigurationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaddLifecycleInterceptor(ProcessingLifecycleInterceptor lifecycleInterceptor) Creates a new configuration that chains the given interceptor after any already registeredinterceptor(composing viaProcessingLifecycleInterceptor.andThen(ProcessingLifecycleInterceptor)).booleanReturns the value of theallowAsyncProcessingrecord component.final booleanIndicates whether some other object is "equal to" this one.Creates a newUnitOfWorkConfigurationthat forces all handlers to be invoked by the same thread.final inthashCode()Returns a hash code value for this object.@Nullable ProcessingLifecycleInterceptorReturns the value of thelifecycleInterceptorrecord component.lifecycleInterceptor(ProcessingLifecycleInterceptor lifecycleInterceptor) Creates a new configuration that replaces the currentinterceptorwith the given one.Returns the value of theprocessingLifecycleEnhancersrecord component.Creates a new configuration including the specified enhancer.final StringtoString()Returns a string representation of this record class.Returns the value of theworkSchedulerrecord component.workScheduler(Executor workScheduler) Creates a new configuration with specified work scheduler.
-
Constructor Details
-
UnitOfWorkConfiguration
public UnitOfWorkConfiguration(Executor workScheduler, boolean allowAsyncProcessing, List<Consumer<ProcessingLifecycle>> processingLifecycleEnhancers) Creates aUnitOfWorkConfigurationwithout aProcessingLifecycleInterceptor. Retained for backward compatibility with callers constructing the configuration before theinterceptorcomponent was introduced.- Parameters:
workScheduler- theExecutorfor processing unit of work actionsallowAsyncProcessing- whether the unit of work should allow fully asynchronous processingprocessingLifecycleEnhancers- the enhancers applied to the processing lifecycle for each created unit of work
-
UnitOfWorkConfiguration
public UnitOfWorkConfiguration(Executor workScheduler, boolean allowAsyncProcessing, List<Consumer<ProcessingLifecycle>> processingLifecycleEnhancers, @Nullable ProcessingLifecycleInterceptor lifecycleInterceptor) Creates an instance of aUnitOfWorkConfigurationrecord class.- Parameters:
workScheduler- the value for theworkSchedulerrecord componentallowAsyncProcessing- the value for theallowAsyncProcessingrecord componentprocessingLifecycleEnhancers- the value for theprocessingLifecycleEnhancersrecord componentlifecycleInterceptor- the value for thelifecycleInterceptorrecord component
-
-
Method Details
-
forcedSameThreadInvocation
Creates a newUnitOfWorkConfigurationthat forces all handlers to be invoked by the same thread. The configuration uses a direct execution model where all tasks are run immediately on the calling thread, and the coordinating thread will wait for any asynchronous processing to complete.The
enhancersand theinterceptorare preserved, so lifecycle customization and state-bridging around framework-executed segments survive the switch to same-thread invocation.- Returns:
- A new modified
UnitOfWorkConfiguration.
-
workScheduler
Creates a new configuration with specified work scheduler.- Parameters:
workScheduler- TheExecutorfor processing actions.- Returns:
- A new modified
UnitOfWorkConfiguration.
-
registerProcessingLifecycleEnhancer
public UnitOfWorkConfiguration registerProcessingLifecycleEnhancer(Consumer<ProcessingLifecycle> enhancer) Creates a new configuration including the specified enhancer.- Parameters:
enhancer- The processing lifecycle enhancer to include.- Returns:
- A new modified
UnitOfWorkConfiguration.
-
lifecycleInterceptor
public UnitOfWorkConfiguration lifecycleInterceptor(ProcessingLifecycleInterceptor lifecycleInterceptor) Creates a new configuration that replaces the currentinterceptorwith the given one. To compose with an already registered interceptor instead of replacing it, useaddLifecycleInterceptor(ProcessingLifecycleInterceptor).- Parameters:
lifecycleInterceptor- TheProcessingLifecycleInterceptorto install.- Returns:
- A new modified
UnitOfWorkConfiguration.
-
addLifecycleInterceptor
public UnitOfWorkConfiguration addLifecycleInterceptor(ProcessingLifecycleInterceptor lifecycleInterceptor) Creates a new configuration that chains the given interceptor after any already registeredinterceptor(composing viaProcessingLifecycleInterceptor.andThen(ProcessingLifecycleInterceptor)). Chaining (rather than replacement) ensures multiple contributors never clobber each other, which is the common case when several framework modules each install their own interceptor. To replace the current interceptor instead, uselifecycleInterceptor(ProcessingLifecycleInterceptor).- Parameters:
lifecycleInterceptor- TheProcessingLifecycleInterceptorto chain in.- Returns:
- A new modified
UnitOfWorkConfiguration.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
workScheduler
Returns the value of theworkSchedulerrecord component.- Returns:
- the value of the
workSchedulerrecord component
-
allowAsyncProcessing
public boolean allowAsyncProcessing()Returns the value of theallowAsyncProcessingrecord component.- Returns:
- the value of the
allowAsyncProcessingrecord component
-
processingLifecycleEnhancers
Returns the value of theprocessingLifecycleEnhancersrecord component.- Returns:
- the value of the
processingLifecycleEnhancersrecord component
-
lifecycleInterceptor
Returns the value of thelifecycleInterceptorrecord component.- Returns:
- the value of the
lifecycleInterceptorrecord component
-