Class DefaultTimestampStrategy
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.sequence.AbstractSequence
-
- com.github.f4b6a3.uuid.strategy.timestamp.DefaultTimestampStrategy
-
- All Implemented Interfaces:
TimestampStrategy,Sequence
public final class DefaultTimestampStrategy extends AbstractSequence implements TimestampStrategy
Strategy that provides the current timestamp. This is an implementation ofTimestampStrategythat provides millisecond resolution. The timestamp resolution is simulated by adding the next value of a counter that is incremented at every call to the methodTimestampStrategy.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 parallel. ### RFC-4122 - 4.2.1.2. System Clock Resolution (4a) 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 (3b) 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCOUNTER_MAXprotected static intCOUNTER_MIN-
Fields inherited from class com.github.f4b6a3.uuid.util.sequence.AbstractSequence
maxValue, minValue, value
-
-
Constructor Summary
Constructors Constructor Description DefaultTimestampStrategy()DefaultTimestampStrategy(boolean enableOverrunException)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longgetNextCounter(long timestamp)Get the next counter value.longgetTimestamp()intnext()voidreset()-
Methods inherited from class com.github.f4b6a3.uuid.util.sequence.AbstractSequence
current, max, min, set
-
-
-
-
Field Detail
-
COUNTER_MIN
protected static final int COUNTER_MIN
- See Also:
- Constant Field Values
-
COUNTER_MAX
protected static final int COUNTER_MAX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTimestamp
public long getTimestamp()
- Specified by:
getTimestampin interfaceTimestampStrategy
-
getNextCounter
protected long getNextCounter(long timestamp)
Get the next counter value.- Parameters:
timestamp- a timestamp- Returns:
- the next counter value
- Throws:
UuidCreatorException- an overrun exception if more than 10 thousand UUIDs are requested within the same millisecond
-
next
public int next()
- Specified by:
nextin interfaceSequence- Overrides:
nextin classAbstractSequence
-
reset
public void reset()
- Specified by:
resetin interfaceSequence- Overrides:
resetin classAbstractSequence
-
-