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 aLockRegistry
and fixed (shared) lock key.LockRequestHandlerAdvice
(LockRegistry lockRegistry, Function<Message<?>, Object> lockKeyFunction) Construct an advice instance based on aLockRegistry
and function for the lock key against request message.LockRequestHandlerAdvice
(LockRegistry lockRegistry, Expression lockKeyExpression) Construct an advice instance based on aLockRegistry
and SpEL expression for the lock key against request message. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
doInvoke
(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler
.protected void
onInit()
Subclasses may implement this for initialization logic.void
setDiscardChannel
(MessageChannel discardChannel) Set a channel where to send a message for whichlockKey
is evaluated tonull
.void
setWaitLockDuration
(Duration waitLockDuration) Optional duration for aLock.tryLock(long, TimeUnit)
API.void
setWaitLockDurationExpression
(Expression waitLockDurationExpression) The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)
duration against request message.void
setWaitLockDurationExpressionString
(String waitLockDurationExpression) The SpEL expression to evaluate aLock.tryLock(long, TimeUnit)
duration against request message.void
setWaitLockDurationFunction
(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
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, 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 aLockRegistry
and fixed (shared) lock key.- Parameters:
lockRegistry
- theLockRegistry
to use.lockKey
- the static (shared) lock key for all the calls.
-
LockRequestHandlerAdvice
Construct an advice instance based on aLockRegistry
and SpEL expression for the lock key against request message.- Parameters:
lockRegistry
- theLockRegistry
to use.lockKeyExpression
- the SpEL expression to evaluate a lock key against request message.
-
LockRequestHandlerAdvice
public LockRequestHandlerAdvice(LockRegistry lockRegistry, Function<Message<?>, Object> lockKeyFunction) Construct an advice instance based on aLockRegistry
and function for the lock key against request message.- Parameters:
lockRegistry
- theLockRegistry
to use.lockKeyFunction
- the function to evaluate a lock key against 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 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 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 whichlockKey
is 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:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
doInvoke
protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdvice
Subclasses implement this method to apply behavior to theMessageHandler
.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvoke
in 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
.
-