Class CosIdGenerator

java.lang.Object
icu.congee.id.generator.cosid.CosIdGenerator
All Implemented Interfaces:
IdGenerator

public class CosIdGenerator extends Object implements IdGenerator
CosId分布式ID生成器实现类 采用80位二进制结构:44位时间戳 + 20位机器ID + 16位序列号
  • Constructor Details

    • CosIdGenerator

      public CosIdGenerator()
    • CosIdGenerator

      public CosIdGenerator(long machineId, long epoch)
      构造函数
      Parameters:
      machineId - 机器ID(0~1048575)
      epoch - 自定义纪元时间戳
  • Method Details

    • next

      public static String next()
    • generateId

      public byte[] generateId()
      生成分布式ID的字节数组 该方法使用synchronized确保线程安全
      Returns:
      10字节的ID字节数组
    • main

      public static void main(String[] args)
      主方法,用于测试ID生成器
    • generate

      public Object generate()
      实现IdGenerator接口的generate方法
      Specified by:
      generate in interface IdGenerator
      Returns:
      Base62编码的ID字符串
    • idType

      public IdType idType()
      实现IdGenerator接口的idType方法
      Specified by:
      idType in interface IdGenerator
      Returns:
      ID类型为CosId