Interface SegmentAllocator
- All Known Implementing Classes:
JdbcSegmentAllocator, MemorySegmentAllocator
public interface SegmentAllocator
Segment Allocator Interface
号段分配器接口
Interface for allocating ID segments from a central source. Implementations should handle concurrent access and persistence.
从中心源分配ID号段的接口。实现应处理并发访问和持久化。
Features | 主要功能:
- Segment allocation - 号段分配
- Business tag support - 业务标识支持
- Configurable step size - 可配置步长
Usage Examples | 使用示例:
SegmentAllocator allocator = JdbcSegmentAllocator.create(dataSource);
Segment segment = allocator.allocate("order");
for (long i = segment.start(); i < segment.end(); i++) {
// Use i as ID
}
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Since:
- JDK 25, opencode-base-id V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classSegment definition 号段定义 -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionAllocates a segment for the given business tag 为给定业务标识分配号段intgetStep()Gets the step size 获取步长
-
Field Details
-
DEFAULT_STEP
static final int DEFAULT_STEPDefault step size 默认步长- See Also:
-
-
Method Details
-
allocate
Allocates a segment for the given business tag 为给定业务标识分配号段- Parameters:
bizTag- the business tag | 业务标识- Returns:
- allocated segment | 分配的号段
-
getStep
int getStep()Gets the step size 获取步长- Returns:
- step size | 步长
-