Class UnitOfWorkTimeoutInterceptor
java.lang.Object
org.axonframework.messaging.timeout.UnitOfWorkTimeoutInterceptor
- All Implemented Interfaces:
MessageHandlerInterceptor<Message<?>>
public class UnitOfWorkTimeoutInterceptor
extends Object
implements MessageHandlerInterceptor<Message<?>>
Message handler interceptor that sets a timeout on the processing of the current
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.
- Since:
- 4.11.0
- Author:
- Mitchell Herrijgers
-
Constructor Summary
ConstructorsConstructorDescriptionUnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval) Creates a newUnitOfWorkTimeoutInterceptorfor the givencomponentNamewith the giventimeout,warningThresholdandwarningInterval.UnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval, ScheduledExecutorService executorService, org.slf4j.Logger logger) Creates a newUnitOfWorkTimeoutInterceptorfor the givencomponentNamewith the giventimeout,warningThresholdandwarningInterval. -
Method Summary
Modifier and TypeMethodDescriptionhandle(UnitOfWork<? extends Message<?>> unitOfWork, InterceptorChain interceptorChain) Invoked before a Message is handled by a designatedMessageHandler.
-
Constructor Details
-
UnitOfWorkTimeoutInterceptor
public UnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval) Creates a newUnitOfWorkTimeoutInterceptorfor the givencomponentNamewith the giventimeout,warningThresholdandwarningInterval. The warnings and timeout will be scheduled on theAxonTaskJanitor.INSTANCE. If you want to use a differentScheduledExecutorServiceorLoggerto log on, use the otherUnitOfWorkTimeoutInterceptor(String, int, int, int, ScheduledExecutorService, Logger).- Parameters:
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 thantimeoutwill disable warnings.warningInterval- The interval in milliseconds between warnings.
-
UnitOfWorkTimeoutInterceptor
public UnitOfWorkTimeoutInterceptor(String componentName, int timeout, int warningThreshold, int warningInterval, ScheduledExecutorService executorService, org.slf4j.Logger logger) Creates a newUnitOfWorkTimeoutInterceptorfor the givencomponentNamewith the giventimeout,warningThresholdandwarningInterval. The warnings and timeout will be scheduled on the providedexecutorService.- Parameters:
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 thantimeoutwill 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 errors
-
-
Method Details
-
handle
public Object handle(@Nonnull UnitOfWork<? extends Message<?>> unitOfWork, @Nonnull InterceptorChain interceptorChain) throws Exception Description copied from interface:MessageHandlerInterceptorInvoked before a Message is handled by a designatedMessageHandler. The interceptor is responsible for the continuation of the handling process by invoking theInterceptorChain.proceed()method on the giveninterceptorChain. The givenunitOfWorkcontains 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.- Specified by:
handlein interfaceMessageHandlerInterceptor<Message<?>>- Parameters:
unitOfWork- The UnitOfWork that is processing the messageinterceptorChain- The interceptor chain that allows this interceptor to proceed the dispatch process- Returns:
- the result of the message handler. May have been modified by interceptors.
- Throws:
Exception- any exception that occurs while handling the message
-