public abstract class TimeProvider extends Object implements Serializable
ChronicleHash
replication needs. TimeProvider
is specified to be used in a replicated ChronicleHash
via ChronicleHashBuilder.timeProvider(TimeProvider)
method. The simplest (including default)
providers rely on system time (System.currentTimeMillis()
), but more complex ones could
use some atomic counters, or different sources of time.
Possible reasons to implement a custom time provider:
System.currentTimeMillis()
is considered too slowChronicleHash
system is completely hijacked,
and used to store some long
value with non-time meaning (see ReplicableEntry.originTimestamp()
, ReplicableEntry.updateOrigin(byte, long)
,
RemoteOperationContext.remoteTimestamp()
).Subclasses should be immutable, because ChronicleHashBuilder
doesn't make defensive
copies.
Constructor and Description |
---|
TimeProvider() |
Modifier and Type | Method and Description |
---|---|
abstract long |
currentTime()
Returns the current time in this provider's context.
|
abstract long |
systemTimeIntervalBetween(long earlierTime,
long laterTime,
TimeUnit systemTimeIntervalUnit)
Returns system time interval (i.
|
public abstract long currentTime()
public abstract long systemTimeIntervalBetween(long earlierTime, long laterTime, TimeUnit systemTimeIntervalUnit)
TimeProvider
's currentTime()
method, with the highest possible
precision, in the given time units.earlierTime
- currentTime()
result, taken at some moment in the past (earlier)laterTime
- currentTime()
result, taken at some moment in the past, but later
than earlierTime
was takensystemTimeIntervalUnit
- the time units to return system time interval inCopyright © 2015. All rights reserved.