public final class RetryPolicy extends Object
| Constructor and Description |
|---|
RetryPolicy()
Creates a retry policy that retries forever with no delay between retries.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
allowsRetries()
Returns whether the policy allows any retries based on the configured maxRetries and maxDuration.
|
boolean |
allowsRetriesFor(Object result,
Throwable failure)
Returns whether the policy will allow retries for the
failure. |
Duration |
getDelay()
Returns the delay between retries.
|
double |
getDelayMultiplier()
Returns the delay multiplier for backoff retries.
|
Duration |
getMaxDelay()
Returns the max delay between backoff retries.
|
Duration |
getMaxDuration()
Returns the max duration to perform retries for.
|
int |
getMaxRetries()
Returns the max retries.
|
RetryPolicy |
retryOn(Class<? extends Throwable>... failures)
Specifies the failures to retry on.
|
RetryPolicy |
retryOn(Predicate<? extends Throwable> failurePredicate)
Specifies when a retry should occur for a particular failure.
|
<T> RetryPolicy |
retryWhen(BiPredicate<T,? extends Throwable> completionPredicate)
Specifies when a retry should occur for a particular result and failure.
|
<T> RetryPolicy |
retryWhen(Predicate<T> resultPredicate)
Specifies when a retry should occur for a particular result.
|
<T> RetryPolicy |
retryWhen(T result)
Specifies when a retry should occur for a particular result.
|
RetryPolicy |
withBackoff(long delay,
long maxDelay,
TimeUnit timeUnit)
Sets the
delay between retries, exponentially backing of to the maxDelay and multiplying successive
delays by a factor of 2. |
RetryPolicy |
withBackoff(long delay,
long maxDelay,
TimeUnit timeUnit,
double delayMultiplier)
Sets the
delay between retries, exponentially backing of to the maxDelay and multiplying successive
delays by the delayMultiplier. |
RetryPolicy |
withDelay(long delay,
TimeUnit timeUnit)
Sets the
delay between retries. |
RetryPolicy |
withMaxDuration(long maxDuration,
TimeUnit timeUnit)
Sets the max duration to perform retries for.
|
RetryPolicy |
withMaxRetries(int maxRetries)
Sets the max number of retries to perform.
|
public RetryPolicy()
public boolean allowsRetries()
public boolean allowsRetriesFor(Object result, Throwable failure)
failure. Order of precedence follows
allowsRetries(), retryWhen(BiPredicate), retryOn(Predicate), retryOn(Class...),
retryWhen(Predicate), retryWhen(Object).public Duration getDelay()
Duration.NONE.withDelay(long, TimeUnit),
withBackoff(long, long, TimeUnit),
#withBackoff(long, long, TimeUnit, int)public double getDelayMultiplier()
#withBackoff(long, long, TimeUnit, int)public Duration getMaxDelay()
withBackoff(long, long, TimeUnit)public Duration getMaxDuration()
withMaxDuration(long, TimeUnit)public int getMaxRetries()
withMaxRetries(int)public RetryPolicy retryOn(Class<? extends Throwable>... failures)
failures will be retried.NullPointerException - if failures is nullIllegalArgumentException - if failures is emptypublic RetryPolicy retryOn(Predicate<? extends Throwable> failurePredicate)
retryPredicate returns true then
retries may be performed, else the failure will be re-thrown. Supercedes retryOn(Class...).NullPointerException - if failurePredicate is nullpublic <T> RetryPolicy retryWhen(T result)
result then retries may
be performed, else the result will be returned.public <T> RetryPolicy retryWhen(Predicate<T> resultPredicate)
resultPredicate returns true then
retries may be performed, else the result will be returned. Supercedes retryWhen(Object).NullPointerException - if failurePredicate is nullpublic <T> RetryPolicy retryWhen(BiPredicate<T,? extends Throwable> completionPredicate)
completionPredicate returns
true then retries may be performed, else the failure will be re-thrown or the result returned. Supercedes all other
retryOn and retryWhen methods.NullPointerException - if completionPredicate is nullpublic RetryPolicy withBackoff(long delay, long maxDelay, TimeUnit timeUnit)
delay between retries, exponentially backing of to the maxDelay and multiplying successive
delays by a factor of 2.NullPointerException - if timeUnit is nullIllegalArgumentException - if delay is <= 0 or delay is >= maxDelaypublic RetryPolicy withBackoff(long delay, long maxDelay, TimeUnit timeUnit, double delayMultiplier)
delay between retries, exponentially backing of to the maxDelay and multiplying successive
delays by the delayMultiplier.NullPointerException - if timeUnit is nullIllegalStateException - if delay is >= the maxDurationIllegalArgumentException - if delay <= 0, delay is >= maxDelay, or the
delayMultiplier is <= 1public RetryPolicy withDelay(long delay, TimeUnit timeUnit)
delay between retries.NullPointerException - if timeUnit is nullIllegalArgumentException - if delay <= 0IllegalStateException - if delay is >= the maxDuration, or backoff delays have already been set via
#withBackoff(Duration, Duration) or #withBackoff(Duration, Duration, int)public RetryPolicy withMaxDuration(long maxDuration, TimeUnit timeUnit)
NullPointerException - if timeUnit is nullIllegalStateException - if maxDuration is <= the delaypublic RetryPolicy withMaxRetries(int maxRetries)
IllegalArgumentException - if maxRetries < -1Copyright © 2015. All Rights Reserved.