Class Wait
java.lang.Object
cloud.opencode.base.id.snowflake.Wait
- All Implemented Interfaces:
ClockBackwardStrategy
Wait Strategy for Clock Backward Handling
时钟回拨等待策略
Waits for the clock to catch up when clock backward is detected. If the wait time exceeds the maximum allowed, throws an exception.
检测到时钟回拨时等待时钟追上。如果等待时间超过最大允许值,则抛出异常。
Features | 主要功能:
- Configurable wait timeout - 可配置等待超时
- Graceful handling for small backward - 小幅回拨优雅处理
- Fail-fast for large backward - 大幅回拨快速失败
Usage Examples | 使用示例:
// Wait up to 5 seconds
Wait wait = Wait.ofSeconds(5);
// Wait up to 100 milliseconds
Wait waitMs = Wait.ofMillis(100);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-id V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ClockBackwardStrategy
ClockBackwardStrategy.Custom -
Constructor Summary
ConstructorsConstructorDescriptionWait(long maxWaitMillis) Creates a wait strategy with maximum wait time 使用最大等待时间创建等待策略 -
Method Summary
Modifier and TypeMethodDescriptionlonghandle(long lastTimestamp, long currentTimestamp) Handles clock backward movement 处理时钟回拨longGets the maximum wait time in milliseconds 获取最大等待时间(毫秒)static WaitofMillis(long millis) Creates a wait strategy with milliseconds timeout 使用毫秒数超时创建等待策略static WaitofSeconds(int seconds) Creates a wait strategy with seconds timeout 使用秒数超时创建等待策略toString()
-
Constructor Details
-
Wait
public Wait(long maxWaitMillis) Creates a wait strategy with maximum wait time 使用最大等待时间创建等待策略- Parameters:
maxWaitMillis- the maximum wait time in milliseconds | 最大等待时间(毫秒)
-
-
Method Details
-
ofSeconds
Creates a wait strategy with seconds timeout 使用秒数超时创建等待策略- Parameters:
seconds- the timeout in seconds | 超时秒数- Returns:
- wait strategy | 等待策略
-
ofMillis
Creates a wait strategy with milliseconds timeout 使用毫秒数超时创建等待策略- Parameters:
millis- the timeout in milliseconds | 超时毫秒数- Returns:
- wait strategy | 等待策略
-
maxWaitMillis
public long maxWaitMillis()Gets the maximum wait time in milliseconds 获取最大等待时间(毫秒)- Returns:
- maximum wait time | 最大等待时间
-
handle
public long handle(long lastTimestamp, long currentTimestamp) Description copied from interface:ClockBackwardStrategyHandles clock backward movement 处理时钟回拨- Specified by:
handlein interfaceClockBackwardStrategy- Parameters:
lastTimestamp- the last timestamp used | 上次使用的时间戳currentTimestamp- the current (backward) timestamp | 当前(回拨的)时间戳- Returns:
- the timestamp to use | 要使用的时间戳
-
toString
-