Package org.apache.solr.common.util
Class TimeSource
- java.lang.Object
- 
- org.apache.solr.common.util.TimeSource
 
- 
- Direct Known Subclasses:
- TimeSource.CurrentTimeSource,- TimeSource.NanoTimeSource,- TimeSource.SimTimeSource
 
 public abstract class TimeSource extends Object Source of time.NOTE: depending on implementation returned values may not be related in any way to the current Epoch or calendar time, and they may even be negative - but the API guarantees that they are always monotonically increasing. 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classTimeSource.CurrentTimeSourceImplementation that usesSystem.currentTimeMillis().static classTimeSource.NanoTimeSourceImplementation that usesSystem.nanoTime().static classTimeSource.SimTimeSourceImplementation that usesNANO_TIMEaccelerated by a double multiplier.
 - 
Field SummaryFields Modifier and Type Field Description static TimeSourceCURRENT_TIMEThis instance usesTimeSource.CurrentTimeSourcefor generating timestamps.static TimeSourceNANO_TIMEThis instance usesTimeSource.NanoTimeSourcefor generating timestamps.
 - 
Constructor SummaryConstructors Constructor Description TimeSource()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract longconvertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit)This method allows using TimeSource with APIs that require providing just plain time intervals, e.g.static TimeSourceget(String type)Obtain an instance of time source.abstract longgetEpochTimeNs()Return Epoch time.abstract long[]getTimeAndEpochNs()Return both the source's time value and the corresponding epoch time value.abstract longgetTimeNs()Return a time value, in nanosecond units.abstract voidsleep(long ms)Sleep according to this source's notion of time.StringtoString()
 
- 
- 
- 
Field Detail- 
CURRENT_TIMEpublic static final TimeSource CURRENT_TIME This instance usesTimeSource.CurrentTimeSourcefor generating timestamps.
 - 
NANO_TIMEpublic static final TimeSource NANO_TIME This instance usesTimeSource.NanoTimeSourcefor generating timestamps.
 
- 
 - 
Method Detail- 
getpublic static TimeSource get(String type) Obtain an instance of time source.- Parameters:
- type- supported types:- currentTime,- nanoTimeand accelerated time with a double factor in the form of- simTime:FACTOR, e.g.- simTime:2.5
- Returns:
- one of the supported types
 
 - 
getTimeNspublic abstract long getTimeNs() Return a time value, in nanosecond units. Depending on implementation this value may or may not be related to Epoch time.
 - 
getEpochTimeNspublic abstract long getEpochTimeNs() Return Epoch time. Implementations that are not natively based on epoch time may return values that are consistently off by a (small) fixed number of milliseconds from the actual epoch time.
 - 
getTimeAndEpochNspublic abstract long[] getTimeAndEpochNs() Return both the source's time value and the corresponding epoch time value. This method ensures that epoch time calculations use the same internal value of time as that reported bygetTimeNs().- Returns:
- an array where the first element is getTimeNs()and the second element isgetEpochTimeNs().
 
 - 
sleeppublic abstract void sleep(long ms) throws InterruptedExceptionSleep according to this source's notion of time. E.g. accelerated time source such asTimeSource.SimTimeSourcewill sleep proportionally shorter, according to its multiplier.- Parameters:
- ms- number of milliseconds to sleep
- Throws:
- InterruptedException- when the current thread is interrupted
 
 - 
convertDelaypublic abstract long convertDelay(TimeUnit fromUnit, long value, TimeUnit toUnit) This method allows using TimeSource with APIs that require providing just plain time intervals, e.g.Object.wait(long). Values returned by this method are adjusted according to the time source's notion of time - e.g. accelerated time source provided byTimeSource.SimTimeSourcewill 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. - Parameters:
- fromUnit- source unit
- value- original value
- toUnit- target unit
- Returns:
- converted value, possibly scaled by the source's notion of accelerated time (see TimeSource.SimTimeSource)
 
 
- 
 
-