public class DistributedUniqueTimeProvider
extends net.openhft.chronicle.core.io.SimpleCloseable
implements net.openhft.chronicle.core.time.TimeProvider, net.openhft.chronicle.core.io.Monitorable
TimeProvider
.
NOTE: currentTimeMillis()
is not unique, it is just a call to the underlying provider as there isn't enough resolution to include the hostId.
Each timestamp generated is guaranteed to be unique across all hosts participating in the system. The class uses a file-based mechanism to ensure that timestamps are not only unique across restarts but also across different JVM instances.
Modifier and Type | Method and Description |
---|---|
long |
currentTimeMicros()
This method returns a unique, monotonically increasing microsecond timestamp where
the lowest two digits of the microseconds is the hostId, ensuring uniqueness across different hosts.
|
long |
currentTimeMillis()
NOTE: Calls to this method do not produce unique timestamps, rather just calls the underlying provider.
|
long |
currentTimeNanos()
This method returns a unique, monotonically increasing nanosecond timestamp.
|
static DistributedUniqueTimeProvider |
forHostId(int hostId)
Creates a new instance of DistributedUniqueTimeProvider for a specified hostId.
|
DistributedUniqueTimeProvider |
hostId(int hostId)
Sets the hostId of the DistributedUniqueTimeProvider.
|
static long |
hostIdFor(long timestampWithHostId)
Extract the hostId from the timestampWithHostId
|
static DistributedUniqueTimeProvider |
instance()
Provides a singleton instance of DistributedUniqueTimeProvider using the default hostId.
|
protected void |
performClose() |
DistributedUniqueTimeProvider |
provider(net.openhft.chronicle.core.time.TimeProvider provider)
Sets the TimeProvider of the DistributedUniqueTimeProvider.
|
static long |
timestampFor(long timestampWithHostId)
Extract the timestamp in nanoseconds from the timestampWithHostId
|
void |
unmonitor() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
referenceId, referenceName, temporary
public static DistributedUniqueTimeProvider instance()
public static DistributedUniqueTimeProvider forHostId(int hostId)
hostId
- the host identifier for which the time provider is to be created, must be non-negativepublic static long timestampFor(long timestampWithHostId)
timestampWithHostId
- to extract frompublic static long hostIdFor(long timestampWithHostId)
timestampWithHostId
- to extract fromprotected void performClose()
performClose
in class net.openhft.chronicle.core.io.SimpleCloseable
public DistributedUniqueTimeProvider hostId(int hostId)
hostId
- The host identifier, must be non-negative.IllegalArgumentException
- if the provided hostId is negative.public DistributedUniqueTimeProvider provider(net.openhft.chronicle.core.time.TimeProvider provider)
provider
- The TimeProvider instance to be used for fetching the current time.public long currentTimeMillis()
Use currentTimeMicros()
or currentTimeNanos()
to generate unique timestamps,
or use UniqueMicroTimeProvider.currentTimeMillis()
to generate unique timestamps.
currentTimeMillis
in interface net.openhft.chronicle.core.time.TimeProvider
public long currentTimeMicros() throws IllegalStateException
currentTimeMicros
in interface net.openhft.chronicle.core.time.TimeProvider
IllegalStateException
public long currentTimeNanos() throws IllegalStateException
currentTimeNanos
in interface net.openhft.chronicle.core.time.TimeProvider
IllegalStateException
public void unmonitor()
unmonitor
in interface net.openhft.chronicle.core.io.Monitorable
Copyright © 2024. All rights reserved.