Class AbstractTimeBasedUuidCreator

    • Constructor Detail

      • AbstractTimeBasedUuidCreator

        protected AbstractTimeBasedUuidCreator​(UuidVersion version)
    • Method Detail

      • create

        public UUID create()
        Returns a time-based UUID. ### Timestamp The timestamp has 100-nanoseconds resolution, starting from 1582-10-15. It uses 60 bits from the most significant bits. The the time value rolls over around AD 5235.
           s = 10_000_000
           m = 60 * s
           h = 60 * m
           d = 24 * h
           y = 365.25 * d
           2^60 / y = ~3653
           3653 + 1582 = 5235
         
        ### RFC-4122 - 4.1.4. Timestamp The timestamp is a 60-bit value. For UUID version 1, this is represented by Coordinated Universal Time (UTC) as a count of 100- nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar). ### RFC-4122 - 4.1.5. Clock Sequence 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. ### RFC-4122 - 4.1.6. Node For UUID version 1, the node field consists of an IEEE 802 MAC address, usually the host address. For systems with multiple IEEE 802 addresses, any available one can be used. The lowest addressed octet (octet number 10) contains the global/local bit and the unicast/multicast bit, and is the first octet of the address transmitted on an 802.3 LAN. For systems with no IEEE address, a randomly or pseudo-randomly generated value may be used; see Section 4.5. The multicast bit must be set in such addresses, in order that they will never conflict with addresses obtained from network cards. ### RFC-4122 - 4.2.1. Basic Algorithm (1a) Obtain a system-wide global lock (2a) From a system-wide shared stable store (e.g., a file), read the UUID generator state: the values of the timestamp, clock sequence, and node ID used to generate the last UUID. (3a) Get the current time as a 60-bit count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582. (4a) Get the current node ID. (5a) If the state was unavailable (e.g., non-existent or corrupted), or the saved node ID is different than the current node ID, generate a random clock sequence value. (6a) If the state was available, but the saved timestamp is later than the current timestamp, increment the clock sequence value. (7a) Save the state (current timestamp, clock sequence, and node ID) back to the stable store. (8a) Release the global lock. (9a) Format a UUID from the current timestamp, clock sequence, and node ID values according to the steps in Section 4.2.2.
        Specified by:
        create in interface NoArgumentsUuidCreator
        Returns:
        UUID a UUID value
        Throws:
        UuidCreatorException - an overrun exception if more than 10 thousand UUIDs are requested within the same millisecond
      • formatMostSignificantBits

        protected abstract long formatMostSignificantBits​(long timestamp)
        Formats the most significant bits of the UUID. This method must be implemented by all subclasses.
        Parameters:
        timestamp - a timestamp
        Returns:
        the MSB
      • formatLeastSignificantBits

        protected long formatLeastSignificantBits​(long nodeIdentifier,
                                                  long clockSequence)
        Returns the least significant bits of the UUID. ### RFC-4122 - 4.2.2. Generation Details Set the clock_seq_low field to the eight least significant bits (bits zero through 7) of the clock sequence in the same order of significance. Set the 6 least significant bits (bits zero through 5) of the clock_seq_hi_and_reserved field to the 6 most significant bits (bits 8 through 13) of the clock sequence in the same order of significance. Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively. Set the node field to the 48-bit IEEE address in the same order of significance as the address.
        Parameters:
        nodeIdentifier - a node identifier
        clockSequence - a clock sequence
        Returns:
        the LSB