Class DefaultClockSequenceStrategy

  • All Implemented Interfaces:
    ClockSequenceStrategy

    public final class DefaultClockSequenceStrategy
    extends Object
    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 (P1) 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. (P2) 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. (P3) 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. (P4) 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.
    • Constructor Detail

      • DefaultClockSequenceStrategy

        public DefaultClockSequenceStrategy()
    • Method Detail

      • getClockSequence

        public int getClockSequence​(long timestamp)
        Returns the next value for a clock sequence. ### RFC-4122 - 4.1.5. Clock Sequence (P2) 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:
        getClockSequence in interface ClockSequenceStrategy
        Parameters:
        timestamp - a timestamp
        Returns:
        a clock sequence
      • next

        public int next()