javadoc
This commit is contained in:
@@ -64,7 +64,7 @@ public class BackToBackPatternClassifier<C, T> implements Classifier<C, T> {
|
||||
* Java Object. The object provided must have precisely one public method
|
||||
* that either has the <code>@Classifier</code> annotation or accepts a single argument
|
||||
* and outputs a String. This will be used to create an input classifier for
|
||||
* the router component. <br/>
|
||||
* the router component.
|
||||
*
|
||||
* @param delegate the delegate object used to create a router classifier
|
||||
*/
|
||||
|
||||
@@ -50,7 +50,8 @@ public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boo
|
||||
* subclasses. The mapped value for these exceptions will be the one
|
||||
* provided (which will be the opposite of the default).
|
||||
*
|
||||
* @param value
|
||||
* @param exceptionClasses the exceptions to classify among
|
||||
* @param value the value to classify
|
||||
*/
|
||||
public BinaryExceptionClassifier(Collection<Class<? extends Throwable>> exceptionClasses, boolean value) {
|
||||
this(!value);
|
||||
@@ -66,6 +67,8 @@ public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boo
|
||||
/**
|
||||
* Create a binary exception classifier with the default value false and
|
||||
* value mapping true for the provided classes and their subclasses.
|
||||
*
|
||||
* @param exceptionClasses the exception types to throw
|
||||
*/
|
||||
public BinaryExceptionClassifier(Collection<Class<? extends Throwable>> exceptionClasses) {
|
||||
this(exceptionClasses, true);
|
||||
@@ -74,8 +77,7 @@ public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boo
|
||||
/**
|
||||
* Create a binary exception classifier using the given classification map
|
||||
* and a default classification of false.
|
||||
*
|
||||
* @param typeMap
|
||||
* @param typeMap the map of types
|
||||
*/
|
||||
public BinaryExceptionClassifier(Map<Class<? extends Throwable>, Boolean> typeMap) {
|
||||
this(typeMap, false);
|
||||
@@ -85,7 +87,8 @@ public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boo
|
||||
* Create a binary exception classifier using the given classification map
|
||||
* and a default classification of false.
|
||||
*
|
||||
* @param typeMap
|
||||
* @param defaultValue the default value to use
|
||||
* @param typeMap the map of types to classify
|
||||
*/
|
||||
public BinaryExceptionClassifier(Map<Class<? extends Throwable>, Boolean> typeMap, boolean defaultValue) {
|
||||
super(typeMap, defaultValue);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ClassifierAdapter<C, T> implements Classifier<C, T> {
|
||||
* Create a new {@link Classifier} from the delegate provided. Use the
|
||||
* constructor as an alternative to the {@link #setDelegate(Object)} method.
|
||||
*
|
||||
* @param delegate
|
||||
* @param delegate the delegate
|
||||
*/
|
||||
public ClassifierAdapter(Object delegate) {
|
||||
setDelegate(delegate);
|
||||
@@ -53,7 +53,7 @@ public class ClassifierAdapter<C, T> implements Classifier<C, T> {
|
||||
* constructor as an alternative to the {@link #setDelegate(Classifier)}
|
||||
* method.
|
||||
*
|
||||
* @param delegate
|
||||
* @param delegate the classifier to delegate to
|
||||
*/
|
||||
public ClassifierAdapter(Classifier<C, T> delegate) {
|
||||
classifier = delegate;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ClassifierSupport<C, T> implements Classifier<C, T> {
|
||||
final private T defaultValue;
|
||||
|
||||
/**
|
||||
* @param defaultValue
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
public ClassifierSupport(T defaultValue) {
|
||||
super();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PatternMatchingClassifier<T> implements Classifier<String, T> {
|
||||
* Create a classifier from the provided map. The keys are patterns, using
|
||||
* '?' as a single character and '*' as multi-character wildcard.
|
||||
*
|
||||
* @param values
|
||||
* @param values the values to use in the {@link PatternMatcher}
|
||||
*/
|
||||
public PatternMatchingClassifier(Map<String, T> values) {
|
||||
super();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class SubclassClassifier<T, C> implements Classifier<T, C> {
|
||||
/**
|
||||
* Create a {@link SubclassClassifier} with supplied default value.
|
||||
*
|
||||
* @param defaultValue
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
public SubclassClassifier(C defaultValue) {
|
||||
this(new HashMap<Class<? extends T>, C>(), defaultValue);
|
||||
@@ -62,7 +62,8 @@ public class SubclassClassifier<T, C> implements Classifier<T, C> {
|
||||
/**
|
||||
* Create a {@link SubclassClassifier} with supplied default value.
|
||||
*
|
||||
* @param defaultValue
|
||||
* @param defaultValue the default value
|
||||
* @param typeMap the map of types
|
||||
*/
|
||||
public SubclassClassifier(Map<Class<? extends T>, C> typeMap, C defaultValue) {
|
||||
super();
|
||||
@@ -95,6 +96,8 @@ public class SubclassClassifier<T, C> implements Classifier<T, C> {
|
||||
* Return the value from the type map whose key is the class of the given
|
||||
* Throwable, or its nearest ancestor if a subclass.
|
||||
*
|
||||
* @return C the classified value
|
||||
* @param classifiable the classifiable thing
|
||||
*/
|
||||
public C classify(T classifiable) {
|
||||
|
||||
@@ -124,6 +127,8 @@ public class SubclassClassifier<T, C> implements Classifier<T, C> {
|
||||
|
||||
/**
|
||||
* Return the default value supplied in the constructor (default false).
|
||||
*
|
||||
* @return C the default value
|
||||
*/
|
||||
final public C getDefault() {
|
||||
return defaultValue;
|
||||
|
||||
@@ -41,6 +41,7 @@ public class AnnotationMethodResolver implements MethodResolver {
|
||||
|
||||
/**
|
||||
* Create a MethodResolver for the specified Method-level annotation type
|
||||
* @param annotationType the type of the annotation
|
||||
*/
|
||||
public AnnotationMethodResolver(Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for create MethodInvoker instances.
|
||||
* Utility methods to create {@link MethodInvoker} instances.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Artem Bilan
|
||||
@@ -190,6 +190,8 @@ public class MethodInvokerUtils {
|
||||
*
|
||||
* @param target an object to search for an appropriate method
|
||||
* @return a MethodInvoker that calls a method on the delegate
|
||||
* @param <T> the t
|
||||
* @param <C> the C
|
||||
*/
|
||||
public static <C, T> MethodInvoker getMethodInvokerForSingleArgument(Object target) {
|
||||
final AtomicReference<Method> methodHolder = new AtomicReference<Method>();
|
||||
|
||||
@@ -26,9 +26,8 @@ public interface RecoveryCallback<T> {
|
||||
|
||||
/**
|
||||
* @param context the current retry context
|
||||
* @return an Object that can be used to replace the callback result that
|
||||
* failed
|
||||
* @throws Exception
|
||||
* @return an Object that can be used to replace the callback result that failed
|
||||
* @throws Exception when something goes wrong
|
||||
*/
|
||||
T recover(RetryContext context) throws Exception;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.springframework.retry;
|
||||
* Callback interface for an operation that can be retried using a
|
||||
* {@link RetryOperations}.
|
||||
*
|
||||
* @param T the type of object returned by the callback
|
||||
* @param E the type of exception it declares may be thrown
|
||||
* @param <T> the type of object returned by the callback
|
||||
* @param <E> the type of exception it declares may be thrown
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Dave Syer
|
||||
@@ -34,7 +34,7 @@ public interface RetryCallback<T, E extends Throwable> {
|
||||
* semantics when an operation is retried.
|
||||
* @param context the current retry context.
|
||||
* @return the result of the successful operation.
|
||||
* @throws Throwable of type E if processing fails
|
||||
* @throws E of type E if processing fails
|
||||
*/
|
||||
T doWithRetry(RetryContext context) throws E;
|
||||
T doWithRetry(RetryContext context) throws E;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ public interface RetryListener {
|
||||
* {@link RetryOperations}. The whole retry can be vetoed by returning
|
||||
* false from this method, in which case a {@link TerminatedRetryException}
|
||||
* will be thrown.
|
||||
*
|
||||
*
|
||||
* @param <T> the type of object returned by the callback
|
||||
* @param <E> the type of exception it declares may be thrown
|
||||
* @param context the current {@link RetryContext}.
|
||||
* @param callback the current {@link RetryCallback}.
|
||||
* @return true if the retry should proceed.
|
||||
@@ -48,6 +50,8 @@ public interface RetryListener {
|
||||
* @param context the current {@link RetryContext}.
|
||||
* @param callback the current {@link RetryCallback}.
|
||||
* @param throwable the last exception that was thrown by the callback.
|
||||
* @param <E> the exception type
|
||||
* @param <T> the return value
|
||||
*/
|
||||
<T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable);
|
||||
|
||||
@@ -57,6 +61,8 @@ public interface RetryListener {
|
||||
* @param context the current {@link RetryContext}.
|
||||
* @param callback the current {@link RetryCallback}.
|
||||
* @param throwable the last exception that was thrown by the callback.
|
||||
* @param <T> the return value
|
||||
* @param <E> the exception to throw
|
||||
*/
|
||||
<T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable);
|
||||
}
|
||||
|
||||
@@ -33,9 +33,12 @@ public interface RetryOperations {
|
||||
*
|
||||
* @return the value returned by the {@link RetryCallback} upon successful
|
||||
* invocation.
|
||||
* @throws Exception any {@link Exception} raised by the
|
||||
* @throws E any {@link Exception} raised by the
|
||||
* {@link RetryCallback} upon unsuccessful retry.
|
||||
* @throws Throwable
|
||||
* @throws E the exception thrown
|
||||
* @param <T> the return value
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param <E> the exception to throw
|
||||
*/
|
||||
<T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback) throws E;
|
||||
|
||||
@@ -46,7 +49,11 @@ public interface RetryOperations {
|
||||
*
|
||||
* @return the value returned by the {@link RetryCallback} upon successful
|
||||
* invocation, and that returned by the {@link RecoveryCallback} otherwise.
|
||||
* @throws Exception any {@link Exception} raised by the
|
||||
* @throws E any {@link Exception} raised by the
|
||||
* @param <T> the type to return
|
||||
* @param <E> the type of the exception
|
||||
* @param recoveryCallback the {@link RecoveryCallback}
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* {@link RecoveryCallback} upon unsuccessful retry.
|
||||
*/
|
||||
<T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback) throws E;
|
||||
@@ -58,16 +65,19 @@ public interface RetryOperations {
|
||||
* the state is required to be able to identify the previous attempt, if
|
||||
* there is one - hence the state is required. Normal patterns would see
|
||||
* this method being used inside a transaction, where the callback might
|
||||
* invalidate the transaction if it fails.<br/><br/>
|
||||
* invalidate the transaction if it fails.
|
||||
*
|
||||
* See implementations for configuration details.
|
||||
*
|
||||
*
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param retryState the {@link RetryState}
|
||||
* @return the value returned by the {@link RetryCallback} upon successful
|
||||
* invocation, and that returned by the {@link RecoveryCallback} otherwise.
|
||||
* @throws Exception any {@link Exception} raised by the
|
||||
* {@link RecoveryCallback}.
|
||||
* @throws E any {@link Exception} raised by the {@link RecoveryCallback}.
|
||||
* @throws ExhaustedRetryException if the last attempt for this state has
|
||||
* already been reached
|
||||
* @param <T> the type of the return value
|
||||
* @param <E> the type of the exception to return
|
||||
*/
|
||||
<T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RetryState retryState) throws E, ExhaustedRetryException;
|
||||
|
||||
@@ -76,13 +86,15 @@ public interface RetryOperations {
|
||||
* {@link RetryCallback} with a fallback on exhausted retry to the
|
||||
* {@link RecoveryCallback} and a target object for the retry attempt
|
||||
* identified by the {@link DefaultRetryState}.
|
||||
*
|
||||
* @param recoveryCallback the {@link RecoveryCallback}
|
||||
* @param retryState the {@link RetryState}
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @see #execute(RetryCallback, RetryState)
|
||||
*
|
||||
* @return the value returned by the {@link RetryCallback} upon successful
|
||||
* invocation, and that returned by the {@link RecoveryCallback} otherwise.
|
||||
* @throws Exception any {@link Exception} raised by the
|
||||
* {@link RecoveryCallback} upon unsuccessful retry.
|
||||
* @param <T> the return value type
|
||||
* @param <E> the exception type
|
||||
* @return the value returned by the {@link RetryCallback} upon successful
|
||||
* invocation, and that returned by the {@link RecoveryCallback} otherwise.
|
||||
* @throws E any {@link Exception} raised by the {@link RecoveryCallback} upon unsuccessful retry.
|
||||
*/
|
||||
<T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RecoveryCallback<T> recoveryCallback, RetryState retryState)
|
||||
throws E;
|
||||
|
||||
@@ -56,7 +56,7 @@ public interface RetryPolicy {
|
||||
* Called once per retry attempt, after the callback fails.
|
||||
*
|
||||
* @param context the current status object.
|
||||
*
|
||||
* @param throwable the exception to throw
|
||||
*/
|
||||
void registerThrowable(RetryContext context, Throwable throwable);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public @interface Backoff {
|
||||
double multiplier() default 0;
|
||||
|
||||
/**
|
||||
* In the exponential case ({@link #multiplier()}>0) set this to true to have the
|
||||
* In the exponential case ({@link #multiplier()} > 0) set this to true to have the
|
||||
* backoff delays randomized, so that the maximum delay is multiplier times the
|
||||
* previous delay and the distribution is uniform between the two values.
|
||||
*
|
||||
|
||||
@@ -45,6 +45,8 @@ public @interface EnableRetry {
|
||||
/**
|
||||
* Indicate whether subclass-based (CGLIB) proxies are to be created as opposed
|
||||
* to standard Java interface-based proxies. The default is {@code false}.
|
||||
*
|
||||
* @return whether to proxy or not to proxy the class
|
||||
*/
|
||||
boolean proxyTargetClass() default false;
|
||||
|
||||
|
||||
@@ -21,17 +21,19 @@ import org.springframework.retry.RetryContext;
|
||||
/**
|
||||
* Strategy interface to control back off between attempts in a single
|
||||
* {@link org.springframework.retry.support.RetryTemplate retry operation}.
|
||||
* <p/> Implementations are expected to be thread-safe and should be designed
|
||||
*
|
||||
* Implementations are expected to be thread-safe and should be designed
|
||||
* for concurrent access. Configuration for each implementation is also expected
|
||||
* to be thread-safe but need not be suitable for high load concurrent access.
|
||||
* <p/> For each block of retry operations the {@link #start} method is called
|
||||
*
|
||||
* For each block of retry operations the {@link #start} method is called
|
||||
* and implementations can return an implementation-specific
|
||||
*
|
||||
* {@link BackOffContext} that can be used to track state through subsequent
|
||||
* back off invocations. <p/> Each back off process is handled via a call to
|
||||
* {@link #backOff}. The
|
||||
* {@link org.springframework.retry.support.RetryTemplate} will pass in
|
||||
* the corresponding {@link BackOffContext} object created by the call to
|
||||
* {@link #start}.
|
||||
* back off invocations. Each back off process is handled via a call to {@link #backOff}.
|
||||
*
|
||||
* The {@link org.springframework.retry.support.RetryTemplate} will pass in
|
||||
* the corresponding {@link BackOffContext} object created by the call to {@link #start}.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Dave Syer
|
||||
@@ -42,7 +44,7 @@ public interface BackOffPolicy {
|
||||
* Start a new block of back off operations. Implementations can choose to
|
||||
* pause when this method is called, but normally it returns immediately.
|
||||
*
|
||||
* @param context the current retry context, which might contain information
|
||||
* @param context the {@link RetryContext} context, which might contain information
|
||||
* that we can use to decide how to proceed.
|
||||
* @return the implementation-specific {@link BackOffContext} or '<code>null</code>'.
|
||||
*/
|
||||
@@ -55,6 +57,7 @@ public interface BackOffPolicy {
|
||||
*
|
||||
* @throws BackOffInterruptedException if the attempt at back off is
|
||||
* interrupted.
|
||||
* @param backOffContext the {@link BackOffContext}
|
||||
*/
|
||||
void backOff(BackOffContext backOffContext) throws BackOffInterruptedException;
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ import org.springframework.util.ClassUtils;
|
||||
* Implementation of {@link BackOffPolicy} that increases the back off period
|
||||
* for each retry attempt in a given set using the {@link Math#exp(double)
|
||||
* exponential} function.
|
||||
* <p/>
|
||||
*
|
||||
* This implementation is thread-safe and suitable for concurrent access.
|
||||
* Modifications to the configuration do not affect any retry sets that are
|
||||
* already in progress.
|
||||
* <p/>
|
||||
*
|
||||
* The {@link #setInitialInterval(long)} property controls the initial value
|
||||
* passed to {@link Math#exp(double)} and the {@link #setMultiplier(double)}
|
||||
* property controls by how much this value is increased for each subsequent
|
||||
@@ -104,8 +104,10 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy<Exponenti
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the initial sleep interval value. Default is <code>100</code>
|
||||
* Set the initial sleep interval value. Default is {@code 100}
|
||||
* millisecond. Cannot be set to a value less than one.
|
||||
*
|
||||
* @param initialInterval the initial interval
|
||||
*/
|
||||
public void setInitialInterval(long initialInterval) {
|
||||
this.initialInterval = (initialInterval > 1 ? initialInterval : 1);
|
||||
@@ -115,6 +117,7 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy<Exponenti
|
||||
* Set the multiplier value. Default is '<code>2.0</code>'. Hint: do not use
|
||||
* values much in excess of 1.0 (or the backoff will get very long very
|
||||
* fast).
|
||||
* @param multiplier the multiplier
|
||||
*/
|
||||
public void setMultiplier(double multiplier) {
|
||||
this.multiplier = (multiplier > 1.0 ? multiplier : 1.0);
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.retry.backoff;
|
||||
/**
|
||||
* Implementation of {@link BackOffPolicy} that pauses for a fixed period of time before
|
||||
* continuing. A pause is implemented using {@link Sleeper#sleep(long)}.
|
||||
* <p/>
|
||||
*
|
||||
* {@link #setBackOffPeriod(long)} is thread-safe and it is safe to call
|
||||
* {@link #setBackOffPeriod} during execution from multiple threads, however this may
|
||||
* cause a single retry operation to have pauses of different intervals.
|
||||
@@ -60,6 +60,7 @@ public class FixedBackOffPolicy extends StatelessBackOffPolicy implements
|
||||
|
||||
/**
|
||||
* Set the back off period in milliseconds. Cannot be < 1. Default value is 1000ms.
|
||||
* @param backOffPeriod the back off period
|
||||
*/
|
||||
public void setBackOffPeriod(long backOffPeriod) {
|
||||
this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1);
|
||||
|
||||
@@ -26,7 +26,8 @@ public interface Sleeper {
|
||||
/**
|
||||
* Pause for the specified period using whatever means available.
|
||||
*
|
||||
* @param backOffPeriod
|
||||
* @param backOffPeriod the backoff period
|
||||
* @throws InterruptedException the exception when interrupted
|
||||
*/
|
||||
void sleep(long backOffPeriod) throws InterruptedException;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Random;
|
||||
/**
|
||||
* Implementation of {@link BackOffPolicy} that pauses for a random period of
|
||||
* time before continuing. A pause is implemented using {@link Sleeper#sleep(long)}.
|
||||
* <p/>
|
||||
*
|
||||
* {@link #setMinBackOffPeriod(long)} is thread-safe and it is safe to call
|
||||
* {@link #setMaxBackOffPeriod(long)} during execution from multiple threads, however
|
||||
* this may cause a single retry operation to have pauses of different
|
||||
@@ -69,6 +69,8 @@ public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy implement
|
||||
/**
|
||||
* Set the minimum back off period in milliseconds. Cannot be < 1. Default value
|
||||
* is 500ms.
|
||||
*
|
||||
* @param backOffPeriod the backoff period
|
||||
*/
|
||||
public void setMinBackOffPeriod(long backOffPeriod) {
|
||||
this.minBackOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1);
|
||||
@@ -85,6 +87,7 @@ public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy implement
|
||||
/**
|
||||
* Set the maximum back off period in milliseconds. Cannot be < 1. Default value
|
||||
* is 1500ms.
|
||||
* @param backOffPeriod the back off period
|
||||
*/
|
||||
public void setMaxBackOffPeriod(long backOffPeriod) {
|
||||
this.maxBackOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1);
|
||||
|
||||
@@ -61,11 +61,11 @@ public class RetryContextSupport extends AttributeAccessorSupport implements Ret
|
||||
|
||||
/**
|
||||
* Set the exception for the public interface {@link RetryContext}, and
|
||||
* also increment the retry count if the throwable is non-null.<br/>
|
||||
* also increment the retry count if the throwable is non-null.
|
||||
*
|
||||
* All {@link RetryPolicy} implementations should use this method when they
|
||||
* register the throwable. It should only be called once per retry attempt
|
||||
* because it increments a counter.<br/>
|
||||
* because it increments a counter.
|
||||
*
|
||||
* Use of this method is not enforced by the framework - it is a service
|
||||
* provider contract for authors of policies.
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.retry.interceptor;
|
||||
|
||||
|
||||
/**
|
||||
* Strategy interface for recovery action when processing of an item fails.<br/>
|
||||
* Strategy interface for recovery action when processing of an item fails.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
* A {@link MethodInterceptor} that can be used to automatically retry calls to a method
|
||||
* on a service if it fails. The injected {@link RetryOperations} is used to control the
|
||||
* number of retries. By default it will retry a fixed number of times, according to the
|
||||
* defaults in {@link RetryTemplate}.<br/>
|
||||
* defaults in {@link RetryTemplate}.
|
||||
*
|
||||
* Hint about transaction boundaries. If you want to retry a failed transaction you need
|
||||
* to make sure that the transaction boundary is inside the retry, otherwise the
|
||||
|
||||
@@ -40,15 +40,15 @@ import org.springframework.util.ObjectUtils;
|
||||
* 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 {@link MethodArgumentsKeyGenerator})
|
||||
* until the retry is exhausted, at which point the {@link MethodInvocationRecoverer} is
|
||||
* called.<br/>
|
||||
* 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.<br/>
|
||||
* exhausted) always happens in a new transaction.
|
||||
*
|
||||
* The injected {@link RetryOperations} is used to control the number of retries. By
|
||||
* default it will retry a fixed number of times, according to the defaults in
|
||||
* {@link RetryTemplate}.<br/>
|
||||
* {@link RetryTemplate}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CompositeRetryPolicy implements RetryPolicy {
|
||||
/**
|
||||
* Setter for optimistic.
|
||||
*
|
||||
* @param optimistic
|
||||
* @param optimistic should this retry policy be optimistic
|
||||
*/
|
||||
public void setOptimistic(boolean optimistic) {
|
||||
this.optimistic = optimistic;
|
||||
@@ -49,7 +49,7 @@ public class CompositeRetryPolicy implements RetryPolicy {
|
||||
/**
|
||||
* Setter for policies.
|
||||
*
|
||||
* @param policies
|
||||
* @param policies the {@link RetryPolicy} policies
|
||||
*/
|
||||
public void setPolicies(RetryPolicy[] policies) {
|
||||
this.policies = Arrays.asList(policies).toArray(new RetryPolicy[policies.length]);
|
||||
@@ -60,6 +60,7 @@ public class CompositeRetryPolicy implements RetryPolicy {
|
||||
* created. If any of them cannot retry then return false, otherwise return
|
||||
* true.
|
||||
*
|
||||
* @param context the {@link RetryContext}
|
||||
* @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext)
|
||||
*/
|
||||
@Override
|
||||
@@ -94,6 +95,7 @@ public class CompositeRetryPolicy implements RetryPolicy {
|
||||
* those later in the chain are closed before re-throwing).
|
||||
*
|
||||
* @see org.springframework.retry.RetryPolicy#close(org.springframework.retry.RetryContext)
|
||||
* @param context the {@link RetryContext}
|
||||
*/
|
||||
@Override
|
||||
public void close(RetryContext context) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.retry.RetryContext;
|
||||
* cache of contexts is synchronized.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class MapRetryContextCache implements RetryContextCache {
|
||||
|
||||
@@ -49,7 +48,7 @@ public class MapRetryContextCache implements RetryContextCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultCapacity
|
||||
* @param defaultCapacity the default capacity
|
||||
*/
|
||||
public MapRetryContextCache(int defaultCapacity) {
|
||||
super();
|
||||
|
||||
@@ -34,7 +34,7 @@ public class RetryCacheCapacityExceededException extends RetryException {
|
||||
/**
|
||||
* Constructs a new instance with a message.
|
||||
*
|
||||
* @param message
|
||||
* @param message the message sent when creating the exception
|
||||
*/
|
||||
public RetryCacheCapacityExceededException(String message) {
|
||||
super(message);
|
||||
@@ -44,7 +44,7 @@ public class RetryCacheCapacityExceededException extends RetryException {
|
||||
* Constructs a new instance with a message and nested exception.
|
||||
*
|
||||
* @param msg the exception message.
|
||||
*
|
||||
* @param nested the nested exception
|
||||
*/
|
||||
public RetryCacheCapacityExceededException(String msg, Throwable nested) {
|
||||
super(msg, nested);
|
||||
|
||||
@@ -67,8 +67,8 @@ public class SimpleRetryPolicy implements RetryPolicy {
|
||||
* Create a {@link SimpleRetryPolicy} with the specified number of retry
|
||||
* attempts.
|
||||
*
|
||||
* @param maxAttempts
|
||||
* @param retryableExceptions
|
||||
* @param maxAttempts the maximum number of attempts
|
||||
* @param retryableExceptions the map of exceptions that are retryable
|
||||
*/
|
||||
public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
|
||||
this(maxAttempts, retryableExceptions, false);
|
||||
@@ -79,9 +79,9 @@ public class SimpleRetryPolicy implements RetryPolicy {
|
||||
* attempts. If traverseCauses is true, the exception causes will be traversed until
|
||||
* a match is found.
|
||||
*
|
||||
* @param maxAttempts
|
||||
* @param retryableExceptions
|
||||
* @param traverseCauses
|
||||
* @param maxAttempts the maximum number of attempts
|
||||
* @param retryableExceptions the map of exceptions that are retryable
|
||||
* @param traverseCauses is this clause traversable
|
||||
*/
|
||||
public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions,
|
||||
boolean traverseCauses) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.retry.RetryContext;
|
||||
* @see MapRetryContextCache for non-soft referenced version
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SoftReferenceMapRetryContextCache implements RetryContextCache {
|
||||
|
||||
@@ -54,7 +53,7 @@ public class SoftReferenceMapRetryContextCache implements RetryContextCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultCapacity
|
||||
* @param defaultCapacity the default capacity
|
||||
*/
|
||||
public SoftReferenceMapRetryContextCache(int defaultCapacity) {
|
||||
super();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TimeoutRetryPolicy implements RetryPolicy {
|
||||
|
||||
/**
|
||||
* Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
|
||||
* @param timeout
|
||||
* @param timeout how long to wait until a timeout
|
||||
*/
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
|
||||
@@ -58,6 +58,8 @@ public class DefaultRetryState implements RetryState {
|
||||
/**
|
||||
* Defaults the force refresh flag to false.
|
||||
* @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier)
|
||||
* @param key the key
|
||||
* @param rollbackClassifier the rollback {@link Classifier}
|
||||
*/
|
||||
public DefaultRetryState(Object key, Classifier<? super Throwable, Boolean> rollbackClassifier) {
|
||||
this(key, false, rollbackClassifier);
|
||||
@@ -66,6 +68,8 @@ public class DefaultRetryState implements RetryState {
|
||||
/**
|
||||
* Defaults the rollback classifier to null.
|
||||
* @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier)
|
||||
* @param key the key
|
||||
* @param forceRefresh whether to force a refresh
|
||||
*/
|
||||
public DefaultRetryState(Object key, boolean forceRefresh) {
|
||||
this(key, forceRefresh, null);
|
||||
@@ -74,7 +78,8 @@ public class DefaultRetryState implements RetryState {
|
||||
/**
|
||||
* Defaults the force refresh flag (to false) and the rollback classifier
|
||||
* (to null).
|
||||
*
|
||||
*
|
||||
* @param key the key to use
|
||||
* @see DefaultRetryState#DefaultRetryState(Object, boolean, Classifier)
|
||||
*/
|
||||
public DefaultRetryState(Object key) {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class RetrySimulation {
|
||||
|
||||
/**
|
||||
* Add a sequence of sleeps to the simulation.
|
||||
* @param sleeps the times to be created as a {@link SleepSequence}
|
||||
*/
|
||||
public void addSequence(List<Long> sleeps) {
|
||||
sleepHistogram.addAll(sleeps);
|
||||
@@ -97,7 +98,7 @@ public class RetrySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the longest individual sleep within this sequence.
|
||||
* @return the longest individual sleep within this sequence
|
||||
*/
|
||||
public long getLongestSleep() {
|
||||
return longestSleep;
|
||||
|
||||
@@ -43,20 +43,21 @@ import org.springframework.retry.policy.RetryContextCache;
|
||||
import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||
|
||||
/**
|
||||
* Template class that simplifies the execution of operations with retry semantics. <br/>
|
||||
* Template class that simplifies the execution of operations with retry semantics.
|
||||
* <p>
|
||||
* Retryable operations are encapsulated in implementations of the {@link RetryCallback}
|
||||
* interface and are executed using one of the supplied execute methods. <br/>
|
||||
*
|
||||
* interface and are executed using one of the supplied execute methods.
|
||||
* <p>
|
||||
* By default, an operation is retried if is throws any {@link Exception} or subclass of
|
||||
* {@link Exception}. This behaviour can be changed by using the
|
||||
* {@link #setRetryPolicy(RetryPolicy)} method. <br/>
|
||||
*
|
||||
* {@link #setRetryPolicy(RetryPolicy)} method.
|
||||
* <p>
|
||||
* Also by default, each operation is retried for a maximum of three attempts with no back
|
||||
* off in between. This behaviour can be configured using the
|
||||
* {@link #setRetryPolicy(RetryPolicy)} and {@link #setBackOffPolicy(BackOffPolicy)}
|
||||
* properties. The {@link org.springframework.retry.backoff.BackOffPolicy} controls how
|
||||
* long the pause is between each individual retry attempt. <br/>
|
||||
*
|
||||
* long the pause is between each individual retry attempt.
|
||||
* <p>
|
||||
* This class is thread-safe and suitable for concurrent access when executing operations
|
||||
* and when performing configuration changes. As such, it is possible to change the number
|
||||
* of retries on the fly, as well as the {@link BackOffPolicy} used and no in progress
|
||||
@@ -66,6 +67,7 @@ import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class RetryTemplate implements RetryOperations {
|
||||
|
||||
@@ -102,7 +104,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
* Setter for listeners. The listeners are executed before and after a retry block
|
||||
* (i.e. before and after all the attempts), and on an error (every attempt).
|
||||
*
|
||||
* @param listeners
|
||||
* @param listeners the {@link RetryListener}s
|
||||
* @see RetryListener
|
||||
*/
|
||||
public void setListeners(RetryListener[] listeners) {
|
||||
@@ -113,7 +115,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
/**
|
||||
* Register an additional listener.
|
||||
*
|
||||
* @param listener
|
||||
* @param listener the {@link RetryListener}
|
||||
* @see #setListeners(RetryListener[])
|
||||
*/
|
||||
public void registerListener(RetryListener listener) {
|
||||
@@ -125,7 +127,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
/**
|
||||
* Setter for {@link BackOffPolicy}.
|
||||
*
|
||||
* @param backOffPolicy
|
||||
* @param backOffPolicy the {@link BackOffPolicy}
|
||||
*/
|
||||
public void setBackOffPolicy(BackOffPolicy backOffPolicy) {
|
||||
this.backOffPolicy = backOffPolicy;
|
||||
@@ -134,7 +136,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
/**
|
||||
* Setter for {@link RetryPolicy}.
|
||||
*
|
||||
* @param retryPolicy
|
||||
* @param retryPolicy the {@link RetryPolicy}
|
||||
*/
|
||||
public void setRetryPolicy(RetryPolicy retryPolicy) {
|
||||
this.retryPolicy = retryPolicy;
|
||||
@@ -146,6 +148,7 @@ public class RetryTemplate implements RetryOperations {
|
||||
* rethrown.
|
||||
*
|
||||
* @see RetryOperations#execute(RetryCallback)
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
*
|
||||
* @throws TerminatedRetryException if the retry has been manually terminated by a
|
||||
* listener.
|
||||
@@ -159,7 +162,8 @@ public class RetryTemplate implements RetryOperations {
|
||||
* stop, in which case the recovery callback will be executed.
|
||||
*
|
||||
* @see RetryOperations#execute(RetryCallback, RecoveryCallback)
|
||||
*
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param recoveryCallback the {@link RecoveryCallback}
|
||||
* @throws TerminatedRetryException if the retry has been manually terminated by a
|
||||
* listener.
|
||||
*/
|
||||
@@ -173,7 +177,8 @@ public class RetryTemplate implements RetryOperations {
|
||||
* exception encountered so that clients can re-present the same task later.
|
||||
*
|
||||
* @see RetryOperations#execute(RetryCallback, RetryState)
|
||||
*
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param retryState the {@link RetryState}
|
||||
* @throws ExhaustedRetryException if the retry has been exhausted.
|
||||
*/
|
||||
public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback, RetryState retryState)
|
||||
@@ -186,6 +191,9 @@ public class RetryTemplate implements RetryOperations {
|
||||
* exception encountered so that clients can re-present the same task later.
|
||||
*
|
||||
* @see RetryOperations#execute(RetryCallback, RetryState)
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param recoveryCallback the {@link RecoveryCallback}
|
||||
* @param retryState the {@link RetryState}
|
||||
*/
|
||||
public final <T, E extends Throwable> T execute(RetryCallback<T, E> retryCallback,
|
||||
RecoveryCallback<T> recoveryCallback, RetryState retryState)
|
||||
@@ -196,10 +204,15 @@ public class RetryTemplate implements RetryOperations {
|
||||
/**
|
||||
* Execute the callback once if the policy dictates that we can, otherwise execute the
|
||||
* recovery callback.
|
||||
*
|
||||
* @param recoveryCallback the {@link RecoveryCallback}
|
||||
* @param retryCallback the {@link RetryCallback}
|
||||
* @param state the {@link RetryState}
|
||||
* @param <T> the type of the return value
|
||||
* @param <E> the exception type to throw
|
||||
* @see RetryOperations#execute(RetryCallback, RecoveryCallback, RetryState)
|
||||
* @throws ExhaustedRetryException if the retry has been exhausted. finally {
|
||||
|
||||
* @throws ExhaustedRetryException if the retry has been exhausted.
|
||||
* @throws E an exception if the retry operation fails
|
||||
* @return T the retried value
|
||||
*/
|
||||
protected <T, E extends Throwable> T doExecute(RetryCallback<T, E> retryCallback,
|
||||
RecoveryCallback<T> recoveryCallback, RetryState state) throws E,
|
||||
@@ -348,9 +361,10 @@ public class RetryTemplate implements RetryOperations {
|
||||
* Clean up the cache if necessary and close the context provided (if the flag
|
||||
* indicates that processing was successful).
|
||||
*
|
||||
* @param context
|
||||
* @param state
|
||||
* @param succeeded
|
||||
* @param retryPolicy the {@link RetryPolicy}
|
||||
* @param context the {@link RetryContext}
|
||||
* @param state the {@link RetryState}
|
||||
* @param succeeded whether the close succeeded
|
||||
*/
|
||||
protected void close(RetryPolicy retryPolicy, RetryContext context, RetryState state,
|
||||
boolean succeeded) {
|
||||
@@ -366,10 +380,10 @@ public class RetryTemplate implements RetryOperations {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param retryPolicy
|
||||
* @param state
|
||||
* @param context
|
||||
* @param e
|
||||
* @param retryPolicy the retry policy
|
||||
* @param state the retry state
|
||||
* @param context the retry context
|
||||
* @param e the exception thrown
|
||||
*/
|
||||
protected void registerThrowable(RetryPolicy retryPolicy, RetryState state,
|
||||
RetryContext context, Throwable e) {
|
||||
@@ -390,7 +404,9 @@ public class RetryTemplate implements RetryOperations {
|
||||
* Delegate to the {@link RetryPolicy} having checked in the cache for an existing
|
||||
* value if the state is not null.
|
||||
*
|
||||
* @param state a {@link RetryState}
|
||||
* @param retryPolicy a {@link RetryPolicy} to delegate the context creation
|
||||
*
|
||||
* @return a retry context, either a new one or the one used last time the same state
|
||||
* was encountered
|
||||
*/
|
||||
@@ -429,10 +445,6 @@ public class RetryTemplate implements RetryOperations {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param retryPolicy
|
||||
* @return
|
||||
*/
|
||||
private RetryContext doOpenInternal(RetryPolicy retryPolicy) {
|
||||
return retryPolicy.open(RetrySynchronizationManager.getContext());
|
||||
}
|
||||
@@ -444,10 +456,13 @@ public class RetryTemplate implements RetryOperations {
|
||||
*
|
||||
* @param recoveryCallback the callback for recovery (might be null)
|
||||
* @param context the current retry context
|
||||
* @param state the {@link RetryState}
|
||||
* @param <T> the type to classify
|
||||
* @throws Exception if the callback does, and if there is no callback and the state
|
||||
* is null then the last exception from the context
|
||||
* @throws ExhaustedRetryException if the state is not null and there is no recovery
|
||||
* callback
|
||||
* @return T the payload to return
|
||||
*/
|
||||
protected <T> T handleRetryExhausted(RecoveryCallback<T> recoveryCallback,
|
||||
RetryContext context, RetryState state) throws Throwable {
|
||||
@@ -480,9 +495,9 @@ public class RetryTemplate implements RetryOperations {
|
||||
* in a {@link RetryCallback}. Normal stateless behaviour is not to rethrow, and if
|
||||
* there is state we rethrow.
|
||||
*
|
||||
* @param retryPolicy
|
||||
* @param retryPolicy the retry policy
|
||||
* @param context the current context
|
||||
*
|
||||
* @param state the current retryState
|
||||
* @return true if the state is not null but subclasses might choose otherwise
|
||||
*/
|
||||
protected boolean shouldRethrow(RetryPolicy retryPolicy, RetryContext context, RetryState state) {
|
||||
|
||||
Reference in New Issue
Block a user