T - the type of node to be used in the ringpublic final class HashRing<T extends Node> extends java.lang.Object implements ConsistentHash<T>
TreeMap| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T node)
Add node to the consistent hash
|
boolean |
addAll(java.util.Collection<T> nodes)
Add all nodes to the consistent hash
|
boolean |
contains(T node)
Check if consistent hash contains node
|
Hasher |
getHasher() |
java.lang.String |
getName()
Return name of the consistent hash instance
|
java.util.Set<T> |
getNodes()
Return list of all nodes that consistent hash contains
|
int |
getPartitionRate() |
java.util.Optional<T> |
locate(java.lang.String key)
Find node which most matches the key
|
java.util.Set<T> |
locate(java.lang.String key,
int count)
Find nodes which most matches the key
|
static <T extends Node> |
newBuilder()
Create instance of
HashRingBuilder |
boolean |
remove(T node)
Remove node from the consistent hash
|
int |
size()
Return number of nodes inside consistent hash
|
java.lang.String |
toString() |
public static <T extends Node> HashRingBuilder<T> newBuilder()
HashRingBuilderT - the type of nodepublic boolean add(T node)
ConsistentHashadd in interface ConsistentHash<T extends Node>node - the node to be addedpublic boolean addAll(java.util.Collection<T> nodes)
ConsistentHashaddAll in interface ConsistentHash<T extends Node>nodes - the nodes to be addedpublic boolean contains(T node)
ConsistentHashcontains in interface ConsistentHash<T extends Node>node - the node to be checkedpublic boolean remove(T node)
ConsistentHashremove in interface ConsistentHash<T extends Node>node - the node to be removedpublic java.util.Set<T> getNodes()
ConsistentHashgetNodes in interface ConsistentHash<T extends Node>public java.util.Optional<T> locate(java.lang.String key)
ConsistentHashlocate in interface ConsistentHash<T extends Node>key - the keyOptional.empty() if no node was foundpublic java.util.Set<T> locate(java.lang.String key, int count)
ConsistentHashlocate in interface ConsistentHash<T extends Node>key - the keycount - the amount of nodes to be matchedpublic java.lang.String getName()
ConsistentHashgetName in interface ConsistentHash<T extends Node>public int size()
ConsistentHashsize in interface ConsistentHash<T extends Node>public Hasher getHasher()
public int getPartitionRate()
public java.lang.String toString()
toString in class java.lang.Object