Class OpenIdGenerationException

All Implemented Interfaces:
Serializable

public class OpenIdGenerationException extends OpenException
ID Generation Exception - Unified exception for all ID generation failures ID生成异常 - 所有ID生成失败的统一异常

Exception thrown when ID generation fails due to various reasons such as clock backward, segment exhaustion, or invalid parameters.

当ID生成由于各种原因(如时钟回拨、号段耗尽或参数无效)失败时抛出的异常。

Features | 主要功能:

  • Generator type tracking - 生成器类型追踪
  • Business tag support - 业务标识支持
  • Structured error codes - 结构化错误码
  • Factory methods for common errors - 常见错误的工厂方法

Error Codes | 错误码:

Usage Examples | 使用示例:

try {
    long id = generator.generate();
} catch (OpenIdGenerationException e) {
    log.error("ID generation failed: type={}, bizTag={}, code={}",
        e.generatorType(), e.bizTag(), e.getErrorCode());
}

// Using factory methods
throw OpenIdGenerationException.clockBackward(lastTs, currentTs);
throw OpenIdGenerationException.invalidPrefix("MyPrefix");

Security | 安全性:

  • Thread-safe: Yes (immutable exception) - 线程安全: 是(不可变异常)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • ERR_CLOCK_BACKWARD

      public static final String ERR_CLOCK_BACKWARD
      Clock moved backwards | 时钟回拨
      See Also:
    • ERR_INVALID_PARAMETER

      public static final String ERR_INVALID_PARAMETER
      Invalid configuration parameter | 参数无效
      See Also:
    • ERR_SEGMENT_EXHAUSTED

      public static final String ERR_SEGMENT_EXHAUSTED
      ID segment exhausted | 号段耗尽
      See Also:
    • ERR_SEGMENT_FAILED

      public static final String ERR_SEGMENT_FAILED
      Segment allocation failed | 号段分配失败
      See Also:
    • ERR_INVALID_FORMAT

      public static final String ERR_INVALID_FORMAT
      Invalid ID format | ID格式无效
      See Also:
    • ERR_SEQUENCE_OVERFLOW

      public static final String ERR_SEQUENCE_OVERFLOW
      Sequence counter overflow | 序列号溢出
      See Also:
    • ERR_INVALID_PREFIX

      public static final String ERR_INVALID_PREFIX
      Invalid typed ID prefix | 无效前缀
      See Also:
    • ERR_TABLE_INIT_FAILED

      public static final String ERR_TABLE_INIT_FAILED
      Database table initialization failed | 数据库表初始化失败
      See Also:
  • Constructor Details

    • OpenIdGenerationException

      public OpenIdGenerationException(String message)
      Creates an exception with message 使用消息创建异常
      Parameters:
      message - the error message | 错误消息
    • OpenIdGenerationException

      public OpenIdGenerationException(String message, Throwable cause)
      Creates an exception with message and cause 使用消息和原因创建异常
      Parameters:
      message - the error message | 错误消息
      cause - the cause | 原因
    • OpenIdGenerationException

      public OpenIdGenerationException(String generatorType, String bizTag, String message)
      Creates an exception with generator type, bizTag and message 使用生成器类型、业务标识和消息创建异常
      Parameters:
      generatorType - the generator type | 生成器类型
      bizTag - the business tag | 业务标识
      message - the error message | 错误消息
    • OpenIdGenerationException

      public OpenIdGenerationException(String generatorType, String bizTag, String message, Throwable cause)
      Creates an exception with generator type, bizTag, message and cause 使用生成器类型、业务标识、消息和原因创建异常
      Parameters:
      generatorType - the generator type | 生成器类型
      bizTag - the business tag | 业务标识
      message - the error message | 错误消息
      cause - the cause | 原因
  • Method Details

    • generatorType

      public String generatorType()
      Gets the generator type 获取生成器类型
      Returns:
      generator type | 生成器类型
    • bizTag

      public String bizTag()
      Gets the business tag 获取业务标识
      Returns:
      business tag | 业务标识
    • clockBackward

      public static OpenIdGenerationException clockBackward(long lastTimestamp, long currentTimestamp)
      Creates a clock backward exception 创建时钟回拨异常
      Parameters:
      lastTimestamp - the last timestamp | 上次时间戳
      currentTimestamp - the current timestamp | 当前时间戳
      Returns:
      exception | 异常
    • invalidParameter

      public static OpenIdGenerationException invalidParameter(String param, long value, String range)
      Creates an invalid parameter exception 创建参数无效异常
      Parameters:
      param - the parameter name | 参数名称
      value - the parameter value | 参数值
      range - the valid range | 有效范围
      Returns:
      exception | 异常
    • segmentExhausted

      public static OpenIdGenerationException segmentExhausted(String bizTag)
      Creates a segment exhausted exception 创建号段耗尽异常
      Parameters:
      bizTag - the business tag | 业务标识
      Returns:
      exception | 异常
    • segmentAllocationFailed

      public static OpenIdGenerationException segmentAllocationFailed(String bizTag, Throwable cause)
      Creates a segment allocation failed exception 创建号段分配失败异常
      Parameters:
      bizTag - the business tag | 业务标识
      cause - the cause | 原因
      Returns:
      exception | 异常
    • invalidIdFormat

      public static OpenIdGenerationException invalidIdFormat(String generatorType, String id)
      Creates an invalid ID format exception 创建ID格式无效异常
      Parameters:
      generatorType - the generator type | 生成器类型
      id - the invalid ID | 无效的ID
      Returns:
      exception | 异常
    • sequenceOverflow

      public static OpenIdGenerationException sequenceOverflow(long maxSequence)
      Creates a sequence overflow exception 创建序列号溢出异常
      Parameters:
      maxSequence - the maximum sequence value | 最大序列号值
      Returns:
      exception | 异常
    • invalidPrefix

      public static OpenIdGenerationException invalidPrefix(String prefix)
      Creates an invalid prefix exception for typed/prefixed IDs 创建类型化ID的无效前缀异常
      Parameters:
      prefix - the invalid prefix | 无效的前缀
      Returns:
      exception | 异常
    • tableInitFailed

      public static OpenIdGenerationException tableInitFailed(String tableName, Throwable cause)
      Creates a table initialization failed exception 创建数据库表初始化失败异常
      Parameters:
      tableName - the table name | 表名
      cause - the underlying cause | 底层原因
      Returns:
      exception | 异常