public class SqlRetryPolicy extends Object implements org.springframework.retry.RetryPolicy
RetryPolicy implementation that checks for database error which are retryable. Normally this are well known
exceptions inside the JDBC (1.6) exception hierarchy and also the Spring DataAccessException hierarchy. In addition to that, this class also tries for permanent
exception which are related to a connection of the database. This is useful because Amazon RDS database instances
might be retryable even if there is a permanent error. This is typically the case in a master a/z failover where
the source instance might not be available but a second attempt might succeed because the DNS record has been updated
to the failover instance.
In contrast to a SimpleRetryPolicy this class also checks recursively the
cause of the exception if there is a retryable implementation.
| Constructor and Description |
|---|
SqlRetryPolicy() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRetry(org.springframework.retry.RetryContext context)
Returns if this method is retryable based on the
RetryContext. |
void |
close(org.springframework.retry.RetryContext context) |
org.springframework.retry.RetryContext |
open(org.springframework.retry.RetryContext parent) |
void |
registerThrowable(org.springframework.retry.RetryContext context,
Throwable throwable) |
void |
setMaxNumberOfRetries(int maxNumberOfRetries)
Configures the maximum number of retries.
|
public boolean canRetry(org.springframework.retry.RetryContext context)
RetryContext. If there is no Throwable registered, then
this method returns true without checking any further conditions. If there is a Throwable registered,
this class checks if the registered Throwable is a retryable Exception in the context of SQL exception. If not
successful, this class also checks the cause if there is a nested retryable exception available.
Before checking exception this class checks that the current retry count (fetched through RetryContext.getRetryCount() is smaller or equals to the maxNumberOfRetries
canRetry in interface org.springframework.retry.RetryPolicycontext - - the retry context holding information about the retryable operation (number of retries, throwable if any)true if there is no throwable registered, if there is a retryable exception and the number of maximum
numbers of retries have not been reached.public org.springframework.retry.RetryContext open(org.springframework.retry.RetryContext parent)
open in interface org.springframework.retry.RetryPolicypublic void close(org.springframework.retry.RetryContext context)
close in interface org.springframework.retry.RetryPolicypublic void registerThrowable(org.springframework.retry.RetryContext context,
Throwable throwable)
registerThrowable in interface org.springframework.retry.RetryPolicypublic void setMaxNumberOfRetries(int maxNumberOfRetries)
Note:Consider using a BackOffPolicy which ensures that there is
enough time left between the retry attempts instead of increasing this value to a high number. The back-off policy
ensures that there is a delay in between the retry operations.
maxNumberOfRetries - - the maximum number of retries should be a positive number, otherwise all retries will fail.Copyright © 2016 Pivotal Software, Inc.. All rights reserved.