Package cz.xtf.core.waiting
Class SimpleWaiter
- java.lang.Object
-
- cz.xtf.core.waiting.SimpleWaiter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cz.xtf.core.waiting.Waiter
Waiter.LogPoint
-
-
Field Summary
-
Fields inherited from interface cz.xtf.core.waiting.Waiter
DEFAULT_INTERVAL
-
-
Constructor Summary
Constructors Constructor Description SimpleWaiter(BooleanSupplier successCondition)Construct new SimpleWaiter with a defined success condition.SimpleWaiter(BooleanSupplier successCondition, String reason)Construct new SimpleWaiter with a defined success condition and a reason.SimpleWaiter(BooleanSupplier successCondition, TimeUnit timeoutUnit, long timeout)Construct new SimpleWaiter with a defined success condition and a timeout.SimpleWaiter(BooleanSupplier successCondition, TimeUnit timeoutUnit, long timeout, String reason)Construct new SimpleWaiter with a defined success condition, reason, and a timeout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleWaiterfailFast(FailFastCheck failFast)Set the condition which will be evaluated before other conditions are checked.SimpleWaiterfailureCondition(BooleanSupplier failureCondition)Set a failure condition.SimpleWaiterinterval(long millis)Set the amount of time the wait will rest after checking all the conditions in the evaluation routineSimpleWaiterinterval(TimeUnit timeUnit, long t)Set the amount of time the wait will rest after checking all the conditions in the evaluation routine.SimpleWaiterlevel(org.slf4j.event.Level level)Set the log level of messages produced during this wait.SimpleWaiterlogPoint(Waiter.LogPoint logPoint)Set XTF Waiter specific log configuration.SimpleWaiteronFailure(Runnable runnable)Set theRunnableto be executed after thefailureConditionhas been met.SimpleWaiteronIteration(Runnable runnable)Set theRunnableto be executed upon each iteration of the evaluation cycle.SimpleWaiteronSuccess(Runnable runnable)Set theRunnableto be executed after thesuccessConditionhas been met.SimpleWaiteronTimeout(Runnable runnable)Set aRunnableto be executed upon timeout.SimpleWaiterreason(String reason)Set the description of the reason why this wait is being performed.SimpleWaitertimeout(long millis)Set the maximum time windows in which the periodical evaluation of failure and success conditions will be done.SimpleWaitertimeout(TimeUnit timeUnit, long t)Set the maximum time windows in which the periodical evaluation of failure and success conditions will be done.booleanwaitFor()Waits for the success or a failure condition to be met or the timeout to occur.
-
-
-
Constructor Detail
-
SimpleWaiter
public SimpleWaiter(BooleanSupplier successCondition)
Construct new SimpleWaiter with a defined success condition. To perform the wait, you need to callwaitFor().- Parameters:
successCondition- whenever this supplier will providetrue, waiting stops.
-
SimpleWaiter
public SimpleWaiter(BooleanSupplier successCondition, String reason)
Construct new SimpleWaiter with a defined success condition and a reason. The reason will be used in log messages associated with the wait. To perform the wait, you need to callwaitFor().- Parameters:
successCondition- whenever the provided condition will providetrue, waiting stops.reason- description of the reason why this wait is being performed
-
SimpleWaiter
public SimpleWaiter(BooleanSupplier successCondition, TimeUnit timeoutUnit, long timeout)
Construct new SimpleWaiter with a defined success condition and a timeout. The timeout denotes the maximum time window in which periodical condition evaluation will be done. To perform the wait, you need to callwaitFor().- Parameters:
successCondition- whenever this supplier will providetrue, waiting stops.timeoutUnit- unit of the timeouttimeout- maximum time window in which periodical condition evaluation will be done
-
SimpleWaiter
public SimpleWaiter(BooleanSupplier successCondition, TimeUnit timeoutUnit, long timeout, String reason)
Construct new SimpleWaiter with a defined success condition, reason, and a timeout. The timeout denotes the maximum time window in which periodical condition evaluation will be done. To perform the wait, you need to callwaitFor().- Parameters:
successCondition- whenever this supplier will providetrue, waiting stops.timeoutUnit- unit of the timeouttimeout- maximum time window in which periodical condition evaluation will be donereason- description of the reason why this wait is being performed. Will be used in associated log messages.
-
-
Method Detail
-
failureCondition
public SimpleWaiter failureCondition(BooleanSupplier failureCondition)
Set a failure condition. Note that this condition will be evaluated first when the evaluation routine.- Parameters:
failureCondition- whenever this supplier provides true, the wait will stop.- Returns:
- instance of this
SimpleWaiter
-
timeout
public SimpleWaiter timeout(long millis)
Set the maximum time windows in which the periodical evaluation of failure and success conditions will be done.- Specified by:
timeoutin interfaceWaiter- Parameters:
millis- timeout in milliseconds- Returns:
- instance of this
SimpleWaiter
-
timeout
public SimpleWaiter timeout(TimeUnit timeUnit, long t)
Set the maximum time windows in which the periodical evaluation of failure and success conditions will be done.- Specified by:
timeoutin interfaceWaiter- Parameters:
timeUnit- timeUnit that is converts timetto millisecondst- timeout intimeUnit- Returns:
- instance of this
SimpleWaiter
-
interval
public SimpleWaiter interval(long millis)
Set the amount of time the wait will rest after checking all the conditions in the evaluation routine- Specified by:
intervalin interfaceWaiter- Parameters:
millis- interval in milliseconds- Returns:
- instance of this
SimpleWaiter
-
interval
public SimpleWaiter interval(TimeUnit timeUnit, long t)
Set the amount of time the wait will rest after checking all the conditions in the evaluation routine.- Specified by:
intervalin interfaceWaiter- Parameters:
timeUnit- timeUnit that is converts timetto millisecondst- interval in milliseconds- Returns:
- instance of this
SimpleWaiter
-
reason
public SimpleWaiter reason(String reason)
Set the description of the reason why this wait is being performed. Will be used in associated log messages.- Specified by:
reasonin interfaceWaiter- Parameters:
reason- what the waiters what upon.- Returns:
- instance of this
SimpleWaiter
-
logPoint
public SimpleWaiter logPoint(Waiter.LogPoint logPoint)
Set XTF Waiter specific log configuration. It can be set to any enum value fromWaiter.LogPointallowing to specify whether the wait start, end, both events or none of them should be logged.- Specified by:
logPointin interfaceWaiter- Parameters:
logPoint- what points of waiting should be logged.- Returns:
- instance of this
SimpleWaiter - See Also:
Waiter.LogPoint
-
level
public SimpleWaiter level(org.slf4j.event.Level level)
Set the log level of messages produced during this wait.- Specified by:
levelin interfaceWaiter- Parameters:
level- what level of severity should be used to log the message.- Returns:
- instance of this
SimpleWaiter - See Also:
Level
-
onIteration
public SimpleWaiter onIteration(Runnable runnable)
Set theRunnableto be executed upon each iteration of the evaluation cycle. This will be run after all conditions were evaluated.- Specified by:
onIterationin interfaceWaiter- Parameters:
runnable- code to be executed upon successful waiting.- Returns:
- instance of this
SimpleWaiter
-
onSuccess
public SimpleWaiter onSuccess(Runnable runnable)
Set theRunnableto be executed after thesuccessConditionhas been met.- Specified by:
onSuccessin interfaceWaiter- Parameters:
runnable- code to be executed upon successful waiting.- Returns:
- instance of this
SimpleWaiter
-
onFailure
public SimpleWaiter onFailure(Runnable runnable)
Set theRunnableto be executed after thefailureConditionhas been met.- Specified by:
onFailurein interfaceWaiter- Parameters:
runnable- code to be executed upon successful waiting.- Returns:
- instance of this
SimpleWaiter
-
failFast
public SimpleWaiter failFast(FailFastCheck failFast)
Set the condition which will be evaluated before other conditions are checked. If evaluated to true, the wait will stop with aWaiterException. Note that non-blocking wait with exponential time backoff is used in the evaluation routine for this check meaning that this condition will not be evaluated during each routine cycle because the backoff time gradually increases while the interval is a constant.- Specified by:
failFastin interfaceWaiter- Parameters:
failFast- returns true if waiting has failed.- Returns:
- instance of this
SimpleWaiter
-
onTimeout
public SimpleWaiter onTimeout(Runnable runnable)
Set aRunnableto be executed upon timeout. This will be executed as a last thing outside the evaluation routine before theWaiterExceptionis thrown.- Specified by:
onTimeoutin interfaceWaiter- Parameters:
runnable- code to be executed upon timed out waiting.- Returns:
- instance of this
SimpleWaiter
-
waitFor
public boolean waitFor()
Waits for the success or a failure condition to be met or the timeout to occur.- Specified by:
waitForin interfaceWaiter- Returns:
- true if the success condition is met, false if the failure condition is met
- Throws:
WaiterException- if the timeout occurs, the blocking wait thread is interrupted or a fast fail check is evaluated to true.
-
-