Record Class VirtualNode<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.hash.consistent.VirtualNode<T>
Type Parameters:
T - data type | 数据类型

Usage Examples | 使用示例:

// Virtual nodes map to physical nodes
// 虚拟节点映射到物理节点
HashNode physical = new HashNode("server-1");
VirtualNode<HashNode> vnode = new VirtualNode<>(physical, 0);

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No - 空值安全: 否
Record Components:
physicalNode - the physical node this virtual node belongs to | 此虚拟节点所属的物理节点
replicaIndex - the replica index (0-based) | 副本索引(从0开始)
hashValue - the hash value (position on ring) | 哈希值(环上的位置)

public record VirtualNode<T>(HashNode<T> physicalNode, int replicaIndex, long hashValue) extends Record
Virtual node in consistent hash ring 一致性哈希环中的虚拟节点

Represents a virtual node that maps to a physical node. Virtual nodes help achieve more uniform distribution of keys across physical nodes.

表示映射到物理节点的虚拟节点。虚拟节点有助于在物理节点间实现更均匀的键分布。

Features | 主要功能:

  • Maps to physical node - 映射到物理节点
  • Has position on hash ring - 在哈希环上有位置
  • Identified by replica number - 通过副本号标识
Since:
JDK 25, opencode-base-hash V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    VirtualNode(HashNode<T> physicalNode, int replicaIndex, long hashValue)
    Creates an instance of a VirtualNode record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the physical node's data 获取物理节点的数据
    final boolean
    Indicates whether some other object is "equal to" this one.
    Gets the key used for hashing this virtual node 获取用于哈希此虚拟节点的键
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the hashValue record component.
    static <T> VirtualNode<T>
    of(HashNode<T> physicalNode, int replicaIndex, long hashValue)
    Creates a virtual node 创建虚拟节点
    Returns the value of the physicalNode record component.
    Gets the physical node's id 获取物理节点的ID
    int
    Returns the value of the replicaIndex record component.
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • VirtualNode

      public VirtualNode(HashNode<T> physicalNode, int replicaIndex, long hashValue)
      Creates an instance of a VirtualNode record class.
      Parameters:
      physicalNode - the value for the physicalNode record component
      replicaIndex - the value for the replicaIndex record component
      hashValue - the value for the hashValue record component
  • Method Details

    • physicalNodeId

      public String physicalNodeId()
      Gets the physical node's id 获取物理节点的ID
      Returns:
      physical node id | 物理节点ID
    • data

      public T data()
      Gets the physical node's data 获取物理节点的数据
      Returns:
      node data | 节点数据
    • getKey

      public String getKey()
      Gets the key used for hashing this virtual node 获取用于哈希此虚拟节点的键
      Returns:
      virtual node key | 虚拟节点键
    • of

      public static <T> VirtualNode<T> of(HashNode<T> physicalNode, int replicaIndex, long hashValue)
      Creates a virtual node 创建虚拟节点
      Type Parameters:
      T - data type | 数据类型
      Parameters:
      physicalNode - physical node | 物理节点
      replicaIndex - replica index | 副本索引
      hashValue - hash value | 哈希值
      Returns:
      virtual node | 虚拟节点
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • physicalNode

      public HashNode<T> physicalNode()
      Returns the value of the physicalNode record component.
      Returns:
      the value of the physicalNode record component
    • replicaIndex

      public int replicaIndex()
      Returns the value of the replicaIndex record component.
      Returns:
      the value of the replicaIndex record component
    • hashValue

      public long hashValue()
      Returns the value of the hashValue record component.
      Returns:
      the value of the hashValue record component