Package org.apache.solr.util
Class TimeOut
java.lang.Object
org.apache.solr.util.TimeOut
Timeout tool to ease checking time left, time elapsed, and waiting on a condition.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidsleep(long ms) longtimeElapsed(TimeUnit unit) longtoString()voidWait until the givenSupplierreturns true or the timeout expires which ever happens first
-
Constructor Details
-
TimeOut
- Parameters:
timeout- after this maximum time,hasTimedOut()will return true.unit- the time unit of the timeout argument.timeSource- the source of the time.
-
-
Method Details
-
hasTimedOut
public boolean hasTimedOut() -
sleep
- Throws:
InterruptedException
-
timeLeft
-
timeElapsed
-
waitFor
public void waitFor(String messageOnTimeOut, Supplier<Boolean> supplier) throws InterruptedException, TimeoutException Wait until the givenSupplierreturns true or the timeout expires which ever happens first- Parameters:
messageOnTimeOut- the exception message to be used in case a TimeoutException is thrownsupplier- aSupplierthat returns aBooleanvalue- Throws:
InterruptedException- if any thread has interrupted the current threadTimeoutException- if the timeout expires
-
toString
-