public class StatefulRetryOperationsInterceptor extends Object implements org.aopalliance.intercept.MethodInterceptor
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.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
.Constructor and Description |
---|
StatefulRetryOperationsInterceptor() |
Modifier and Type | Method and Description |
---|---|
Object |
invoke(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 |
setNewItemIdentifier(NewMethodArgumentsIdentifier newMethodArgumentsIdentifier)
Public setter for the
NewMethodArgumentsIdentifier . |
void |
setRecoverer(MethodInvocationRecoverer<?> recoverer)
Public setter for the
MethodInvocationRecoverer to use if the retry is
exhausted. |
void |
setRetryOperations(RetryOperations retryTemplate) |
public void setRetryOperations(RetryOperations retryTemplate)
public void setRecoverer(MethodInvocationRecoverer<?> recoverer)
MethodInvocationRecoverer
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.recoverer
- the MethodInvocationRecoverer
to setpublic void setKeyGenerator(MethodArgumentsKeyGenerator keyGenerator)
public void setNewItemIdentifier(NewMethodArgumentsIdentifier newMethodArgumentsIdentifier)
NewMethodArgumentsIdentifier
. Only set this if the
arguments to the intercepted method can be inspected to find out if they have never
been processed before.newMethodArgumentsIdentifier
- the NewMethodArgumentsIdentifier
to setpublic Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws Throwable
MethodInvocationRecoverer
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).invoke
in interface org.aopalliance.intercept.MethodInterceptor
Throwable
MethodInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)
,
MethodInvocationRecoverer.recover(Object[], Throwable)
Copyright © 2014 SpringSource. All rights reserved.