Class TimeBasedReorderedGenerator

java.lang.Object
com.fasterxml.uuid.UUIDGenerator
com.fasterxml.uuid.NoArgGenerator
com.fasterxml.uuid.impl.TimeBasedReorderedGenerator

public class TimeBasedReorderedGenerator extends NoArgGenerator
Implementation of UUID generator that uses time/location based generation method field compatible with UUIDv1, reorderd for improved DB locality. This is usually referred to as "Version 6".

As all JUG provided implementations, this generator is fully thread-safe. Additionally it can also be made externally synchronized with other instances (even ones running on other JVMs); to do this, use FileBasedTimestampSynchronizer (or equivalent).

Since:
4.1
  • Field Details

    • BYTE_OFFSET_TIME_HIGH

      public static int BYTE_OFFSET_TIME_HIGH
    • BYTE_OFFSET_TIME_MID

      public static int BYTE_OFFSET_TIME_MID
    • BYTE_OFFSET_TIME_LOW

      public static int BYTE_OFFSET_TIME_LOW
    • _ethernetAddress

      protected final EthernetAddress _ethernetAddress
    • _timer

      protected final UUIDTimer _timer
      Object used for synchronizing access to timestamps, to guarantee that timestamps produced by this generator are unique and monotonically increasings. Some implementations offer even stronger guarantees, for example that same guarantee holds between instances running on different JVMs (or with native code).
    • _uuidL2

      protected final long _uuidL2
      Base values for the second long (last 8 bytes) of UUID to construct
  • Constructor Details

    • TimeBasedReorderedGenerator

      public TimeBasedReorderedGenerator(EthernetAddress ethAddr, UUIDTimer timer)
      Parameters:
      ethAddr - Hardware address (802.1) to use for generating spatially unique part of UUID. If system has more than one NIC,
  • Method Details

    • getType

      public UUIDType getType()
      Description copied from class: UUIDGenerator
      Accessor for determining type of UUIDs (version) that this generator instance will produce.
      Specified by:
      getType in class UUIDGenerator
    • getEthernetAddress

      public EthernetAddress getEthernetAddress()
    • generate

      public UUID generate()
      Description copied from class: NoArgGenerator
      Method for generating a UUID.
      Specified by:
      generate in class NoArgGenerator
      Returns:
      Newly generated UUID
    • construct

      public UUID construct(long rawTimestamp)
      Method that will construct actual UUID instance for given timestamp: called by generate() but may alternatively be called directly to construct an instance with known timestamp. NOTE: calling this method directly does NOT guarantee uniqueness of resulting UUID (caller has to guarantee uniqueness)
      Parameters:
      rawTimestamp - Timestamp usually obtained from UUIDTimer.getTimestamp(), used for constructing UUID instance
      Returns:
      unix Time-based, Reordered UUID constructed for given timestamp
      Since:
      4.3