Class Waiter

java.lang.Object
org.apache.hadoop.hbase.Waiter

@Private public final class Waiter extends Object
A class that provides a standard waitFor pattern See details at https://issues.apache.org/jira/browse/HBASE-7384
  • Field Details

  • Constructor Details

  • Method Details

    • getWaitForRatio

      public static float getWaitForRatio(org.apache.hadoop.conf.Configuration conf)
      Returns the 'wait for ratio' used in the sleep(Configuration, long), waitFor(Configuration, long, Predicate), waitFor(Configuration, long, long, Predicate) and waitFor(Configuration, long, long, boolean, Predicate) methods of the class

      This is useful to dynamically adjust max time out values when same test cases run in different test machine settings without recompiling & re-deploying code.

      The value is obtained from the Java System property or configuration setting hbase.test.wait.for.ratio which defaults to 1.

      Parameters:
      conf - the configuration
      Returns:
      the 'wait for ratio' for the current test run.
    • sleep

      public static void sleep(org.apache.hadoop.conf.Configuration conf, long time)
      Makes the current thread sleep for the duration equal to the specified time in milliseconds multiplied by the getWaitForRatio(Configuration).
      Parameters:
      conf - the configuration
      time - the number of milliseconds to sleep.
    • waitFor

      public static <E extends Exception> long waitFor(org.apache.hadoop.conf.Configuration conf, long timeout, Waiter.Predicate<E> predicate)
      Waits up to the duration equal to the specified timeout multiplied by the getWaitForRatio(Configuration) for the given Waiter.Predicate to become true, failing the test if the timeout is reached and the Predicate is still false.

      Parameters:
      conf - the configuration
      timeout - the timeout in milliseconds to wait for the predicate.
      predicate - the predicate to evaluate.
      Returns:
      the effective wait, in milli-seconds until the predicate becomes true or wait is interrupted otherwise -1 when times out
    • waitFor

      public static <E extends Exception> long waitFor(org.apache.hadoop.conf.Configuration conf, long timeout, long interval, Waiter.Predicate<E> predicate)
      Waits up to the duration equal to the specified timeout multiplied by the getWaitForRatio(Configuration) for the given Waiter.Predicate to become true, failing the test if the timeout is reached and the Predicate is still false.

      Parameters:
      conf - the configuration
      timeout - the max timeout in milliseconds to wait for the predicate.
      interval - the interval in milliseconds to evaluate predicate.
      predicate - the predicate to evaluate.
      Returns:
      the effective wait, in milli-seconds until the predicate becomes true or wait is interrupted otherwise -1 when times out
    • waitFor

      public static <E extends Exception> long waitFor(org.apache.hadoop.conf.Configuration conf, long timeout, long interval, boolean failIfTimeout, Waiter.Predicate<E> predicate)
      Waits up to the duration equal to the specified timeout multiplied by the getWaitForRatio(Configuration) for the given Waiter.Predicate to become true, failing the test if the timeout is reached, the Predicate is still false and failIfTimeout is set as true.

      Parameters:
      conf - the configuration
      timeout - the timeout in milliseconds to wait for the predicate.
      interval - the interval in milliseconds to evaluate predicate.
      failIfTimeout - indicates if should fail current test case when times out.
      predicate - the predicate to evaluate.
      Returns:
      the effective wait, in milli-seconds until the predicate becomes true or wait is interrupted otherwise -1 when times out
    • getExplanation

      public static String getExplanation(Waiter.Predicate<?> explain)