public static final class TimeSource.SimTimeSource extends TimeSource
TimeSource.NANO_TIME accelerated by a double multiplier.TimeSource.CurrentTimeSource, TimeSource.NanoTimeSource, TimeSource.SimTimeSourceCURRENT_TIME, NANO_TIME| Constructor and Description |
|---|
SimTimeSource(double multiplier)
Create a simulated time source that runs faster than real time by a multiplier.
|
| Modifier and Type | Method and Description |
|---|---|
long |
convertDelay(TimeUnit fromUnit,
long value,
TimeUnit toUnit)
This method allows using TimeSource with APIs that require providing just plain time intervals,
eg.
|
long |
getEpochTimeNs()
Return Epoch time.
|
long[] |
getTimeAndEpochNs()
Return both the source's time value and the corresponding epoch time
value.
|
long |
getTimeNs()
Return a time value, in nanosecond units.
|
void |
sleep(long ms)
Sleep according to this source's notion of time.
|
String |
toString() |
getpublic SimTimeSource(double multiplier)
multiplier - must be greater than 0.0public long getTimeNs()
TimeSourcegetTimeNs in class TimeSourcepublic long getEpochTimeNs()
TimeSourcegetEpochTimeNs in class TimeSourcepublic long[] getTimeAndEpochNs()
TimeSourceTimeSource.getTimeNs().getTimeAndEpochNs in class TimeSourceTimeSource.getTimeNs() and the
second element is TimeSource.getEpochTimeNs().public void sleep(long ms)
throws InterruptedException
TimeSourceTimeSource.SimTimeSource will sleep proportionally shorter, according to its multiplier.sleep in class TimeSourcems - number of milliseconds to sleepInterruptedException - when the current thread is interruptedpublic long convertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit)
TimeSourceObject.wait(long). Values returned by this method are adjusted according to the
time source's notion of time - eg. accelerated time source provided by TimeSource.SimTimeSource
will return intervals that are proportionally shortened by the multiplier.
NOTE: converting small values may significantly affect precision of the returned values due to rounding, especially for accelerated time source, so care should be taken to use time units that result in relatively large values. For example, converting a value of 1 expressed in seconds would result in less precision than converting a value of 1000 expressed in milliseconds.
convertDelay in class TimeSourcefromUnit - source unitvalue - original valuetoUnit - target unitTimeSource.SimTimeSource)public String toString()
toString in class TimeSourceCopyright © 2000-2021 Apache Software Foundation. All Rights Reserved.