public class RetryPolicies
extends java.lang.Object
A collection of useful implementations of RetryPolicy.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
RetryPolicies.MultipleLinearRandomRetry |
Given pairs of number of retries and sleep time (n0, t0), (n1, t1), ...,
the first n0 retries sleep t0 milliseconds on average,
the following n1 retries sleep t1 milliseconds on average, and so on.
|
| Modifier and Type | Field | Description |
|---|---|---|
static org.slf4j.Logger |
LOG |
|
static RetryPolicy |
RETRY_FOREVER |
Keep trying forever.
|
static RetryPolicy |
TRY_ONCE_THEN_FAIL |
Try once, and fail by re-throwing the exception.
|
| Constructor | Description |
|---|---|
RetryPolicies() |
| Modifier and Type | Method | Description |
|---|---|---|
static RetryPolicy |
exponentialBackoffRetry(int maxRetries,
long sleepTime,
java.util.concurrent.TimeUnit timeUnit) |
Keep trying a limited number of times, waiting a growing amount of time between attempts,
and then fail by re-throwing the exception.
|
static RetryPolicy |
failoverOnNetworkException(int maxFailovers) |
|
static RetryPolicy |
failoverOnNetworkException(RetryPolicy fallbackPolicy,
int maxFailovers) |
|
static RetryPolicy |
failoverOnNetworkException(RetryPolicy fallbackPolicy,
int maxFailovers,
int maxRetries,
long delayMillis,
long maxDelayBase) |
|
static RetryPolicy |
failoverOnNetworkException(RetryPolicy fallbackPolicy,
int maxFailovers,
long delayMillis,
long maxDelayBase) |
|
static RetryPolicy |
retryByException(RetryPolicy defaultPolicy,
java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap) |
Set a default policy with some explicit handlers for specific exceptions.
|
static RetryPolicy |
retryByRemoteException(RetryPolicy defaultPolicy,
java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap) |
A retry policy for RemoteException
Set a default policy with some explicit handlers for specific exceptions.
|
static RetryPolicy |
retryForeverWithFixedSleep(long sleepTime,
java.util.concurrent.TimeUnit timeUnit) |
Keep trying forever with a fixed time between attempts.
|
static RetryPolicy |
retryOtherThanRemoteAndSaslException(RetryPolicy defaultPolicy,
java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap) |
A retry policy where RemoteException and SaslException are not retried, other individual
exception types can have RetryPolicy overrides, and any other exception type without an
override is not retried.
|
static RetryPolicy |
retryUpToMaximumCountWithFixedSleep(int maxRetries,
long sleepTime,
java.util.concurrent.TimeUnit timeUnit) |
Keep trying a limited number of times, waiting a fixed time between attempts,
and then fail by re-throwing the exception.
|
static RetryPolicy |
retryUpToMaximumCountWithProportionalSleep(int maxRetries,
long sleepTime,
java.util.concurrent.TimeUnit timeUnit) |
Keep trying a limited number of times, waiting a growing amount of time between attempts,
and then fail by re-throwing the exception.
|
static RetryPolicy |
retryUpToMaximumTimeWithFixedSleep(long maxTime,
long sleepTime,
java.util.concurrent.TimeUnit timeUnit) |
Keep trying for a maximum time, waiting a fixed time between attempts,
and then fail by re-throwing the exception.
|
public static final org.slf4j.Logger LOG
public static final RetryPolicy TRY_ONCE_THEN_FAIL
Try once, and fail by re-throwing the exception. This corresponds to having no retry mechanism in place.
public static final RetryPolicy RETRY_FOREVER
Keep trying forever.
public static final RetryPolicy retryForeverWithFixedSleep(long sleepTime, java.util.concurrent.TimeUnit timeUnit)
Keep trying forever with a fixed time between attempts.
sleepTime - sleepTime.timeUnit - timeUnit.public static final RetryPolicy retryUpToMaximumCountWithFixedSleep(int maxRetries, long sleepTime, java.util.concurrent.TimeUnit timeUnit)
Keep trying a limited number of times, waiting a fixed time between attempts, and then fail by re-throwing the exception.
maxRetries - maxRetries.sleepTime - sleepTime.timeUnit - timeUnit.public static final RetryPolicy retryUpToMaximumTimeWithFixedSleep(long maxTime, long sleepTime, java.util.concurrent.TimeUnit timeUnit)
Keep trying for a maximum time, waiting a fixed time between attempts, and then fail by re-throwing the exception.
timeUnit - timeUnit.sleepTime - sleepTime.maxTime - maxTime.public static final RetryPolicy retryUpToMaximumCountWithProportionalSleep(int maxRetries, long sleepTime, java.util.concurrent.TimeUnit timeUnit)
Keep trying a limited number of times, waiting a growing amount of time between attempts,
and then fail by re-throwing the exception.
The time between attempts is sleepTime mutliplied by the number of tries so far.
sleepTime - sleepTime.maxRetries - maxRetries.timeUnit - timeUnit.public static final RetryPolicy exponentialBackoffRetry(int maxRetries, long sleepTime, java.util.concurrent.TimeUnit timeUnit)
Keep trying a limited number of times, waiting a growing amount of time between attempts,
and then fail by re-throwing the exception.
The time between attempts is sleepTime mutliplied by a random
number in the range of [0, 2 to the number of retries)
timeUnit - timeUnit.maxRetries - maxRetries.sleepTime - sleepTime.public static final RetryPolicy retryByException(RetryPolicy defaultPolicy, java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap)
Set a default policy with some explicit handlers for specific exceptions.
exceptionToPolicyMap - exceptionToPolicyMap.defaultPolicy - defaultPolicy.public static final RetryPolicy retryByRemoteException(RetryPolicy defaultPolicy, java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap)
A retry policy for RemoteException Set a default policy with some explicit handlers for specific exceptions.
defaultPolicy - defaultPolicy.exceptionToPolicyMap - exceptionToPolicyMap.public static final RetryPolicy retryOtherThanRemoteAndSaslException(RetryPolicy defaultPolicy, java.util.Map<java.lang.Class<? extends java.lang.Exception>,RetryPolicy> exceptionToPolicyMap)
A retry policy where RemoteException and SaslException are not retried, other individual exception types can have RetryPolicy overrides, and any other exception type without an override is not retried.
defaultPolicy - defaultPolicy.exceptionToPolicyMap - exceptionToPolicyMap.public static final RetryPolicy failoverOnNetworkException(int maxFailovers)
public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers)
public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers, long delayMillis, long maxDelayBase)
public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers, int maxRetries, long delayMillis, long maxDelayBase)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.