public final class WaitStrategies
extends java.lang.Object
WaitStrategy.| Modifier and Type | Method and Description |
|---|---|
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,
java.util.concurrent.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,
java.util.concurrent.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,
java.util.concurrent.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,
java.util.concurrent.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,
java.util.concurrent.TimeUnit timeUnit)
Returns a wait strategy that sleeps a fixed amount of time before retrying.
|
static WaitStrategy |
incrementingWait(long initialSleepTime,
java.util.concurrent.TimeUnit initialSleepTimeUnit,
long increment,
java.util.concurrent.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 |
noWait()
Returns a wait strategy that doesn't sleep at all before retrying.
|
static WaitStrategy |
randomWait(long maximumTime,
java.util.concurrent.TimeUnit timeUnit)
Returns a strategy that sleeps a random amount of time before retrying.
|
static WaitStrategy |
randomWait(long minimumTime,
java.util.concurrent.TimeUnit minimumTimeUnit,
long maximumTime,
java.util.concurrent.TimeUnit maximumTimeUnit)
Returns a strategy that sleeps a random amount of time before retrying.
|
public static WaitStrategy noWait()
public static WaitStrategy fixedWait(long sleepTime, @Nonnull java.util.concurrent.TimeUnit timeUnit) throws java.lang.IllegalStateException
sleepTime - the time to sleeptimeUnit - the unit of the time to sleepjava.lang.IllegalStateException - if the sleep time is < 0public static WaitStrategy randomWait(long maximumTime, @Nonnull java.util.concurrent.TimeUnit timeUnit)
maximumTime - the maximum time to sleeptimeUnit - the unit of the maximum timejava.lang.IllegalStateException - if the maximum sleep time is <= 0.public static WaitStrategy randomWait(long minimumTime, @Nonnull java.util.concurrent.TimeUnit minimumTimeUnit, long maximumTime, @Nonnull java.util.concurrent.TimeUnit maximumTimeUnit)
minimumTime - the minimum time to sleepminimumTimeUnit - the unit of the minimum timemaximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timejava.lang.IllegalStateException - 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, @Nonnull java.util.concurrent.TimeUnit initialSleepTimeUnit, long increment, @Nonnull java.util.concurrent.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, @Nonnull java.util.concurrent.TimeUnit maximumTimeUnit)
maximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static WaitStrategy exponentialWait(long multiplier, long maximumTime, @Nonnull java.util.concurrent.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, @Nonnull java.util.concurrent.TimeUnit maximumTimeUnit)
maximumTime.maximumTime - the maximum time to sleepmaximumTimeUnit - the unit of the maximum timepublic static WaitStrategy fibonacciWait(long multiplier, long maximumTime, @Nonnull java.util.concurrent.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 time