Class OpenIdGenerationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.id.exception.OpenIdGenerationException
- All Implemented Interfaces:
Serializable
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 | 错误码:
ERR_CLOCK_BACKWARD- Clock moved backwards | 时钟回拨ERR_INVALID_PARAMETER- Invalid configuration parameter | 参数无效ERR_SEGMENT_EXHAUSTED- ID segment exhausted | 号段耗尽ERR_SEGMENT_FAILED- Segment allocation failed | 号段分配失败ERR_INVALID_FORMAT- Invalid ID format | ID格式无效ERR_SEQUENCE_OVERFLOW- Sequence counter overflow | 序列号溢出ERR_INVALID_PREFIX- Invalid typed ID prefix | 无效前缀ERR_TABLE_INIT_FAILED- Database table init failed | 数据库表初始化失败
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClock moved backwards | 时钟回拨static final StringInvalid ID format | ID格式无效static final StringInvalid configuration parameter | 参数无效static final StringInvalid typed ID prefix | 无效前缀static final StringID segment exhausted | 号段耗尽static final StringSegment allocation failed | 号段分配失败static final StringSequence counter overflow | 序列号溢出static final StringDatabase table initialization failed | 数据库表初始化失败 -
Constructor Summary
ConstructorsConstructorDescriptionOpenIdGenerationException(String message) Creates an exception with message 使用消息创建异常OpenIdGenerationException(String generatorType, String bizTag, String message) Creates an exception with generator type, bizTag and message 使用生成器类型、业务标识和消息创建异常OpenIdGenerationException(String generatorType, String bizTag, String message, Throwable cause) Creates an exception with generator type, bizTag, message and cause 使用生成器类型、业务标识、消息和原因创建异常OpenIdGenerationException(String message, Throwable cause) Creates an exception with message and cause 使用消息和原因创建异常 -
Method Summary
Modifier and TypeMethodDescriptionbizTag()Gets the business tag 获取业务标识static OpenIdGenerationExceptionclockBackward(long lastTimestamp, long currentTimestamp) Creates a clock backward exception 创建时钟回拨异常Gets the generator type 获取生成器类型static OpenIdGenerationExceptioninvalidIdFormat(String generatorType, String id) Creates an invalid ID format exception 创建ID格式无效异常static OpenIdGenerationExceptioninvalidParameter(String param, long value, String range) Creates an invalid parameter exception 创建参数无效异常static OpenIdGenerationExceptioninvalidPrefix(String prefix) Creates an invalid prefix exception for typed/prefixed IDs 创建类型化ID的无效前缀异常static OpenIdGenerationExceptionsegmentAllocationFailed(String bizTag, Throwable cause) Creates a segment allocation failed exception 创建号段分配失败异常static OpenIdGenerationExceptionsegmentExhausted(String bizTag) Creates a segment exhausted exception 创建号段耗尽异常static OpenIdGenerationExceptionsequenceOverflow(long maxSequence) Creates a sequence overflow exception 创建序列号溢出异常static OpenIdGenerationExceptiontableInitFailed(String tableName, Throwable cause) Creates a table initialization failed exception 创建数据库表初始化失败异常Methods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
ERR_CLOCK_BACKWARD
-
ERR_INVALID_PARAMETER
-
ERR_SEGMENT_EXHAUSTED
-
ERR_SEGMENT_FAILED
-
ERR_INVALID_FORMAT
-
ERR_SEQUENCE_OVERFLOW
-
ERR_INVALID_PREFIX
-
ERR_TABLE_INIT_FAILED
Database table initialization failed | 数据库表初始化失败- See Also:
-
-
Constructor Details
-
OpenIdGenerationException
Creates an exception with message 使用消息创建异常- Parameters:
message- the error message | 错误消息
-
OpenIdGenerationException
-
OpenIdGenerationException
-
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
-
bizTag
-
clockBackward
Creates a clock backward exception 创建时钟回拨异常- Parameters:
lastTimestamp- the last timestamp | 上次时间戳currentTimestamp- the current timestamp | 当前时间戳- Returns:
- exception | 异常
-
invalidParameter
Creates an invalid parameter exception 创建参数无效异常- Parameters:
param- the parameter name | 参数名称value- the parameter value | 参数值range- the valid range | 有效范围- Returns:
- exception | 异常
-
segmentExhausted
Creates a segment exhausted exception 创建号段耗尽异常- Parameters:
bizTag- the business tag | 业务标识- Returns:
- exception | 异常
-
segmentAllocationFailed
Creates a segment allocation failed exception 创建号段分配失败异常- Parameters:
bizTag- the business tag | 业务标识cause- the cause | 原因- Returns:
- exception | 异常
-
invalidIdFormat
Creates an invalid ID format exception 创建ID格式无效异常- Parameters:
generatorType- the generator type | 生成器类型id- the invalid ID | 无效的ID- Returns:
- exception | 异常
-
sequenceOverflow
Creates a sequence overflow exception 创建序列号溢出异常- Parameters:
maxSequence- the maximum sequence value | 最大序列号值- Returns:
- exception | 异常
-
invalidPrefix
Creates an invalid prefix exception for typed/prefixed IDs 创建类型化ID的无效前缀异常- Parameters:
prefix- the invalid prefix | 无效的前缀- Returns:
- exception | 异常
-
tableInitFailed
Creates a table initialization failed exception 创建数据库表初始化失败异常- Parameters:
tableName- the table name | 表名cause- the underlying cause | 底层原因- Returns:
- exception | 异常
-