@Immutable public final class Timeout extends Object
Usage:
Timeout timeout = Timeout.getNanosTimeout(1, TimeUnit.SECONDS); String str = futureString.get(timeout.getTime(), timeout.getUnit()); Integer num = futureInt.get(timeout.getTime(), timeout.getUnit());where if the first call takes quarter of a second, the second call is passed the equivalent of three-quarters of a second.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Timeout.TimeSupplier
Supply time and precision to a
Timeout. |
| Modifier and Type | Method and Description |
|---|---|
static Timeout |
getMillisTimeout(long time,
TimeUnit unit)
Get a
Timeout that uses millisecond
precision. |
static Timeout |
getNanosTimeout(long time,
TimeUnit unit)
Get a
Timeout that uses nanosecond
precision. |
long |
getTime()
Get time remaining
|
RuntimeTimeoutException |
getTimeoutException()
Build a new time out exception for this timeout
|
long |
getTimeoutPeriod()
The original timeout period expressed in
units |
TimeUnit |
getUnit()
Get the precision of this timeout.
|
boolean |
isExpired()
Has this timeout expired
|
void |
throwTimeoutException()
Always throws a
TimeoutException. |
static Supplier<Timeout> |
timeoutFactory(long time,
TimeUnit unit,
Timeout.TimeSupplier supplier)
Factory for creating timeouts of the specified duration.
|
public static Timeout getNanosTimeout(long time, TimeUnit unit)
Timeout that uses nanosecond
precision. The accuracy will depend on the accuracy of
System.nanoTime().time - the maximum time to wait for the lockunit - the time unit of the time argument.TimeUnit.NANOSECONDS
precision.public static Timeout getMillisTimeout(long time, TimeUnit unit)
Timeout that uses millisecond
precision. The accuracy will depend on the accuracy of
System.currentTimeMillis().time - the maximum time to wait for the lockunit - the time unit of the time argument.TimeUnit.MILLISECONDS
precision.public static Supplier<Timeout> timeoutFactory(long time, TimeUnit unit, Timeout.TimeSupplier supplier)
Timeout will start when the factory is
called.
Generally, use the getMillisTimeout(long, TimeUnit) or
getNanosTimeout(long, TimeUnit) factory methods directly. Only use
this if a custom Timeout.TimeSupplier
is required – for instance for testing, you can use this to mock out the
actual passage of time.
time - how long the timeouts should be forunit - in what units time is expressed insupplier - the thing that tells the timeout what the current time is.Supplier.public long getTime()
public boolean isExpired()
public long getTimeoutPeriod()
unitspublic void throwTimeoutException()
throws TimedOutException
TimeoutException.TimedOutException - if any.public RuntimeTimeoutException getTimeoutException()
RuntimeTimeoutException.Copyright © 2016 Atlassian. All rights reserved.