Class Waiter

java.lang.Object
com.sas.services.util.Waiter

public class Waiter extends Object
Waiter class. This is used in conjunction with 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
    Constructor
    Description
    Waiter(WaitPolicy waitPolicy)
    Constructs a Waiter from a WaitPolicy.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the total time spent waiting at the time of this method call.
    boolean
    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

      public Waiter(WaitPolicy waitPolicy)
      Constructs a Waiter from a WaitPolicy. After the constructor returns the WaitPolicy object is no longer needed.
      Parameters:
      waitPolicy -
  • Method Details

    • sleep

      public boolean sleep() throws InterruptedException
      Sleep 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 type WaitPolicy.TYPE.FINITE then 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: