public class DistributedUniqueTimeProvider
extends net.openhft.chronicle.core.io.SimpleCloseable
implements net.openhft.chronicle.core.time.TimeProvider, net.openhft.chronicle.core.io.Monitorable
TimeProvider implementation producing timestamps that remain unique across JVMs by embedding
a host identifier in the lower bits. A memory mapped file coordinates monotonicity between processes.
currentTimeMillis() simply delegates to the underlying provider and is therefore not unique.| Modifier and Type | Method and Description |
|---|---|
long |
currentTimeMicros()
Generates a unique microsecond-resolution timestamp embedding the configured host id.
|
long |
currentTimeMillis()
NOTE: Calls to this method do not produce unique timestamps, rather just calls the underlying provider.
|
long |
currentTimeNanos()
Generates a unique nanosecond-resolution timestamp embedding the host id.
|
static DistributedUniqueTimeProvider |
forHostId(int hostId)
Creates a new instance of DistributedUniqueTimeProvider for a specified hostId.
|
DistributedUniqueTimeProvider |
hostId(int hostId)
Configures the host identifier used in generated timestamps.
|
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)
Replaces the underlying time source used for wall-clock time.
|
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, waitreferenceId, referenceName, temporarypublic 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.SimpleCloseablepublic DistributedUniqueTimeProvider hostId(int hostId)
public DistributedUniqueTimeProvider provider(net.openhft.chronicle.core.time.TimeProvider provider)
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.TimeProviderpublic long currentTimeMicros()
throws IllegalStateException
currentTimeMicros in interface net.openhft.chronicle.core.time.TimeProviderIllegalStateExceptionpublic long currentTimeNanos()
throws IllegalStateException
currentTimeNanos in interface net.openhft.chronicle.core.time.TimeProviderIllegalStateExceptionpublic void unmonitor()
unmonitor in interface net.openhft.chronicle.core.io.MonitorableCopyright © 2026 Chronicle Software Ltd. All rights reserved.