Class SimpleWaiter

  • All Implemented Interfaces:
    Waiter

    public class SimpleWaiter
    extends Object
    implements Waiter
    A simple waiter enabling user to wait until a success or a fail condition will be satisfied
    • Constructor Detail

      • SimpleWaiter

        public SimpleWaiter​(BooleanSupplier successCondition)
        Construct new SimpleWaiter with a defined success condition. To perform the wait, you need to call waitFor().
        Parameters:
        successCondition - whenever this supplier will provide true, 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 call waitFor().
        Parameters:
        successCondition - whenever the provided condition will provide true, 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 call waitFor().
        Parameters:
        successCondition - whenever this supplier will provide true, waiting stops.
        timeoutUnit - unit of the timeout
        timeout - 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 call waitFor().
        Parameters:
        successCondition - whenever this supplier will provide true, waiting stops.
        timeoutUnit - unit of the timeout
        timeout - maximum time window in which periodical condition evaluation will be done
        reason - 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:
        timeout in interface Waiter
        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:
        timeout in interface Waiter
        Parameters:
        timeUnit - timeUnit that is converts time t to milliseconds
        t - timeout in timeUnit
        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:
        interval in interface Waiter
        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:
        interval in interface Waiter
        Parameters:
        timeUnit - timeUnit that is converts time t to milliseconds
        t - 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:
        reason in interface Waiter
        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 from Waiter.LogPoint allowing to specify whether the wait start, end, both events or none of them should be logged.
        Specified by:
        logPoint in interface Waiter
        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:
        level in interface Waiter
        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 the Runnable to be executed upon each iteration of the evaluation cycle. This will be run after all conditions were evaluated.
        Specified by:
        onIteration in interface Waiter
        Parameters:
        runnable - code to be executed upon successful waiting.
        Returns:
        instance of this SimpleWaiter
      • onSuccess

        public SimpleWaiter onSuccess​(Runnable runnable)
        Set the Runnable to be executed after the successCondition has been met.
        Specified by:
        onSuccess in interface Waiter
        Parameters:
        runnable - code to be executed upon successful waiting.
        Returns:
        instance of this SimpleWaiter
      • onFailure

        public SimpleWaiter onFailure​(Runnable runnable)
        Set the Runnable to be executed after the failureCondition has been met.
        Specified by:
        onFailure in interface Waiter
        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 a WaiterException. 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:
        failFast in interface Waiter
        Parameters:
        failFast - returns true if waiting has failed.
        Returns:
        instance of this SimpleWaiter
      • onTimeout

        public SimpleWaiter onTimeout​(Runnable runnable)
        Set a Runnable to be executed upon timeout. This will be executed as a last thing outside the evaluation routine before the WaiterException is thrown.
        Specified by:
        onTimeout in interface Waiter
        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:
        waitFor in interface Waiter
        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.