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
ConstructorsConstructorDescriptionVirtualNode(HashNode<T> physicalNode, int replicaIndex, long hashValue) Creates an instance of aVirtualNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptiondata()Gets the physical node's data 获取物理节点的数据final booleanIndicates whether some other object is "equal to" this one.getKey()Gets the key used for hashing this virtual node 获取用于哈希此虚拟节点的键final inthashCode()Returns a hash code value for this object.longReturns the value of thehashValuerecord component.static <T> VirtualNode<T> Creates a virtual node 创建虚拟节点Returns the value of thephysicalNoderecord component.Gets the physical node's id 获取物理节点的IDintReturns the value of thereplicaIndexrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
VirtualNode
Creates an instance of aVirtualNoderecord class.- Parameters:
physicalNode- the value for thephysicalNoderecord componentreplicaIndex- the value for thereplicaIndexrecord componenthashValue- the value for thehashValuerecord component
-
-
Method Details
-
physicalNodeId
Gets the physical node's id 获取物理节点的ID- Returns:
- physical node id | 物理节点ID
-
data
-
getKey
Gets the key used for hashing this virtual node 获取用于哈希此虚拟节点的键- Returns:
- virtual node key | 虚拟节点键
-
of
Creates a virtual node 创建虚拟节点- Type Parameters:
T- data type | 数据类型- Parameters:
physicalNode- physical node | 物理节点replicaIndex- replica index | 副本索引hashValue- hash value | 哈希值- Returns:
- virtual node | 虚拟节点
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
physicalNode
Returns the value of thephysicalNoderecord component.- Returns:
- the value of the
physicalNoderecord component
-
replicaIndex
public int replicaIndex()Returns the value of thereplicaIndexrecord component.- Returns:
- the value of the
replicaIndexrecord component
-
hashValue
-