public class UnitOfWorkTimeoutInterceptor extends Object implements MessageHandlerInterceptor<Message<?>>
UnitOfWork
. If the timeout
is reached, the thread is interrupted and the transaction will be rolled back automatically.
Note: Due to interceptor ordering, this interceptor may not be the first in the chain. We are unable to work around
this, and as such the timeout measuring starts from the moment this interceptor is invoked, and ends measuring when
the commit of the UnitOfWork
is completed.
Constructor and Description |
---|
UnitOfWorkTimeoutInterceptor(String componentName,
int timeout,
int warningThreshold,
int warningInterval)
Creates a new
UnitOfWorkTimeoutInterceptor for the given componentName with the given
timeout , warningThreshold and warningInterval . |
UnitOfWorkTimeoutInterceptor(String componentName,
int timeout,
int warningThreshold,
int warningInterval,
ScheduledExecutorService executorService,
org.slf4j.Logger logger)
Creates a new
UnitOfWorkTimeoutInterceptor for the given componentName with the given
timeout , warningThreshold and warningInterval . |
Modifier and Type | Method and Description |
---|---|
Object |
handle(UnitOfWork<? extends Message<?>> unitOfWork,
InterceptorChain interceptorChain)
Invoked before a Message is handled by a designated
MessageHandler . |
public UnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval)
UnitOfWorkTimeoutInterceptor
for the given componentName
with the given
timeout
, warningThreshold
and warningInterval
. The warnings and timeout will be scheduled
on the AxonTaskJanitor.INSTANCE
. If you want to use a different ScheduledExecutorService
or
Logger
to log on, use the other
UnitOfWorkTimeoutInterceptor(String, int, int, int, ScheduledExecutorService, Logger)
.componentName
- The name of the component to be included in the loggingtimeout
- The timeout in millisecondswarningThreshold
- The threshold in milliseconds after which a warning is logged. Setting this to a value
higher than timeout
will disable warnings.warningInterval
- The interval in milliseconds between warnings.public UnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval, ScheduledExecutorService executorService, org.slf4j.Logger logger)
UnitOfWorkTimeoutInterceptor
for the given componentName
with the given
timeout
, warningThreshold
and warningInterval
. The warnings and timeout will be scheduled
on the provided executorService
.componentName
- The name of the component to be included in the loggingtimeout
- The timeout in millisecondswarningThreshold
- The threshold in milliseconds after which a warning is logged. Setting this to a value
higher than timeout
will disable warnings.warningInterval
- The interval in milliseconds between warnings.executorService
- The executor service to schedule the timeout and warningslogger
- The logger to log warnings and errorspublic Object handle(@Nonnull UnitOfWork<? extends Message<?>> unitOfWork, @Nonnull InterceptorChain interceptorChain) throws Exception
MessageHandlerInterceptor
MessageHandler
.
The interceptor is responsible for the continuation of the handling process by invoking the InterceptorChain.proceed()
method on the given interceptorChain
.
The given unitOfWork
contains contextual information. Any information gathered by interceptors
may be attached to the unitOfWork.
Interceptors are highly recommended not to change the type of the message handling result, as the dispatching
component might expect a result of a specific type.handle
in interface MessageHandlerInterceptor<Message<?>>
unitOfWork
- The UnitOfWork that is processing the messageinterceptorChain
- The interceptor chain that allows this interceptor to proceed the dispatch processException
- any exception that occurs while handling the messageCopyright © 2010–2025. All rights reserved.