/** * Creates a Retry with default configuration. * * @param id the ID of the Retry * @return a Retry with default configuration */ static AsyncRetry ofDefaults(String id){ return of(id, RetryConfig.ofDefaults()); }
public RetryConfig build() { buildExceptionPredicate(); RetryConfig config = new RetryConfig(); config.intervalFunction = intervalFunction; config.maxAttempts = maxAttempts; config.exceptionPredicate = exceptionPredicate; config.resultPredicate = resultPredicate; return config; }
static IntervalFunction ofExponentialBackoff(long initialIntervalMillis, double multiplier) { checkMultiplier(multiplier); return of(initialIntervalMillis, (x) -> (long) (x * multiplier)); }
@Test() public void shouldUseIgnoreExceptionToBuildPredicate() { RetryConfig retryConfig = RetryConfig.custom() .ignoreExceptions(RuntimeException.class, ExtendsExtendsException.class).build(); final Predicate<? super Throwable> failurePredicate = retryConfig.getExceptionPredicate(); then(failurePredicate.test(new Exception())).isEqualTo(true); // not explicitly excluded then(failurePredicate.test(new ExtendsError())).isEqualTo(true); // not explicitly excluded then(failurePredicate.test(new ExtendsException())).isEqualTo(true); // not explicitly excluded then(failurePredicate.test(new ExtendsException2())).isEqualTo(true); // not explicitly excluded then(failurePredicate.test(new RuntimeException())).isEqualTo(false); // explicitly excluded then(failurePredicate.test(new ExtendsRuntimeException())).isEqualTo(false); // inherits excluded from ExtendsException then(failurePredicate.test(new ExtendsExtendsException())).isEqualTo(false); // explicitly excluded }
@Test(expected = IllegalArgumentException.class) public void zeroMaxAttemptsShouldFail() { RetryConfig.custom().maxAttempts(0).build(); }
static IntervalFunction ofExponentialRandomBackoff( long initialIntervalMillis, double multiplier, double randomizationFactor ) { checkInterval(initialIntervalMillis); checkMultiplier(multiplier); checkRandomizationFactor(randomizationFactor); return (attempt) -> { checkAttempt(attempt); final long interval = of(initialIntervalMillis, (x) -> (long) (x * multiplier)).apply(attempt); return (long) randomize(interval, randomizationFactor); }; }
RetrySubscriber(Subscriber<? super T> actual, long count, SubscriptionArbiter sa, Publisher<? extends T> source, Retry retry) { this.actual = actual; this.sa = sa; this.source = source; this.context = retry.context(); this.remaining = count; }
static IntervalFunction ofRandomized(long intervalMillis, double randomizationFactor) { checkInterval(intervalMillis); checkRandomizationFactor(randomizationFactor); return (attempt) -> { checkAttempt(attempt); return (long) randomize(intervalMillis, randomizationFactor); }; }
public DecorateSupplier<T> withRetry(Retry retryContext) { supplier = Retry.decorateSupplier(retryContext, supplier); return this; }
public DecorateCompletionStage<T> withRetry(AsyncRetry retryContext, ScheduledExecutorService scheduler) { stageSupplier = AsyncRetry.decorateCompletionStage(retryContext, scheduler, stageSupplier); return this; }
public DecorateRunnable withRetry(Retry retryContext) { runnable = Retry.decorateRunnable(retryContext, runnable); return this; }
static IntervalFunction of(long intervalMillis) { checkInterval(intervalMillis); return (attempt) -> { checkAttempt(attempt); return intervalMillis; }; }
static IntervalFunction ofExponentialRandomBackoff( long initialIntervalMillis ) { return ofExponentialRandomBackoff(initialIntervalMillis, DEFAULT_MULTIPLIER); }
public DecorateCheckedSupplier<T> withRetry(Retry retryContext) { supplier = Retry.decorateCheckedSupplier(retryContext, supplier); return this; }
public DecorateCheckedRunnable withRetry(Retry retryContext) { runnable = Retry.decorateCheckedRunnable(retryContext, runnable); return this; }
static IntervalFunction ofRandomized() { return ofRandomized(DEFAULT_INITIAL_INTERVAL, DEFAULT_RANDOMIZATION_FACTOR); }
/** * Returns a builder to create a custom RetryConfig. * * @return a {@link Builder} */ public static <T> Builder<T> custom() { return new Builder<>(); }
public DecorateFunction<T, R> withRetry(Retry retryContext) { function = Retry.decorateFunction(retryContext, function); return this; }
public DecorateCheckedFunction<T, R> withRetry(Retry retryContext) { function = Retry.decorateCheckedFunction(retryContext, function); return this; }