Class Waiter
WaitPolicy.
Typical use is for the application which needs to follow a WaitPolicy to construct a Waiter
and if the resource in question is not available call sleep() until it is or sleep()
returns false.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the total time spent waiting at the time of this method call.booleansleep()Sleep as dictated by the policy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Waiter
Constructs a Waiter from aWaitPolicy. After the constructor returns the WaitPolicy object is no longer needed.- Parameters:
waitPolicy-
-
-
Method Details
-
sleep
public boolean sleep() throws InterruptedExceptionSleep as dictated by the policy.In the discussion that follows the variables referred to use the names of the parameters of
WaitPolicy(TYPE, int, int, int, int, long). initialWait sets the time for the first sleep. waitIncrement can be either positive or negative and subsequent sleep periods are adjusted by waitIncrement, subject to the bounds imposed by minimumWait and maximumWait. If the WaitPolicy is of typeWaitPolicy.TYPE.FINITEthen the final sleep period is adjusted so that totalWait is not exceeded.Do note the various times determine how long the method sleeps and no attempt is made to adjust for time spent performing other operations.
- Returns:
- true: sleep was invoked;
false: sleep was not invoked because total wait time was exceeded or
policy type was
WaitPolicy.TYPE.NONE - Throws:
InterruptedException- if the call to Thread.sleep() which is used to implement "sleep" throws an InterruptedException.
-
getTotalTimeWaited
public long getTotalTimeWaited()Returns the total time spent waiting at the time of this method call.- Returns:
-