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.
### RFC-4122 - 4.2.1.2. System Clock Resolution
(3c) If a system overruns the generator by requesting too many UUIDs within a
single system time interval, the UUID service MUST either return an error, or
stall the UUID generator until the system clock catches up.| Modifier and Type | Field and Description |
|---|---|
protected static int |
COUNTER_MAX |
protected static int |
COUNTER_MIN |
protected static int |
COUNTER_OFFSET_MAX |
protected static String |
OVERRUN_MESSAGE |
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() |
int |
next() |
void |
reset() |
current, max, min, setprotected long previousTimestamp
protected static final int COUNTER_MIN
protected static final int COUNTER_MAX
protected static final int COUNTER_OFFSET_MAX
protected static final String OVERRUN_MESSAGE
public long getTimestamp()
getTimestamp in interface TimestampStrategyprotected int getNextCounter(long timestamp)
timestamp - a timestamppublic int next()
next in interface Sequencenext in class AbstractSequencepublic void reset()
reset in interface Sequencereset in class AbstractSequenceCopyright © 2019. All rights reserved.