Package org.apache.solr.util
Class TimeOut
- java.lang.Object
-
- org.apache.solr.util.TimeOut
-
public class TimeOut extends Object
Timeout tool to ease checking time left, time elapsed, and waiting on a condition.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasTimedOut()
void
sleep(long ms)
long
timeElapsed(TimeUnit unit)
long
timeLeft(TimeUnit unit)
String
toString()
void
waitFor(String messageOnTimeOut, Supplier<Boolean> supplier)
Wait until the givenSupplier
returns true or the timeout expires which ever happens first
-
-
-
Constructor Detail
-
TimeOut
public TimeOut(long timeout, TimeUnit unit, org.apache.solr.common.util.TimeSource timeSource)
- 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 Detail
-
hasTimedOut
public boolean hasTimedOut()
-
sleep
public void sleep(long ms) throws InterruptedException
- Throws:
InterruptedException
-
timeLeft
public long timeLeft(TimeUnit unit)
-
timeElapsed
public long timeElapsed(TimeUnit unit)
-
waitFor
public void waitFor(String messageOnTimeOut, Supplier<Boolean> supplier) throws InterruptedException, TimeoutException
Wait until the givenSupplier
returns true or the timeout expires which ever happens first- Parameters:
messageOnTimeOut
- the exception message to be used in case a TimeoutException is thrownsupplier
- aSupplier
that returns aBoolean
value- Throws:
InterruptedException
- if any thread has interrupted the current threadTimeoutException
- if the timeout expires
-
-