Package org.apache.hadoop.hbase
Class Waiter
java.lang.Object
org.apache.hadoop.hbase.Waiter
A class that provides a standard waitFor pattern See details at
https://issues.apache.org/jira/browse/HBASE-7384
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Waiter.ExplainingPredicate<E extends Exception>
A mixin interface, can be used withWaiter
to explain failed state.static interface
Waiter.Predicate<E extends Exception>
A predicate 'closure' used by thewaitFor(Configuration, long, Predicate)
andwaitFor(Configuration, long, Predicate)
andwaitFor(Configuration, long, long, boolean, Predicate)
methods. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
System property name whose value is a scale factor to increase time out values dynamically used insleep(Configuration, long)
,waitFor(Configuration, long, Predicate)
,waitFor(Configuration, long, long, Predicate)
, andwaitFor(Configuration, long, long, boolean, Predicate)
methodprivate static float
private static final org.slf4j.Logger
private static float
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getExplanation
(Waiter.Predicate<?> explain) static float
getWaitForRatio
(org.apache.hadoop.conf.Configuration conf) Returns the 'wait for ratio' used in thesleep(Configuration, long)
,waitFor(Configuration, long, Predicate)
,waitFor(Configuration, long, long, Predicate)
andwaitFor(Configuration, long, long, boolean, Predicate)
methods of the classstatic 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 thegetWaitForRatio(Configuration)
.static <E extends Exception>
longwaitFor
(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 thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached, the Predicate is stillfalse
and failIfTimeout is set astrue
.static <E extends Exception>
longwaitFor
(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 thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached and the Predicate is stillfalse
.static <E extends Exception>
longwaitFor
(org.apache.hadoop.conf.Configuration conf, long timeout, Waiter.Predicate<E> predicate) Waits up to the duration equal to the specified timeout multiplied by thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached and the Predicate is stillfalse
.
-
Field Details
-
LOG
-
HBASE_TEST_WAIT_FOR_RATIO
System property name whose value is a scale factor to increase time out values dynamically used insleep(Configuration, long)
,waitFor(Configuration, long, Predicate)
,waitFor(Configuration, long, long, Predicate)
, andwaitFor(Configuration, long, long, boolean, Predicate)
method The actual time out value will equal to hbase.test.wait.for.ratio * passed-in timeout- See Also:
-
HBASE_WAIT_FOR_RATIO_DEFAULT
-
waitForRatio
-
-
Constructor Details
-
Waiter
private Waiter()
-
-
Method Details
-
getWaitForRatio
Returns the 'wait for ratio' used in thesleep(Configuration, long)
,waitFor(Configuration, long, Predicate)
,waitFor(Configuration, long, long, Predicate)
andwaitFor(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 settinghbase.test.wait.for.ratio
which defaults to1
.- Parameters:
conf
- the configuration- Returns:
- the 'wait for ratio' for the current test run.
-
sleep
Makes the current thread sleep for the duration equal to the specified time in milliseconds multiplied by thegetWaitForRatio(Configuration)
.- Parameters:
conf
- the configurationtime
- 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 thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached and the Predicate is stillfalse
.- Parameters:
conf
- the configurationtimeout
- 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 thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached and the Predicate is stillfalse
.- Parameters:
conf
- the configurationtimeout
- 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 thegetWaitForRatio(Configuration)
for the givenWaiter.Predicate
to becometrue
, failing the test if the timeout is reached, the Predicate is stillfalse
and failIfTimeout is set astrue
.- Parameters:
conf
- the configurationtimeout
- 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
-