GH-19 SimpleRetryPolicy MaxAttempts JavaDocs

See GH-19
This commit is contained in:
Gary Russell
2014-12-26 11:41:30 -05:00
committed by Dave Syer
parent b5340eb450
commit 660c01adc9
3 changed files with 14 additions and 9 deletions

View File

@@ -156,7 +156,7 @@ The `SimpleRetryPolicy` just allows a retry on any of a named list of exception
```java ```java
SimpleRetryPolicy policy = new SimpleRetryPolicy(); SimpleRetryPolicy policy = new SimpleRetryPolicy();
// Set the max retry attempts // Set the max attempts including the initial attempt before retrying
policy.setMaxAttempts(5); policy.setMaxAttempts(5);
// Retry on all exceptions (this is the default) // Retry on all exceptions (this is the default)
policy.setRetryableExceptions(new Class[] {Exception.class}); policy.setRetryableExceptions(new Class[] {Exception.class});

View File

@@ -99,7 +99,7 @@ public abstract class RetryInterceptorBuilder<T extends MethodInterceptor> {
/** /**
* Apply the max attempts - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations * Apply the max attempts - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations
* or retry policy has been set. * or retry policy has been set.
* @param maxAttempts the max attempts. * @param maxAttempts the max attempts (including the initial attempt).
* @return this. * @return this.
*/ */
public RetryInterceptorBuilder<T> maxAttempts(int maxAttempts) { public RetryInterceptorBuilder<T> maxAttempts(int maxAttempts) {

View File

@@ -92,22 +92,23 @@ public class SimpleRetryPolicy implements RetryPolicy {
} }
/** /**
* Setter for retry attempts. * Set the number of attempts before retries are exhausted. Includes the initial
* attempt before the retries begin so, generally, will be {@code >= 1}. For example
* setting this property to 3 means 3 attempts total (initial + 2 retries).
* *
* @param retryAttempts the number of attempts before a retry becomes * @param maxAttempts the maximum number of attempts including the initial attempt.
* impossible.
*/ */
public void setMaxAttempts(int retryAttempts) { public void setMaxAttempts(int maxAttempts) {
this.maxAttempts = retryAttempts; this.maxAttempts = maxAttempts;
} }
/** /**
* The maximum number of retry attempts before failure. * The maximum number of attempts before failure.
* *
* @return the maximum number of attempts * @return the maximum number of attempts
*/ */
public int getMaxAttempts() { public int getMaxAttempts() {
return maxAttempts; return this.maxAttempts;
} }
/** /**
@@ -118,6 +119,7 @@ public class SimpleRetryPolicy implements RetryPolicy {
* @return true if the last exception was retryable and the number of * @return true if the last exception was retryable and the number of
* attempts so far is less than the limit. * attempts so far is less than the limit.
*/ */
@Override
public boolean canRetry(RetryContext context) { public boolean canRetry(RetryContext context) {
Throwable t = context.getLastThrowable(); Throwable t = context.getLastThrowable();
return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts; return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts;
@@ -126,6 +128,7 @@ public class SimpleRetryPolicy implements RetryPolicy {
/** /**
* @see org.springframework.retry.RetryPolicy#close(RetryContext) * @see org.springframework.retry.RetryPolicy#close(RetryContext)
*/ */
@Override
public void close(RetryContext status) { public void close(RetryContext status) {
} }
@@ -134,6 +137,7 @@ public class SimpleRetryPolicy implements RetryPolicy {
* *
* @see RetryPolicy#registerThrowable(RetryContext, Throwable) * @see RetryPolicy#registerThrowable(RetryContext, Throwable)
*/ */
@Override
public void registerThrowable(RetryContext context, Throwable throwable) { public void registerThrowable(RetryContext context, Throwable throwable) {
SimpleRetryContext simpleContext = ((SimpleRetryContext) context); SimpleRetryContext simpleContext = ((SimpleRetryContext) context);
simpleContext.registerThrowable(throwable); simpleContext.registerThrowable(throwable);
@@ -146,6 +150,7 @@ public class SimpleRetryPolicy implements RetryPolicy {
* *
* @see org.springframework.retry.RetryPolicy#open(RetryContext) * @see org.springframework.retry.RetryPolicy#open(RetryContext)
*/ */
@Override
public RetryContext open(RetryContext parent) { public RetryContext open(RetryContext parent) {
return new SimpleRetryContext(parent); return new SimpleRetryContext(parent);
} }