From 660c01adc979f6269ed83fe96ca168296b1b1787 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 26 Dec 2014 11:41:30 -0500 Subject: [PATCH] GH-19 SimpleRetryPolicy MaxAttempts JavaDocs See GH-19 --- README.md | 2 +- .../interceptor/RetryInterceptorBuilder.java | 2 +- .../retry/policy/SimpleRetryPolicy.java | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 27191bfb..5235f343 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ The `SimpleRetryPolicy` just allows a retry on any of a named list of exception ```java SimpleRetryPolicy policy = new SimpleRetryPolicy(); -// Set the max retry attempts +// Set the max attempts including the initial attempt before retrying policy.setMaxAttempts(5); // Retry on all exceptions (this is the default) policy.setRetryableExceptions(new Class[] {Exception.class}); diff --git a/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java b/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java index f3547619..bc2eb32f 100644 --- a/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java +++ b/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java @@ -99,7 +99,7 @@ public RetryInterceptorBuilder retryOperations(RetryOperations retryOperation /** * Apply the max attempts - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations * or retry policy has been set. - * @param maxAttempts the max attempts. + * @param maxAttempts the max attempts (including the initial attempt). * @return this. */ public RetryInterceptorBuilder maxAttempts(int maxAttempts) { diff --git a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java index f0ca03d0..f0421c15 100644 --- a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java +++ b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java @@ -92,22 +92,23 @@ public SimpleRetryPolicy(int maxAttempts, Map, Boolea } /** - * 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 - * impossible. + * @param maxAttempts the maximum number of attempts including the initial attempt. */ - public void setMaxAttempts(int retryAttempts) { - this.maxAttempts = retryAttempts; + public void setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; } /** - * The maximum number of retry attempts before failure. + * The maximum number of attempts before failure. * * @return the maximum number of attempts */ public int getMaxAttempts() { - return maxAttempts; + return this.maxAttempts; } /** @@ -118,6 +119,7 @@ public int getMaxAttempts() { * @return true if the last exception was retryable and the number of * attempts so far is less than the limit. */ + @Override public boolean canRetry(RetryContext context) { Throwable t = context.getLastThrowable(); return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts; @@ -126,6 +128,7 @@ public boolean canRetry(RetryContext context) { /** * @see org.springframework.retry.RetryPolicy#close(RetryContext) */ + @Override public void close(RetryContext status) { } @@ -134,6 +137,7 @@ public void close(RetryContext status) { * * @see RetryPolicy#registerThrowable(RetryContext, Throwable) */ + @Override public void registerThrowable(RetryContext context, Throwable throwable) { SimpleRetryContext simpleContext = ((SimpleRetryContext) context); simpleContext.registerThrowable(throwable); @@ -146,6 +150,7 @@ public void registerThrowable(RetryContext context, Throwable throwable) { * * @see org.springframework.retry.RetryPolicy#open(RetryContext) */ + @Override public RetryContext open(RetryContext parent) { return new SimpleRetryContext(parent); }