T - the ring node typepublic class ConsistentHash<T> extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
ConsistentHash.HashFunction
Hash String to long value
|
| 构造器和说明 |
|---|
ConsistentHash(Collection<T> pNodes,
int vNodeCount) |
ConsistentHash(Collection<T> pNodes,
int vNodeCount,
Function<T,String> keyMapper) |
ConsistentHash(Collection<T> pNodes,
int vNodeCount,
Function<T,String> keyMapper,
ConsistentHash.HashFunction hashFunction) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addNode(T pNode,
int vNodeCount)
Add physic node to the hash ring with some virtual nodes
|
int |
getExistingReplicas(T pNode) |
void |
removeNode(T pNode)
Remove the physical node from the hash ring
|
T |
routeNode(String key)
Returns the physical node of counted specified key
|
public ConsistentHash(Collection<T> pNodes, int vNodeCount)
public ConsistentHash(Collection<T> pNodes, int vNodeCount, Function<T,String> keyMapper)
public ConsistentHash(Collection<T> pNodes, int vNodeCount, Function<T,String> keyMapper, ConsistentHash.HashFunction hashFunction)
pNodes - collections of physical nodesvNodeCount - number of virtual nodeskeyMapper - physical node mapping to string key functionhashFunction - hash function to hash node instancespublic void addNode(T pNode, int vNodeCount)
pNode - physical nodevNodeCount - the number virtual node of the physical node.public void removeNode(T pNode)
pNode - the physical nodepublic T routeNode(String key)
key - the key to find the nearest physical nodepublic int getExistingReplicas(T pNode)
Copyright © 2023. All rights reserved.