public final class WaitStrategies extends Object
WaitStrategy.| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Throwable> |
exceptionWait(Class<T> exceptionClass,
ExceptionWaitHandler<T> calculator)
Returns a strategy which sleeps for an amount of time based on the Exception that occurred.
|
static WaitStrategy |
exponentialWait()
Returns a strategy which sleeps for an exponential amount of time after the first failed attempt,
and in exponentially incrementing amounts after each failed attempt up to Long.MAX_VALUE.
|
static WaitStrategy |
exponentialWait(long multiplier,
long maximumTime,
TimeUnit maximumTimeUnit)
Returns a strategy which sleeps for an exponential amount of time after the first failed attempt,
and in exponentially incrementing amounts after each failed attempt up to the maximumTime.
|
static WaitStrategy |
exponentialWait(long maximumTime,
TimeUnit maximumTimeUnit)
Returns a strategy which sleeps for an exponential amount of time after the first failed attempt,
and in exponentially incrementing amounts after each failed attempt up to the maximumTime.
|
static WaitStrategy |
fibonacciWait()
Returns a strategy which sleeps for an increasing amount of time after the first failed attempt,
and in Fibonacci increments after each failed attempt up to
Long.MAX_VALUE. |
static WaitStrategy |
fibonacciWait(long multiplier,
long maximumTime,
TimeUnit maximumTimeUnit)
Returns a strategy which sleeps for an increasing amount of time after the first failed attempt,
and in Fibonacci increments after each failed attempt up to the
maximumTime. |
static WaitStrategy |
fibonacciWait(long maximumTime,
TimeUnit maximumTimeUnit)
Returns a strategy which sleeps for an increasing amount of time after the first failed attempt,
and in Fibonacci increments after each failed attempt up to the
maximumTime. |
static WaitStrategy |
fixedWait(long sleepTime,
TimeUnit timeUnit)
Returns a wait strategy that sleeps a fixed amount of time before retrying.
|
static WaitStrategy |
incrementingWait(long initialSleepTime,
TimeUnit initialSleepTimeUnit,
long increment,
TimeUnit incrementTimeUnit)
Returns a strategy that sleeps a fixed amount of time after the first
failed attempt and in incrementing amounts of time after each additional
failed attempt.
|
static WaitStrategy |
join(WaitStrategy... waitStrategies)
Joins one or more wait strategies to derive a composite wait strategy.
|
static WaitStrategy |
noWait()
Returns a wait strategy that doesn't sleep at all before retrying.
|
static WaitStrategy |
randomWait(long maximumTime,
TimeUnit timeUnit)
Returns a strategy that sleeps a random amount of time before retrying.
|
static WaitStrategy |
randomWait(long minimumTime,
TimeUnit minimumTimeUnit,
long maximumTime,
TimeUnit maximumTimeUnit)
Returns a strategy that sleeps a random amount of time before retrying.
|
public static WaitStrategy noWait()
public static WaitStrategy fixedWait(long sleepTime, TimeUnit timeUnit) throws IllegalStateException
sleepTime - the time to sleeptimeUnit - the unit of the time to sleepIllegalStateException - if the sleep time is < 0public static WaitStrategy randomWait(long maximumTime, TimeUnit timeUnit)
maximumTime - the maximum time to sleeptimeUnit - the unit of the maximum timeIllegalStateException - if the maximum sleep time is <= 0.public static WaitStrategy randomWait(long minimumTime, TimeUnit minimumTimeUnit, long maximumTime, TimeUnit maximumTimeUnit)
minimumTime - the minimum time to sleepminimumTimeUnit - the unit of the minimum timemaximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timeIllegalStateException - if the minimum sleep time is < 0, or if the
maximum sleep time is less than (or equals to) the minimum.public static WaitStrategy incrementingWait(long initialSleepTime, TimeUnit initialSleepTimeUnit, long increment, TimeUnit incrementTimeUnit)
initialSleepTime - the time to sleep before retrying the first timeinitialSleepTimeUnit - the unit of the initial sleep timeincrement - the increment added to the previous sleep time after each failed attemptincrementTimeUnit - the unit of the incrementpublic static WaitStrategy exponentialWait()
public static WaitStrategy exponentialWait(long maximumTime, TimeUnit maximumTimeUnit)
maximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static WaitStrategy exponentialWait(long multiplier, long maximumTime, TimeUnit maximumTimeUnit)
multiplier.multiplier - multiply the wait time calculated by thismaximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static WaitStrategy fibonacciWait()
Long.MAX_VALUE.public static WaitStrategy fibonacciWait(long maximumTime, TimeUnit maximumTimeUnit)
maximumTime.maximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static WaitStrategy fibonacciWait(long multiplier, long maximumTime, TimeUnit maximumTimeUnit)
maximumTime.
The wait time between the retries can be controlled by the multiplier.
nextWaitTime = fibonacciIncrement * multiplier.multiplier - multiply the wait time calculated by thismaximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static <T extends Throwable> WaitStrategy exceptionWait(Class<T> exceptionClass, ExceptionWaitHandler<T> calculator)
function determines how the sleep time should be calculated for the given
exceptionClass. If the exception does not match, a wait time of 0 is returned.calculator - calculator to calculate sleep timeexceptionClass - class to calculate sleep time frompublic static WaitStrategy join(WaitStrategy... waitStrategies)
waitStrategies - Wait strategies that need to be applied one after another for computing the sleep time.Copyright © 2019. All rights reserved.