public class SimpleRetryPolicy extends Object implements RetryPolicy
retryTemplate = new RetryTemplate(new SimpleRetryPolicy(3)); retryTemplate.execute(callback);will execute the callback at least once, and as many as 3 times.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_ATTEMPTS
The default limit to the number of attempts for a new policy.
|
| Constructor and Description |
|---|
SimpleRetryPolicy()
Create a
SimpleRetryPolicy with the default number of retry
attempts, retrying all exceptions. |
SimpleRetryPolicy(int maxAttempts)
Create a
SimpleRetryPolicy with the specified number of retry
attempts, retrying all exceptions. |
SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions)
Create a
SimpleRetryPolicy with the specified number of retry
attempts. |
SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions,
boolean traverseCauses)
Create a
SimpleRetryPolicy with the specified number of retry
attempts. |
SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions,
boolean traverseCauses,
boolean defaultValue)
Create a
SimpleRetryPolicy with the specified number of retry
attempts. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRetry(RetryContext context)
Test for retryable operation based on the status.
|
void |
close(RetryContext status) |
int |
getMaxAttempts()
The maximum number of attempts before failure.
|
RetryContext |
open(RetryContext parent)
Get a status object that can be used to track the current operation
according to this policy.
|
void |
registerThrowable(RetryContext context,
Throwable throwable)
Update the status with another attempted retry and the latest exception.
|
void |
setMaxAttempts(int maxAttempts)
Set the number of attempts before retries are exhausted.
|
String |
toString() |
public static final int DEFAULT_MAX_ATTEMPTS
public SimpleRetryPolicy()
SimpleRetryPolicy with the default number of retry
attempts, retrying all exceptions.public SimpleRetryPolicy(int maxAttempts)
SimpleRetryPolicy with the specified number of retry
attempts, retrying all exceptions.public SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions)
SimpleRetryPolicy with the specified number of retry
attempts.maxAttempts - the maximum number of attemptsretryableExceptions - the map of exceptions that are retryablepublic SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions,
boolean traverseCauses)
SimpleRetryPolicy with the specified number of retry
attempts. If traverseCauses is true, the exception causes will be traversed until
a match is found.maxAttempts - the maximum number of attemptsretryableExceptions - the map of exceptions that are retryable based on the
map value (true/false).traverseCauses - is this clause traversablepublic SimpleRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>,Boolean> retryableExceptions,
boolean traverseCauses,
boolean defaultValue)
SimpleRetryPolicy with the specified number of retry
attempts. If traverseCauses is true, the exception causes will be traversed until
a match is found. The default value indicates whether to retry or not for exceptions
(or super classes) are not found in the map.maxAttempts - the maximum number of attemptsretryableExceptions - the map of exceptions that are retryable based on the
map value (true/false).traverseCauses - is this clause traversabledefaultValue - the default action.public void setMaxAttempts(int maxAttempts)
>= 1. For example
setting this property to 3 means 3 attempts total (initial + 2 retries).maxAttempts - the maximum number of attempts including the initial attempt.public int getMaxAttempts()
public boolean canRetry(RetryContext context)
canRetry in interface RetryPolicycontext - the current retry statusRetryPolicy.canRetry(org.springframework.retry.RetryContext)public void close(RetryContext status)
close in interface RetryPolicystatus - a retry status created by the
RetryPolicy.open(RetryContext) method of this policy.RetryPolicy.close(RetryContext)public void registerThrowable(RetryContext context, Throwable throwable)
registerThrowable in interface RetryPolicycontext - the current status object.throwable - the exception to throwRetryPolicy.registerThrowable(RetryContext, Throwable)public RetryContext open(RetryContext parent)
open in interface RetryPolicyparent - the parent context if we are in a nested retry.RetryContext object specific to this policy.RetryPolicy.open(RetryContext)Copyright © 2018 SpringSource. All rights reserved.