Interface TypedGuard.Builder.RetryBuilder<T>
- Enclosing interface:
TypedGuard.Builder<T>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceConfigures a custom backoff for retry.static interfaceConfigures an exponential backoff for retry.static interfaceConfigures a Fibonacci backoff for retry. -
Method Summary
Modifier and TypeMethodDescriptionEquivalent toabortOn(Set.of(value)).abortOn(Collection<Class<? extends Throwable>> value) Sets the set of exception types considered success.beforeRetry(Runnable value) Sets a before retry handler, which is called before each retry, but not before the original attempt.beforeRetry(Consumer<Throwable> value) Sets a before retry handler, which is called before each retry, but not before the original attempt.delay(long value, ChronoUnit unit) Sets the delay between retries.done()Returns the original fault tolerance builder.jitter(long value, ChronoUnit unit) Sets the jitter bound.maxDuration(long value, ChronoUnit unit) Sets the maximum duration of all invocations, including possible retries.maxRetries(int value) Sets the maximum number of retries.Sets a callback that will be invoked when this retry strategy treats a finished invocation as failure, and no more retries will be attempted.Sets a callback that will be invoked when a retry is attempted.Sets a callback that will be invoked when this retry strategy treats a finished invocation as success, regardless of whether a retry was attempted or not.Equivalent toretryOn(Set.of(value)).retryOn(Collection<Class<? extends Throwable>> value) Sets the set of exception types considered failure.whenException(Predicate<Throwable> value) Sets a predicate to determine when an exception should be considered failure and retry should be attempted.whenResult(Predicate<Object> value) Sets a predicate to determine when a result should be considered failure and retry should be attempted.default TypedGuard.Builder.RetryBuilder<T> with(Consumer<TypedGuard.Builder.RetryBuilder<T>> consumer) Configures retry to use a custom backoff instead of the default constant backoff.Configures retry to use an exponential backoff instead of the default constant backoff.Configures retry to use a Fibonacci backoff instead of the default constant backoff.
-
Method Details
-
maxRetries
Sets the maximum number of retries. Defaults to 3.- Parameters:
value- the maximum number of retries, must be >= -1.- Returns:
- this retry builder
- See Also:
-
delay
Sets the delay between retries. Defaults to 0.- Parameters:
value- the delay length, must be >= 0unit- the delay unit, must not benull- Returns:
- this retry builder
- See Also:
-
maxDuration
Sets the maximum duration of all invocations, including possible retries. Defaults to 3 minutes.- Parameters:
value- the maximum duration length, must be >= 0unit- the maximum duration unit, must not benull- Returns:
- this retry builder
- See Also:
-
jitter
Sets the jitter bound. Random value in the range from-jitterto+jitterwill be added to the delay between retry attempts. Defaults to 200 millis.- Parameters:
value- the jitter bound length, must be >= 0unit- the jitter bound unit, must not benull- Returns:
- this retry builder
- See Also:
-
retryOn
Sets the set of exception types considered failure. Defaults to all exceptions (Exception).- Parameters:
value- collection of exception types, must not benull- Returns:
- this retry builder
- See Also:
-
retryOn
Equivalent toretryOn(Set.of(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this retry builder
-
abortOn
Sets the set of exception types considered success. Defaults to no exception (empty set).- Parameters:
value- collection of exception types, must not benull- Returns:
- this retry builder
- See Also:
-
abortOn
Equivalent toabortOn(Set.of(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this retry builder
-
whenResult
Sets a predicate to determine when a result should be considered failure and retry should be attempted. All results that do not match this predicate are implicitly considered success.- Parameters:
value- the predicate, must not benull- Returns:
- this retry builder
-
whenException
Sets a predicate to determine when an exception should be considered failure and retry should be attempted. This is a more general variant ofretryOn. Note that there is no generalizedabortOn, because all exceptions that do not match this predicate are implicitly considered success.If this method is called,
retryOnandabortOnmay not be called.- Parameters:
value- the predicate, must not benull- Returns:
- this retry builder
- See Also:
-
beforeRetry
Sets a before retry handler, which is called before each retry, but not before the original attempt.- Parameters:
value- the before retry handler, must not benull- Returns:
- this retry builder
- See Also:
-
beforeRetry
Sets a before retry handler, which is called before each retry, but not before the original attempt.- Parameters:
value- the before retry handler, must not benull- Returns:
- this retry builder
-
withExponentialBackoff
TypedGuard.Builder.RetryBuilder.ExponentialBackoffBuilder<T> withExponentialBackoff()Configures retry to use an exponential backoff instead of the default constant backoff.Only one backoff strategy may be configured, so calling
withFibonacciBackoff()orwithCustomBackoff()in addition to this method leads to an exception duringdone().- Returns:
- the exponential backoff builder
- See Also:
-
withFibonacciBackoff
TypedGuard.Builder.RetryBuilder.FibonacciBackoffBuilder<T> withFibonacciBackoff()Configures retry to use a Fibonacci backoff instead of the default constant backoff.Only one backoff strategy may be configured, so calling
withExponentialBackoff()orwithCustomBackoff()in addition to this method leads to an exception duringdone().- Returns:
- the Fibonacci backoff builder
- See Also:
-
withCustomBackoff
TypedGuard.Builder.RetryBuilder.CustomBackoffBuilder<T> withCustomBackoff()Configures retry to use a custom backoff instead of the default constant backoff.Only one backoff strategy may be configured, so calling
withExponentialBackoff()orwithFibonacciBackoff()in addition to this method leads to an exception duringdone().- Returns:
- the custom backoff builder
- See Also:
-
onRetry
Sets a callback that will be invoked when a retry is attempted.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the retried callback, must not benull- Returns:
- this retry builder
-
onSuccess
Sets a callback that will be invoked when this retry strategy treats a finished invocation as success, regardless of whether a retry was attempted or not.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the retried callback, must not benull- Returns:
- this retry builder
-
onFailure
Sets a callback that will be invoked when this retry strategy treats a finished invocation as failure, and no more retries will be attempted. The failure may be caused by depleting the maximum number of retries or the maximum duration, or by an exception that is not retryable.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the retried callback, must not benull- Returns:
- this retry builder
-
done
TypedGuard.Builder<T> done()Returns the original fault tolerance builder.- Returns:
- the original fault tolerance builder
-
with
default TypedGuard.Builder.RetryBuilder<T> with(Consumer<TypedGuard.Builder.RetryBuilder<T>> consumer)
-