public static final class TimeSource.SimTimeSource extends TimeSource
TimeSource.NANO_TIME
accelerated by a double multiplier.TimeSource.CurrentTimeSource, TimeSource.NanoTimeSource, TimeSource.SimTimeSource
CURRENT_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() |
get
public SimTimeSource(double multiplier)
multiplier
- must be greater than 0.0public long getTimeNs()
TimeSource
getTimeNs
in class TimeSource
public long getEpochTimeNs()
TimeSource
getEpochTimeNs
in class TimeSource
public long[] getTimeAndEpochNs()
TimeSource
TimeSource.getTimeNs()
.getTimeAndEpochNs
in class TimeSource
TimeSource.getTimeNs()
and the
second element is TimeSource.getEpochTimeNs()
.public void sleep(long ms) throws InterruptedException
TimeSource
TimeSource.SimTimeSource
will sleep proportionally shorter, according to its multiplier.sleep
in class TimeSource
ms
- number of milliseconds to sleepInterruptedException
- when the current thread is interruptedpublic long convertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit)
TimeSource
Object.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 TimeSource
fromUnit
- source unitvalue
- original valuetoUnit
- target unitTimeSource.SimTimeSource
)public String toString()
toString
in class TimeSource
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.