Class StatefulRetryOperationsInterceptor
java.lang.Object
org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor
- All Implemented Interfaces:
org.aopalliance.aop.Advice
,org.aopalliance.intercept.Interceptor
,org.aopalliance.intercept.MethodInterceptor
public class StatefulRetryOperationsInterceptor
extends Object
implements org.aopalliance.intercept.MethodInterceptor
A
MethodInterceptor
that can be used to automatically retry calls to a method
on a service if it fails. The argument to the service method is treated as an item to
be remembered in case the call fails. So the retry operation is stateful, and the item
that failed is tracked by its unique key (via MethodArgumentsKeyGenerator
)
until the retry is exhausted, at which point the MethodInvocationRecoverer
is
called.
The main use case for this is where the service is transactional, via a transaction
interceptor on the interceptor chain. In this case the retry (and recovery on
exhausted) always happens in a new transaction.
The injected RetryOperations
is used to control the number of retries. By
default it will retry a fixed number of times, according to the defaults in
RetryTemplate
.- Author:
- Dave Syer, Gary Russell
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioninvoke
(org.aopalliance.intercept.MethodInvocation invocation) Wrap the method invocation in a stateful retry with the policy and other helpers provided.void
setKeyGenerator
(MethodArgumentsKeyGenerator keyGenerator) void
void
setNewItemIdentifier
(NewMethodArgumentsIdentifier newMethodArgumentsIdentifier) Public setter for theNewMethodArgumentsIdentifier
.void
setRecoverer
(MethodInvocationRecoverer<?> recoverer) Public setter for theMethodInvocationRecoverer
to use if the retry is exhausted.void
setRetryOperations
(RetryOperations retryTemplate) void
setRollbackClassifier
(Classifier<? super Throwable, Boolean> rollbackClassifier) Rollback classifier for the retry state.void
setUseRawKey
(boolean useRawKey) Set to true to use the raw key generated by the key generator.
-
Constructor Details
-
StatefulRetryOperationsInterceptor
public StatefulRetryOperationsInterceptor()
-
-
Method Details
-
setRetryOperations
-
setRecoverer
Public setter for theMethodInvocationRecoverer
to use if the retry is exhausted. The recoverer should be able to return an object of the same type as the target object because its return value will be used to return to the caller in the case of a recovery.- Parameters:
recoverer
- theMethodInvocationRecoverer
to set
-
setRollbackClassifier
Rollback classifier for the retry state. Default to null (meaning rollback for all).- Parameters:
rollbackClassifier
- the rollbackClassifier to set
-
setKeyGenerator
-
setLabel
-
setNewItemIdentifier
Public setter for theNewMethodArgumentsIdentifier
. Only set this if the arguments to the intercepted method can be inspected to find out if they have never been processed before.- Parameters:
newMethodArgumentsIdentifier
- theNewMethodArgumentsIdentifier
to set
-
setUseRawKey
public void setUseRawKey(boolean useRawKey) Set to true to use the raw key generated by the key generator. Should only be set to true for cases where the key is guaranteed to be unique in all cases. When false, a compound key is used, including invocation metadata. Default: false.- Parameters:
useRawKey
- the useRawKey to set.
-
invoke
Wrap the method invocation in a stateful retry with the policy and other helpers provided. If there is a failure the exception will generally be re-thrown. The only time it is not re-thrown is when retry is exhausted and the recovery path is taken (though theMethodInvocationRecoverer
provided if there is one). In that case the value returned from the method invocation will be the value returned by the recoverer (so the return type for that should be the same as the intercepted method).- Specified by:
invoke
in interfaceorg.aopalliance.intercept.MethodInterceptor
- Throws:
Throwable
- See Also:
-
MethodInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)
MethodInvocationRecoverer.recover(Object[], Throwable)
-