public class DeceleratingWait extends Object implements Wait
A waiter that uses the exponential backoff approach when waiting for a condition. Starting with a minimum wait period, the algorithm waits successively longer on subsequent attempts, increasing the wait time by a small percentage. This allows short waits to be completed quickly while reducing the overhead for repeated checks during long waits.
The expected number of checks grows logarithmically with the wait duration, while the wait duration remains within a constant factor of the actual time until the condition holds true.
| Constructor and Description |
|---|
DeceleratingWait() |
DeceleratingWait(Timeout timeout) |
DeceleratingWait(Timeout timeout,
double timeoutFactor) |
DeceleratingWait(Timeout timeout,
double timeoutFactor,
WaitFailStrategy failStrategy) |
DeceleratingWait(Timeout timeout,
WaitFailStrategy failStrategy) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
nowMillis()
Return the current time in milliseconds.
|
protected void |
sleep(long millis)
Sleep the given number of milliseconds.
|
String |
toString() |
<F,T> T |
until(F input,
com.google.common.base.Function<? super F,T> stateQuery)
Wait until the given input passes its state query without ignorable exception.
|
<F,T> T |
until(F input,
com.google.common.base.Function<? super F,T> stateQuery,
org.hamcrest.Matcher<? super T> matcher)
Wait until an expectation is met.
|
<F,T> T |
until(String message,
F input,
com.google.common.base.Function<? super F,T> stateQuery,
org.hamcrest.Matcher<? super T> matcher)
Wait until an expectation is met.
|
public DeceleratingWait()
public DeceleratingWait(@Nonnull Timeout timeout, @Nonnegative double timeoutFactor)
public DeceleratingWait(@Nonnull Timeout timeout, @Nonnull WaitFailStrategy failStrategy)
public DeceleratingWait(@Nonnull Timeout timeout, @Nonnegative double timeoutFactor, @Nonnull WaitFailStrategy failStrategy)
protected long nowMillis()
protected void sleep(long millis)
throws InterruptedException
millis - how long to sleepInterruptedException - if the current thread has been interruptedpublic final <F,T> T until(@Nonnull F input, @Nonnull com.google.common.base.Function<? super F,T> stateQuery)
WaitWait until the given input passes its state query without ignorable exception.
This call is equal to:
until(null, input, stateQuery, null)
until in interface WaitF - the input typeT - the return type of the state queryinput - the input to pass to the query function; if implementing SelfDescribing the
description of input will be queried on failurestateQuery - the function to query the state of input; if implementing SelfDescribing the
description of stateQuery will be queried on failureIgnorableStateQueryExceptionpublic <F,T> T until(@Nonnull F input, @Nonnull com.google.common.base.Function<? super F,T> stateQuery, @Nullable org.hamcrest.Matcher<? super T> matcher)
WaitWait until an expectation is met. Validate the expectation with decelerating polling intervals.
until in interface WaitF - the input typeT - the return type of the state queryinput - the input to pass to the query function; if implementing SelfDescribing the
description of input will be queried on failurestateQuery - the function to query the state of input; if implementing SelfDescribing the
description of stateQuery will be queried on failurematcher - the matcher to validate the result of the query; null to match any returned valuepublic <F,T> T until(@Nullable String message, @Nonnull F input, @Nonnull com.google.common.base.Function<? super F,T> stateQuery, @Nullable org.hamcrest.Matcher<? super T> matcher)
WaitWait until an expectation is met. Validate the expectation with decelerating polling intervals.
until in interface WaitF - the input typeT - the return type of the state querymessage - the message to print on failure; null for no additional messageinput - the input to pass to the query function; if implementing SelfDescribing the
description of input will be queried on failurestateQuery - the function to query the state of input; if implementing SelfDescribing the
description of stateQuery will be queried on failurematcher - the matcher to validate the result of the query; null to match any returned valueCopyright © 2011-2017 CoreMedia AG. All Rights Reserved.