Interface FaultTolerance.Builder.RetryBuilder<T,R>
-
- Enclosing interface:
- FaultTolerance.Builder<T,R>
public static interface FaultTolerance.Builder.RetryBuilder<T,R>Configures a retry.- See Also:
@Retry
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceFaultTolerance.Builder.RetryBuilder.CustomBackoffBuilder<T,R>Configures a custom backoff for retry.static interfaceFaultTolerance.Builder.RetryBuilder.ExponentialBackoffBuilder<T,R>Configures an exponential backoff for retry.static interfaceFaultTolerance.Builder.RetryBuilder.FibonacciBackoffBuilder<T,R>Configures a Fibonacci backoff for retry.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default FaultTolerance.Builder.RetryBuilder<T,R>abortOn(Class<? extends Throwable> value)Equivalent toabortOn(Collections.singleton(value)).FaultTolerance.Builder.RetryBuilder<T,R>abortOn(Collection<Class<? extends Throwable>> value)Sets the set of exception types considered success.FaultTolerance.Builder.RetryBuilder<T,R>delay(long value, ChronoUnit unit)Sets the delay between retries.FaultTolerance.Builder<T,R>done()Returns the original fault tolerance builder.FaultTolerance.Builder.RetryBuilder<T,R>jitter(long value, ChronoUnit unit)Sets the jitter bound.FaultTolerance.Builder.RetryBuilder<T,R>maxDuration(long value, ChronoUnit unit)Sets the maximum duration of all invocations, including possible retries.FaultTolerance.Builder.RetryBuilder<T,R>maxRetries(int value)Sets the maximum number of retries.FaultTolerance.Builder.RetryBuilder<T,R>onFailure(Runnable callback)Sets a callback that will be invoked when this retry strategy treats a finished invocation as failure, and no more retries will be attempted.FaultTolerance.Builder.RetryBuilder<T,R>onRetry(Runnable callback)Sets a callback that will be invoked when a retry is attempted.FaultTolerance.Builder.RetryBuilder<T,R>onSuccess(Runnable callback)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.default FaultTolerance.Builder.RetryBuilder<T,R>retryOn(Class<? extends Throwable> value)Equivalent toretryOn(Collections.singleton(value)).FaultTolerance.Builder.RetryBuilder<T,R>retryOn(Collection<Class<? extends Throwable>> value)Sets the set of exception types considered failure.default FaultTolerance.Builder.RetryBuilder<T,R>when(Predicate<Throwable> value)Deprecated, for removal: This API element is subject to removal in a future version.FaultTolerance.Builder.RetryBuilder<T,R>whenException(Predicate<Throwable> value)Sets a predicate to determine when an exception should be considered failure and retry should be attempted.FaultTolerance.Builder.RetryBuilder<T,R>whenResult(Predicate<Object> value)Sets a predicate to determine when a result should be considered failure and retry should be attempted.default FaultTolerance.Builder.RetryBuilder<T,R>with(Consumer<FaultTolerance.Builder.RetryBuilder<T,R>> consumer)FaultTolerance.Builder.RetryBuilder.CustomBackoffBuilder<T,R>withCustomBackoff()Configures retry to use a custom backoff instead of the default constant backoff.FaultTolerance.Builder.RetryBuilder.ExponentialBackoffBuilder<T,R>withExponentialBackoff()Configures retry to use an exponential backoff instead of the default constant backoff.FaultTolerance.Builder.RetryBuilder.FibonacciBackoffBuilder<T,R>withFibonacciBackoff()Configures retry to use a Fibonacci backoff instead of the default constant backoff.
-
-
-
Method Detail
-
maxRetries
FaultTolerance.Builder.RetryBuilder<T,R> maxRetries(int value)
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:
@Retry.maxRetries
-
delay
FaultTolerance.Builder.RetryBuilder<T,R> delay(long value, ChronoUnit unit)
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:
@Retry.delay,@Retry.delayUnit
-
maxDuration
FaultTolerance.Builder.RetryBuilder<T,R> maxDuration(long value, ChronoUnit unit)
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:
@Retry.maxDuration,@Retry.durationUnit
-
jitter
FaultTolerance.Builder.RetryBuilder<T,R> jitter(long value, ChronoUnit unit)
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:
@Retry.jitter,@Retry.jitterDelayUnit
-
retryOn
FaultTolerance.Builder.RetryBuilder<T,R> retryOn(Collection<Class<? extends Throwable>> value)
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:
@Retry.retryOn
-
retryOn
default FaultTolerance.Builder.RetryBuilder<T,R> retryOn(Class<? extends Throwable> value)
Equivalent toretryOn(Collections.singleton(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this retry builder
-
abortOn
FaultTolerance.Builder.RetryBuilder<T,R> abortOn(Collection<Class<? extends Throwable>> value)
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:
@Retry.abortOn
-
abortOn
default FaultTolerance.Builder.RetryBuilder<T,R> abortOn(Class<? extends Throwable> value)
Equivalent toabortOn(Collections.singleton(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this retry builder
-
whenResult
FaultTolerance.Builder.RetryBuilder<T,R> whenResult(Predicate<Object> value)
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
-
when
@Deprecated(forRemoval=true) default FaultTolerance.Builder.RetryBuilder<T,R> when(Predicate<Throwable> value)
Deprecated, for removal: This API element is subject to removal in a future version.
-
whenException
FaultTolerance.Builder.RetryBuilder<T,R> whenException(Predicate<Throwable> value)
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
-
withExponentialBackoff
FaultTolerance.Builder.RetryBuilder.ExponentialBackoffBuilder<T,R> 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:
@ExponentialBackoff
-
withFibonacciBackoff
FaultTolerance.Builder.RetryBuilder.FibonacciBackoffBuilder<T,R> 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:
@FibonacciBackoff
-
withCustomBackoff
FaultTolerance.Builder.RetryBuilder.CustomBackoffBuilder<T,R> 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:
@CustomBackoff
-
onRetry
FaultTolerance.Builder.RetryBuilder<T,R> onRetry(Runnable callback)
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
FaultTolerance.Builder.RetryBuilder<T,R> onSuccess(Runnable callback)
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
FaultTolerance.Builder.RetryBuilder<T,R> onFailure(Runnable callback)
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
FaultTolerance.Builder<T,R> done()
Returns the original fault tolerance builder.- Returns:
- the original fault tolerance builder
-
with
default FaultTolerance.Builder.RetryBuilder<T,R> with(Consumer<FaultTolerance.Builder.RetryBuilder<T,R>> consumer)
-
-