Interface WorkerIdAssigner

All Known Implementing Classes:
FixedWorkerIdAssigner, IpBasedAssigner, MacBasedAssigner, RandomAssigner

public interface WorkerIdAssigner
Worker ID Assigner Interface 工作节点ID分配器接口

Provides automatic assignment of worker ID and datacenter ID for Snowflake generator. This is especially useful in containerized or Kubernetes environments.

为雪花ID生成器提供工作节点ID和数据中心ID的自动分配。 这在容器化或Kubernetes环境中特别有用。

Built-in Implementations | 内置实现:

Usage Examples | 使用示例:

SnowflakeGenerator gen = new SnowflakeBuilder()
    .workerIdAssigner(IpBasedAssigner.create())
    .build();

Features | 主要功能:

  • Strategy interface for assigning Snowflake worker IDs - 分配Snowflake工作ID的策略接口
  • Pluggable worker identification mechanism - 可插拔的工作节点标识机制

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-id V1.1.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Assigns a datacenter ID 分配数据中心ID
    long
    Assigns a worker ID 分配工作节点ID
    default String
    Gets a description of the assignment strategy 获取分配策略描述
  • Method Details

    • assignWorkerId

      long assignWorkerId()
      Assigns a worker ID 分配工作节点ID
      Returns:
      worker ID within valid range | 有效范围内的工作节点ID
    • assignDatacenterId

      long assignDatacenterId()
      Assigns a datacenter ID 分配数据中心ID
      Returns:
      datacenter ID within valid range | 有效范围内的数据中心ID
    • getStrategyName

      default String getStrategyName()
      Gets a description of the assignment strategy 获取分配策略描述
      Returns:
      strategy description | 策略描述