Package org.metricshub.wmi
Class TimeoutHelper
java.lang.Object
org.metricshub.wmi.TimeoutHelper
for stagged timeout handling.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longgetRemainingTime(long timeout, long start, String message) Get the remaining time before timeout.static voidstagedSleep(long timeout, long start, String message) Sub to make the thread sleep in a stepped delay.
-
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
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 millisecondsstart- start time in millisecondsmessage- The timeout error message- Throws:
TimeoutException- when times out
-