Ensure label is only set if explicit
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<? extends Throwable>[] 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<? extends Throwable>[] 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<? extends Throwable>[] 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();
|
||||
|
||||
@@ -69,6 +69,8 @@ public abstract class RetryInterceptorBuilder<T extends MethodInterceptor> {
|
||||
|
||||
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<T extends MethodInterceptor> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RetryInterceptorBuilder<T> label(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract T build();
|
||||
|
||||
private RetryInterceptorBuilder() {
|
||||
@@ -326,8 +333,6 @@ public abstract class RetryInterceptorBuilder<T extends MethodInterceptor> {
|
||||
|
||||
private MethodArgumentsKeyGenerator keyGenerator;
|
||||
|
||||
private String label;
|
||||
|
||||
@Override
|
||||
public CircuitBreakerInterceptorBuilder retryOperations(
|
||||
RetryOperations retryOperations) {
|
||||
@@ -359,11 +364,6 @@ public abstract class RetryInterceptorBuilder<T extends MethodInterceptor> {
|
||||
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<T extends MethodInterceptor> {
|
||||
extends RetryInterceptorBuilder<RetryOperationsInterceptor> {
|
||||
|
||||
private final RetryOperationsInterceptor interceptor = new RetryOperationsInterceptor();
|
||||
private String label;
|
||||
|
||||
public StatelessRetryInterceptorBuilder label(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RetryOperationsInterceptor build() {
|
||||
|
||||
Reference in New Issue
Block a user