Revise naming and docs for "jitter" and "multiplier" in AOP retry support

See gh-34529
This commit is contained in:
Sam Brannen 2025-06-27 16:17:40 +02:00
parent 98b29b5e37
commit 7cc29d2019
6 changed files with 30 additions and 30 deletions

View File

@ -104,8 +104,8 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
ExponentialBackOff backOff = new ExponentialBackOff(); ExponentialBackOff backOff = new ExponentialBackOff();
backOff.setInitialInterval(spec.delay()); backOff.setInitialInterval(spec.delay());
backOff.setJitter(spec.jitterDelay()); backOff.setJitter(spec.jitter());
backOff.setMultiplier(spec.delayMultiplier()); backOff.setMultiplier(spec.multiplier());
backOff.setMaxInterval(spec.maxDelay()); backOff.setMaxInterval(spec.maxDelay());
backOff.setMaxAttempts(spec.maxAttempts()); backOff.setMaxAttempts(spec.maxAttempts());
retryTemplate.setBackOffPolicy(backOff); retryTemplate.setBackOffPolicy(backOff);
@ -147,8 +147,8 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
Publisher<?> publisher = adapter.toPublisher(result); Publisher<?> publisher = adapter.toPublisher(result);
Retry retry = Retry.backoff(spec.maxAttempts(), Duration.ofMillis(spec.delay())) Retry retry = Retry.backoff(spec.maxAttempts(), Duration.ofMillis(spec.delay()))
.jitter((double) spec.jitterDelay() / spec.delay()) .jitter((double) spec.jitter() / spec.delay())
.multiplier(spec.delayMultiplier()) .multiplier(spec.multiplier())
.maxBackoff(Duration.ofMillis(spec.maxDelay())) .maxBackoff(Duration.ofMillis(spec.maxDelay()))
.filter(spec.combinedPredicate().forMethod(method)); .filter(spec.combinedPredicate().forMethod(method));
publisher = (adapter.isMultiValue() ? Flux.from(publisher).retryWhen(retry) : publisher = (adapter.isMultiValue() ? Flux.from(publisher).retryWhen(retry) :

View File

@ -31,8 +31,8 @@ import java.util.Collections;
* @param predicate a predicate for filtering exceptions from applicable methods * @param predicate a predicate for filtering exceptions from applicable methods
* @param maxAttempts the maximum number of retry attempts * @param maxAttempts the maximum number of retry attempts
* @param delay the base delay after the initial invocation (in milliseconds) * @param delay the base delay after the initial invocation (in milliseconds)
* @param jitterDelay a jitter delay for the next retry attempt (in milliseconds) * @param jitter a jitter value for the next retry attempt (in milliseconds)
* @param delayMultiplier a multiplier for a delay for the next retry attempt * @param multiplier a multiplier for a delay for the next retry attempt
* @param maxDelay the maximum delay for any retry attempt (in milliseconds) * @param maxDelay the maximum delay for any retry attempt (in milliseconds)
* @see AbstractRetryInterceptor#getRetrySpec * @see AbstractRetryInterceptor#getRetrySpec
* @see SimpleRetryInterceptor#SimpleRetryInterceptor(MethodRetrySpec) * @see SimpleRetryInterceptor#SimpleRetryInterceptor(MethodRetrySpec)
@ -44,8 +44,8 @@ public record MethodRetrySpec(
MethodRetryPredicate predicate, MethodRetryPredicate predicate,
int maxAttempts, int maxAttempts,
long delay, long delay,
long jitterDelay, long jitter,
double delayMultiplier, double multiplier,
long maxDelay) { long maxDelay) {
public MethodRetrySpec(MethodRetryPredicate predicate, int maxAttempts, long delay) { public MethodRetrySpec(MethodRetryPredicate predicate, int maxAttempts, long delay) {
@ -53,10 +53,10 @@ public record MethodRetrySpec(
} }
public MethodRetrySpec(MethodRetryPredicate predicate, int maxAttempts, long delay, public MethodRetrySpec(MethodRetryPredicate predicate, int maxAttempts, long delay,
long jitterDelay, double delayMultiplier, long maxDelay) { long jitter, double multiplier, long maxDelay) {
this(Collections.emptyList(), Collections.emptyList(), predicate, maxAttempts, delay, this(Collections.emptyList(), Collections.emptyList(), predicate, maxAttempts, delay,
jitterDelay, delayMultiplier, maxDelay); jitter, multiplier, maxDelay);
} }

View File

@ -60,8 +60,8 @@ public class RetryAnnotationInterceptor extends AbstractRetryInterceptor {
retrySpec = new MethodRetrySpec( retrySpec = new MethodRetrySpec(
Arrays.asList(retryable.includes()), Arrays.asList(retryable.excludes()), Arrays.asList(retryable.includes()), Arrays.asList(retryable.excludes()),
instantiatePredicate(retryable.predicate()), retryable.maxAttempts(), instantiatePredicate(retryable.predicate()), retryable.maxAttempts(),
retryable.delay(), retryable.jitterDelay(), retryable.delay(), retryable.jitter(),
retryable.delayMultiplier(), retryable.maxDelay()); retryable.multiplier(), retryable.maxDelay());
MethodRetrySpec existing = this.retrySpecCache.putIfAbsent(cacheKey, retrySpec); MethodRetrySpec existing = this.retrySpecCache.putIfAbsent(cacheKey, retrySpec);
return (existing != null ? existing : retrySpec); return (existing != null ? existing : retrySpec);

View File

@ -97,44 +97,44 @@ public @interface Retryable {
* The base delay after the initial invocation in milliseconds. * The base delay after the initial invocation in milliseconds.
* If a multiplier is specified, this serves as the initial delay to multiply from. * If a multiplier is specified, this serves as the initial delay to multiply from.
* <p>The default is 1000. * <p>The default is 1000.
* @see #jitterDelay() * @see #jitter()
* @see #delayMultiplier() * @see #multiplier()
* @see #maxDelay() * @see #maxDelay()
*/ */
long delay() default 1000; long delay() default 1000;
/** /**
* A jitter delay for the base retry attempt (in milliseconds), randomly * A jitter value (in milliseconds) for the base retry attempt, randomly
* subtracted or added to the calculated delay, resulting in a value * subtracted or added to the calculated delay, resulting in a value between
* between {@code delay - jitterDelay} and {@code delay + jitterDelay} * {@code delay - jitter} and {@code delay + jitter} but never below the base
* but never below the base {@link #delay()} or above {@link #maxDelay()}. * {@link #delay()} or above {@link #maxDelay()}.
* If a multiplier is specified, it applies to the jitter delay as well. * <p>If a multiplier is specified, it is applied to the jitter value as well.
* <p>The default is 0 (no jitter). * <p>The default is 0 (no jitter).
* @see #delay() * @see #delay()
* @see #delayMultiplier() * @see #multiplier()
* @see #maxDelay() * @see #maxDelay()
*/ */
long jitterDelay() default 0; long jitter() default 0;
/** /**
* A multiplier for a delay for the next retry attempt, applied * A multiplier for a delay for the next retry attempt, applied
* to the previous delay (starting with {@link #delay()}) as well * to the previous delay (starting with {@link #delay()}) as well
* as to the applicable {@link #jitterDelay()} for each attempt. * as to the applicable {@link #jitter()} for each attempt.
* <p>The default is 1.0, effectively resulting in a fixed delay. * <p>The default is 1.0, effectively resulting in a fixed delay.
* @see #delay() * @see #delay()
* @see #jitterDelay() * @see #jitter()
* @see #maxDelay() * @see #maxDelay()
*/ */
double delayMultiplier() default 1.0; double multiplier() default 1.0;
/** /**
* The maximum delay for any retry attempt (in milliseconds), limiting * The maximum delay for any retry attempt (in milliseconds), limiting
* how far {@link #jitterDelay()} and {@link #delayMultiplier()} can * how far {@link #jitter()} and {@link #multiplier()} can increase the
* increase the {@linkplain #delay() delay}. * {@linkplain #delay() delay}.
* <p>The default is unlimited. * <p>The default is unlimited.
* @see #delay() * @see #delay()
* @see #jitterDelay() * @see #jitter()
* @see #delayMultiplier() * @see #multiplier()
*/ */
long maxDelay() default Integer.MAX_VALUE; long maxDelay() default Integer.MAX_VALUE;

View File

@ -152,7 +152,7 @@ public class ReactiveRetryInterceptorTests {
} }
@Retryable(delay = 10, jitterDelay = 5, delayMultiplier = 2.0, maxDelay = 40, @Retryable(delay = 10, jitter = 5, multiplier = 2.0, maxDelay = 40,
includes = IOException.class, excludes = AccessDeniedException.class, includes = IOException.class, excludes = AccessDeniedException.class,
predicate = CustomPredicate.class) predicate = CustomPredicate.class)
public static class AnnotatedClassBean { public static class AnnotatedClassBean {

View File

@ -135,7 +135,7 @@ public class RetryInterceptorTests {
} }
@Retryable(delay = 10, jitterDelay = 5, delayMultiplier = 2.0, maxDelay = 40, @Retryable(delay = 10, jitter = 5, multiplier = 2.0, maxDelay = 40,
includes = IOException.class, excludes = AccessDeniedException.class, includes = IOException.class, excludes = AccessDeniedException.class,
predicate = CustomPredicate.class) predicate = CustomPredicate.class)
public static class AnnotatedClassBean { public static class AnnotatedClassBean {