Class UUIDv1Generator

java.lang.Object
uno.xifan.id.generator.uuid.UUIDv1Generator
All Implemented Interfaces:
IdGenerator

public class UUIDv1Generator extends Object implements IdGenerator
UUIDv1生成器 (基于时间的DCE安全实现) 该类用于生成符合RFC 4122规范的UUIDv1。该版本包含60位时间戳(100ns精度)、 14位时钟序列和48位节点ID,适用于需要时间排序的场景。 UUIDv1结构规范:
  • time_low - 32位 (时间戳的低32位)
  • time_mid - 16位 (时间戳的中间16位)
  • version - 4位 (0001b)
  • time_high - 12位 (时间戳的高12位)
  • variant - 2位 (RFC 4122规范,10b)
  • clock_seq - 14位 (时钟序列)
  • node - 48位 (MAC地址或随机生成)
平台兼容性说明:
  • 时间精度基于系统时钟,使用100ns精度的时间戳
  • 节点ID优先使用系统MAC地址,无法获取时使用随机值
  • 时钟序列使用原子计数器保证并发安全
  • 支持时钟回拨场景的处理
Since:
2024-05-01
Version:
1.2
Author:
ixiongdi
  • Constructor Details

    • UUIDv1Generator

      public UUIDv1Generator()
  • Method Details

    • next

      public static UUID next()
      生成UUIDv1主方法
    • generate

      public String generate()
      Description copied from interface: IdGenerator
      生成一个唯一标识符。 每个实现类都应该根据其特定的生成策略来实现此方法。
      Specified by:
      generate in interface IdGenerator
      Returns:
      生成的唯一标识符,具体类型由实现类决定
    • idType

      public IdType idType()
      Description copied from interface: IdGenerator
      获取当前生成器的标识符类型

      此方法用于标识生成器使用的具体ID生成策略。每个实现类都应该 返回一个对应其生成策略的IdType枚举值。

      Specified by:
      idType in interface IdGenerator
      Returns:
      当前生成器的标识符类型