org.apache.solr.common.util

## Class TimeSource.NanoTimeSource

- java.lang.Object
- - org.apache.solr.common.util.TimeSource
  - - org.apache.solr.common.util.TimeSource.NanoTimeSource

Enclosing class:
  TimeSource

    public static final class TimeSource.NanoTimeSource
    extends TimeSource

Implementation that uses `System.nanoTime()`. Epoch time is initialized using `TimeSource.CurrentTimeSource`, and then calculated as the elapsed number of nanoseconds as measured by this implementation.

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.solr.common.util.TimeSource

`TimeSource.CurrentTimeSource, TimeSource.NanoTimeSource, TimeSource.SimTimeSource`

### Field Summary

### Fields inherited from class org.apache.solr.common.util.TimeSource

`CURRENT_TIME, NANO_TIME`

### Constructor Summary

Constructors
Constructor and Description
`NanoTimeSource()`

### Method Summary

All Methods Instance Methods Concrete Methods
`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.

### Methods inherited from class org.apache.solr.common.util.TimeSource

`get, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### NanoTimeSource

    public NanoTimeSource()

### Method Detail

#### getTimeNs

    public long getTimeNs()

Description copied from class: `TimeSource`
Return a time value, in nanosecond units. Depending on implementation this value may or may not be related to Epoch time.

Specified by:
  `getTimeNs` in class `TimeSource`

#### getEpochTimeNs

    public long getEpochTimeNs()

Description copied from class: `TimeSource`
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.

Specified by:
  `getEpochTimeNs` in class `TimeSource`

#### getTimeAndEpochNs

    public long[] getTimeAndEpochNs()

Description copied from class: `TimeSource`
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 by `TimeSource.getTimeNs()`.

Specified by:
  `getTimeAndEpochNs` in class `TimeSource`
Returns:
  an array where the first element is `TimeSource.getTimeNs()` and the second element is `TimeSource.getEpochTimeNs()`.

#### sleep

    public void sleep(long ms)
               throws InterruptedException

Description copied from class: `TimeSource`
Sleep according to this source's notion of time. Eg. accelerated time source such as `TimeSource.SimTimeSource` will sleep proportionally shorter, according to its multiplier.

Specified by:
  `sleep` in class `TimeSource`
Parameters:
  `ms` - number of milliseconds to sleep
Throws:
  `InterruptedException` - when the current thread is interrupted

#### convertDelay

    public long convertDelay(TimeUnit fromUnit,
                             long value,
                             TimeUnit toUnit)

Description copied from class: `TimeSource`
This method allows using TimeSource with APIs that require providing just plain time intervals, eg. `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.

Specified by:
  `convertDelay` in class `TimeSource`
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`)