Interface ClockBackwardStrategy

All Known Subinterfaces:
ClockBackwardStrategy.Custom
All Known Implementing Classes:
Extend, ThrowException, Wait

public sealed interface ClockBackwardStrategy permits Wait, ThrowException, Extend, ClockBackwardStrategy.Custom
Clock Backward Handling Strategy 时钟回拨处理策略

Sealed interface defining strategies to handle clock backward movement. Clock backward occurs when the system clock moves to an earlier time, which can cause duplicate IDs if not handled properly.

定义处理时钟回拨策略的密封接口。当系统时钟回退到更早的时间时会发生时钟回拨, 如果不正确处理可能导致ID重复。

Available Strategies | 可用策略:

  • Wait - Wait for clock to catch up | 等待时钟追上
  • ThrowException - Throw exception immediately | 立即抛出异常
  • Extend - Use extension bits | 使用扩展位

Usage Examples | 使用示例:

// Wait strategy with 5 second timeout
ClockBackwardStrategy wait = Wait.ofSeconds(5);

// Throw exception strategy (singleton)
ClockBackwardStrategy throwEx = ThrowException.getInstance();

// Extension bits strategy
ClockBackwardStrategy extend = new Extend(2);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是

Features | 主要功能:

  • Strategy interface for handling clock backward events - 处理时钟回拨事件的策略接口
  • Pluggable clock drift resolution - 可插拔的时钟漂移解决方案
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Custom strategy interface for user-defined implementations 用于用户自定义实现的自定义策略接口
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    handle(long lastTimestamp, long currentTimestamp)
    Handles clock backward movement 处理时钟回拨
  • Method Details

    • handle

      long handle(long lastTimestamp, long currentTimestamp)
      Handles clock backward movement 处理时钟回拨
      Parameters:
      lastTimestamp - the last timestamp used | 上次使用的时间戳
      currentTimestamp - the current (backward) timestamp | 当前(回拨的)时间戳
      Returns:
      the timestamp to use | 要使用的时间戳