Class DefaultClockSequenceStrategy
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.sequence.AbstractSequence
-
- com.github.f4b6a3.uuid.strategy.clockseq.DefaultClockSequenceStrategy
-
- All Implemented Interfaces:
ClockSequenceStrategy,Sequence
public final class DefaultClockSequenceStrategy extends AbstractSequence implements ClockSequenceStrategy
Strategy that provides the current clock sequence. This class is an implementation of the 'clock sequence' defined in the RFC-4122. The maximum value of this sequence is 16,383 or 0x3fff. It has a private static controller to ensure that each instance of this strategy receives a unique clock sequence value in the JVM. This prevents more than one instance from sharing the same clock sequence at any given time. ### RFC-4122 - 4.1.5. Clock Sequence (1) For UUID version 1, the clock sequence is used to help avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes. (2) If the clock is set backwards, or might have been set backwards (e.g., while the system was powered off), and the UUID generator can not be sure that no UUIDs were generated with timestamps larger than the value to which the clock was set, then the clock sequence has to be changed. If the previous value of the clock sequence is known, it can just be incremented; otherwise it should be set to a random or high-quality pseudo-random value. (3) Similarly, if the node ID changes (e.g., because a network card has been moved between machines), setting the clock sequence to a random number minimizes the probability of a duplicate due to slight differences in the clock settings of the machines. If the value of clock sequence associated with the changed node ID were known, then the clock sequence could just be incremented, but that is unlikely. (4) The clock sequence MUST be originally (i.e., once in the lifetime of a system) initialized to a random number to minimize the correlation across systems. This provides maximum protection against node identifiers that may move or switch from system to system rapidly. The initial value MUST NOT be correlated to the node identifier.
-
-
Field Summary
Fields Modifier and Type Field Description static ClockSequenceControllerCONTROLLERprotected static intSEQUENCE_MAXprotected static intSEQUENCE_MIN-
Fields inherited from class com.github.f4b6a3.uuid.util.sequence.AbstractSequence
maxValue, minValue, value
-
-
Constructor Summary
Constructors Constructor Description DefaultClockSequenceStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetClockSequence(long timestamp)Returns the next value for a clock sequence. ### RFC-4122 - 4.1.5.intnext()intreset()-
Methods inherited from class com.github.f4b6a3.uuid.util.sequence.AbstractSequence
current, max, min, set
-
-
-
-
Field Detail
-
SEQUENCE_MIN
protected static final int SEQUENCE_MIN
- See Also:
- Constant Field Values
-
SEQUENCE_MAX
protected static final int SEQUENCE_MAX
- See Also:
- Constant Field Values
-
CONTROLLER
public static final ClockSequenceController CONTROLLER
-
-
Method Detail
-
getClockSequence
public int getClockSequence(long timestamp)
Returns the next value for a clock sequence. ### RFC-4122 - 4.1.5. Clock Sequence (2) If the clock is set backwards, or might have been set backwards (e.g., while the system was powered off), and the UUID generator can not be sure that no UUIDs were generated with timestamps larger than the value to which the clock was set, then the clock sequence has to be changed. If the previous value of the clock sequence is known, it can just be incremented; otherwise it should be set to a random or high-quality pseudo-random value.- Specified by:
getClockSequencein interfaceClockSequenceStrategy- Parameters:
timestamp- a timestamp- Returns:
- a clock sequence
-
next
public int next()
- Specified by:
nextin interfaceSequence- Overrides:
nextin classAbstractSequence
-
reset
public int reset()
- Specified by:
resetin interfaceSequence- Overrides:
resetin classAbstractSequence
-
-