From 38316963c1a340871014b9fa77d1ef0b8fbe0a06 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 23 Aug 2016 13:29:26 +0100 Subject: [PATCH] Ensure label is only set if explicit --- ...tationAwareRetryOperationsInterceptor.java | 4 +-- .../retry/annotation/Retryable.java | 36 +++++++++---------- .../interceptor/RetryInterceptorBuilder.java | 20 ++++------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java index 7b7f973..948f04b 100644 --- a/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java +++ b/src/main/java/org/springframework/retry/annotation/AnnotationAwareRetryOperationsInterceptor.java @@ -189,6 +189,7 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn template.setBackOffPolicy(getBackoffPolicy(retryable.backoff())); return RetryInterceptorBuilder.stateless() .retryOperations(template) + .label(retryable.label()) .recoverer(getRecoverer(target, method)) .build(); } @@ -220,9 +221,6 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn template.setRetryPolicy(policy); template.setBackOffPolicy(getBackoffPolicy(retryable.backoff())); String label = retryable.label(); - if (!StringUtils.hasText(label)) { - label = method.toGenericString(); - } return RetryInterceptorBuilder.stateful() .retryOperations(template) .label(label) diff --git a/src/main/java/org/springframework/retry/annotation/Retryable.java b/src/main/java/org/springframework/retry/annotation/Retryable.java index d9b4c2b..de04526 100644 --- a/src/main/java/org/springframework/retry/annotation/Retryable.java +++ b/src/main/java/org/springframework/retry/annotation/Retryable.java @@ -36,60 +36,58 @@ import java.lang.annotation.Target; public @interface Retryable { /** - * Retry interceptor bean name to be applied for retryable method. - * Is mutually exclusive with other attributes. + * Retry interceptor bean name to be applied for retryable method. Is mutually + * exclusive with other attributes. * @return the retry interceptor bean name */ String interceptor() default ""; /** - * Exception types that are retryable. Synonym for includes(). Defaults to - * empty (and if excludes is also empty all exceptions are retried). + * Exception types that are retryable. Synonym for includes(). Defaults to empty (and + * if excludes is also empty all exceptions are retried). * @return exception types to retry */ Class[] value() default {}; /** - * Exception types that are retryable. Defaults to empty (and if excludes is - * also empty all exceptions are retried). + * Exception types that are retryable. Defaults to empty (and if excludes is also + * empty all exceptions are retried). * @return exception types to retry */ Class[] include() default {}; /** - * Exception types that are not retryable. Defaults to empty (and if - * includes is also empty all exceptions are retried). + * Exception types that are not retryable. Defaults to empty (and if includes is also + * empty all exceptions are retried). * @return exception types to retry */ Class[] exclude() default {}; /** - * A unique label for the statistics reporting. Defaults to the - * method signature where the annotation is declared. + * A unique label for statistics reporting. If not provided the caller may choose to + * ignore it, or provide a default. * * @return the label for the statistics */ String label() default ""; /** - * Flag to say that the retry is stateful: i.e. exceptions are re-thrown, - * but the retry policy is applied with the same policy to subsequent - * invocations with the same arguments. If false then retryable exceptions - * are not re-thrown. + * Flag to say that the retry is stateful: i.e. exceptions are re-thrown, but the + * retry policy is applied with the same policy to subsequent invocations with the + * same arguments. If false then retryable exceptions are not re-thrown. * @return true if retry is stateful, default false */ boolean stateful() default false; /** - * @return the maximum number of attempts (including the first failure), - * defaults to 3 + * @return the maximum number of attempts (including the first failure), defaults to 3 */ int maxAttempts() default 3; /** - * Specify the backoff properties for retrying this operation. The default is - * no backoff, but it can be a good idea to pause between attempts (even at - * the cost of blocking a thread). + * Specify the backoff properties for retrying this operation. The default is no + * backoff, but it can be a good idea to pause between attempts (even at the cost of + * blocking a thread). * @return a backoff specification */ Backoff backoff() default @Backoff(); diff --git a/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java b/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java index 411bdc0..ccc8c31 100644 --- a/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java +++ b/src/main/java/org/springframework/retry/interceptor/RetryInterceptorBuilder.java @@ -69,6 +69,8 @@ public abstract class RetryInterceptorBuilder { private boolean backOffOptionsSet; + protected String label; + /** * Create a builder for a stateful retry interceptor. * @return The interceptor builder. @@ -191,6 +193,11 @@ public abstract class RetryInterceptorBuilder { return this; } + public RetryInterceptorBuilder label(String label) { + this.label = label; + return this; + } + public abstract T build(); private RetryInterceptorBuilder() { @@ -326,8 +333,6 @@ public abstract class RetryInterceptorBuilder { private MethodArgumentsKeyGenerator keyGenerator; - private String label; - @Override public CircuitBreakerInterceptorBuilder retryOperations( RetryOperations retryOperations) { @@ -359,11 +364,6 @@ public abstract class RetryInterceptorBuilder { return this; } - public CircuitBreakerInterceptorBuilder label(String label) { - this.label = label; - return this; - } - @Override public StatefulRetryOperationsInterceptor build() { if (this.recoverer != null) { @@ -394,12 +394,6 @@ public abstract class RetryInterceptorBuilder { extends RetryInterceptorBuilder { private final RetryOperationsInterceptor interceptor = new RetryOperationsInterceptor(); - private String label; - - public StatelessRetryInterceptorBuilder label(String label) { - this.label = label; - return this; - } @Override public RetryOperationsInterceptor build() {