public class UUIDTimer extends Object
Some additional assumptions about calculating the timestamp:
Note about synchronization: main synchronization point (as of version
3.1.1 and above) is getTimestamp()
, so caller need not
synchronize access explicitly.
Modifier and Type | Field and Description |
---|---|
protected UUIDClock |
_clock
Clock used to get the time when a timestamp is requested.
|
protected Random |
_random
Random number generator used to generate additional information
to further reduce probability of collisions.
|
protected TimestampSynchronizer |
_syncer
Object used to reliably ensure that no multiple JVMs
generate UUIDs, and also that the time stamp value used for
generating time-based UUIDs is monotonically increasing
even if system clock moves backwards over a reboot (usually
due to some system level problem).
|
Constructor and Description |
---|
UUIDTimer(Random rnd,
TimestampSynchronizer sync) |
UUIDTimer(Random rnd,
TimestampSynchronizer sync,
UUIDClock clock) |
Modifier and Type | Method and Description |
---|---|
protected void |
getAndSetTimestamp(byte[] uuidBytes) |
int |
getClockSequence() |
long |
getTimestamp()
Method that constructs unique timestamp suitable for use for
constructing UUIDs.
|
protected void |
slowDown(long startTime,
long actDiff)
Simple utility method to use to wait for couple of milliseconds,
to let system clock hopefully advance closer to the virtual
timestamps used.
|
protected final TimestampSynchronizer _syncer
See TimestampSynchronizer
for details.
protected final Random _random
protected final UUIDClock _clock
public UUIDTimer(Random rnd, TimestampSynchronizer sync) throws IOException
IOException
public UUIDTimer(Random rnd, TimestampSynchronizer sync, UUIDClock clock) throws IOException
rnd
- Random-number generator to usesync
- Synchronizer needed for multi-threaded timestamp accessclock
- Provider for milli-second resolution timestampIOException
- if initialization of sync
fails due to problem related
to reading of persisted last-used timestamppublic int getClockSequence()
public long getTimestamp()
protected final void getAndSetTimestamp(byte[] uuidBytes)
protected void slowDown(long startTime, long actDiff)
actDiff
- Number of milliseconds to wait for from current
time point, to catch upCopyright © 2023 FasterXML.com. All rights reserved.