public class DefaultTimestampStrategy extends AbstractSequence implements TimestampStrategy
TimestampStrategy that provides
millisecond resolution. The timestamp resolution is simulated by adding the
value of a counter that is incremented at every call to the method
TimestampStrategy.getTimestamp().
The counter's range is from 0 to 9,999, that is, the number of 100-nanosecond
intervals per millisecond.
The counter is initialized with a random number between 0 and 255 to void
duplicates in the case of multiple time-based generators running in different
JVMs.
### RFC-4122 - 4.2.1.2. System Clock Resolution
(4) A high resolution timestamp can be simulated by keeping a count of the
number of UUIDs that have been generated with the same value of the system
time, and using it to construct the low order bits of the timestamp. The
count will range between zero and the number of 100-nanosecond intervals per
system time interval.| Modifier and Type | Field and Description |
|---|---|
protected static int |
COUNTER_MAX |
protected static int |
COUNTER_MIN |
protected static int |
COUNTER_OFFSET_MAX |
protected long |
previousTimestamp |
maxValue, minValue, value| Constructor and Description |
|---|
DefaultTimestampStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected int |
getNextCounter(long timestamp)
Get the next counter value.
|
long |
getTimestamp() |
void |
reset() |
protected long previousTimestamp
protected static final int COUNTER_MIN
protected static final int COUNTER_MAX
protected static final int COUNTER_OFFSET_MAX
public long getTimestamp()
getTimestamp in interface TimestampStrategyprotected int getNextCounter(long timestamp)
timestamp - a timestamppublic void reset()
reset in interface Sequencereset in class AbstractSequenceCopyright © 2019. All rights reserved.