Class LockRequestHandlerAdvice
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
org.springframework.integration.handler.advice.LockRequestHandlerAdvice
- All Implemented Interfaces:
Advice,Interceptor,MethodInterceptor,Aware,BeanFactoryAware,BeanNameAware,InitializingBean,ApplicationContextAware,ComponentSourceAware,ExpressionCapable,NamedComponent
The
AbstractRequestHandlerAdvice to ensure exclusive access to the
AbstractReplyProducingMessageHandler.RequestHandler#handleRequestMessage(Message) calls
based on the lockKey from message.
If lockKey for the message is null, the no locking around the call.
However, if setDiscardChannel(MessageChannel) is provided, such a message will be sent there instead.
- Since:
- 6.5
- Author:
- Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException -
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
ConstructorsConstructorDescriptionLockRequestHandlerAdvice(LockRegistry<?> lockRegistry, Object lockKey) Construct an advice instance based on aLockRegistryand fixed (shared) lock key.LockRequestHandlerAdvice(LockRegistry<?> lockRegistry, Function<Message<?>, Object> lockKeyFunction) Construct an advice instance based on aLockRegistryand function for the lock key against request message.LockRequestHandlerAdvice(LockRegistry<?> lockRegistry, Expression lockKeyExpression) Construct an advice instance based on aLockRegistryand SpEL expression for the lock key against request message. -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable ObjectdoInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler.protected voidonInit()Subclasses may implement this for initialization logic.voidsetDiscardChannel(@Nullable MessageChannel discardChannel) Set a channel where to send a message for whichlockKeyis evaluated tonull.voidsetWaitLockDuration(Duration waitLockDuration) Optional duration for aLock.tryLock(long, TimeUnit)API.voidsetWaitLockDurationExpression(Expression waitLockDurationExpression) The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)duration against a request message.voidsetWaitLockDurationExpressionString(String waitLockDurationExpression) The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)duration against a request message.voidsetWaitLockDurationFunction(Function<Message<?>, Duration> waitLockDurationFunction) The function to evaluate aLock.tryLock(long, TimeUnit)duration against request message.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
getComponentType, invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessaryMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
LockRequestHandlerAdvice
Construct an advice instance based on aLockRegistryand fixed (shared) lock key.- Parameters:
lockRegistry- theLockRegistryto use.lockKey- the static (shared) lock key for all the calls.
-
LockRequestHandlerAdvice
Construct an advice instance based on aLockRegistryand SpEL expression for the lock key against request message.- Parameters:
lockRegistry- theLockRegistryto use.lockKeyExpression- the SpEL expression to evaluate a lock key against a request message.
-
LockRequestHandlerAdvice
public LockRequestHandlerAdvice(LockRegistry<?> lockRegistry, Function<Message<?>, Object> lockKeyFunction) Construct an advice instance based on aLockRegistryand function for the lock key against request message.- Parameters:
lockRegistry- theLockRegistryto use.lockKeyFunction- the function to evaluate a lock key against a request message.
-
-
Method Details
-
setWaitLockDuration
Optional duration for aLock.tryLock(long, TimeUnit)API. Otherwise,Lock.lockInterruptibly()is used.- Parameters:
waitLockDuration- the duration forLock.tryLock(long, TimeUnit).
-
setWaitLockDurationExpression
The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)duration against a request message. Can be evaluated toDuration,long(with meaning as milliseconds), or to string in the duration ISO-8601 format.- Parameters:
waitLockDurationExpression- SpEL expression for duration.
-
setWaitLockDurationExpressionString
The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)duration against a request message. Can be evaluated toDuration,long(with meaning as milliseconds), or to string in the duration ISO-8601 format.- Parameters:
waitLockDurationExpression- SpEL expression for duration.
-
setWaitLockDurationFunction
The function to evaluate aLock.tryLock(long, TimeUnit)duration against request message.- Parameters:
waitLockDurationFunction- the function for duration.
-
setDiscardChannel
Set a channel where to send a message for whichlockKeyis evaluated tonull. If this is not set andlockKey == null, no locking around the call.- Parameters:
discardChannel- the channel to send messages without a key.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
doInvoke
protected @Nullable Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdviceSubclasses implement this method to apply behavior to theMessageHandler.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvokein classAbstractRequestHandlerAdvice- Parameters:
callback- Subclasses invoke the execute() method on this interface to invoke the handler method.target- The target handler.message- The message that will be sent to the handler.- Returns:
- the result after invoking the
MessageHandler.
-