Class TimeoutHelper

java.lang.Object
org.metricshub.wmi.TimeoutHelper

public class TimeoutHelper extends Object
for stagged timeout handling.
  • Method Details

    • getRemainingTime

      public static long getRemainingTime(long timeout, long start, String message) throws TimeoutException
      Get the remaining time before timeout.
      Parameters:
      timeout - Timeout in milliseconds. (throws an IllegalArgumentException if negative or zero)
      start - start time in milliseconds. (throws an IllegalArgumentException if negative or zero)
      Returns:
      The remaining time
      Throws:
      TimeoutException - if there's no time left
    • stagedSleep

      public static void stagedSleep(long timeout, long start, String message) throws TimeoutException
      Sub to make the thread sleep in a stepped delay.

      Delay:

      • 50 milliseconds for time from start < 500 milliseconds
      • 100 milliseconds for time from start between 500 milliseconds and 1 second
      • 250 milliseconds for time from start between 1 second and 5 seconds
      • 500 milliseconds for time from start between 5 seconds and 10 seconds
      • 1 second for time from start between 10 seconds and 30 seconds
      • 3 seconds otherwise
      Parameters:
      timeout - Timeout in milliseconds
      start - start time in milliseconds
      message - The timeout error message
      Throws:
      TimeoutException - when times out