Package org.apache.pekko.routing
Class ConsistentHash<T>
java.lang.Object
org.apache.pekko.routing.ConsistentHash<T>
Consistent Hashing node ring implementation.
A good explanation of Consistent Hashing: https://tom-e-white.com/2007/11/consistent-hashing.html
Note that toString of the ring nodes are used for the node hash, i.e. make sure it is different for different nodes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription$colon$minus(T node) Removes a node from the node ring.$colon$plus(T node) Adds a node to the node ring.Java API: Adds a node to the node ring.static <T> ConsistentHash<T>apply(scala.collection.Iterable<T> nodes, int virtualNodesFactor, scala.reflect.ClassTag<T> evidence$2) static <T> ConsistentHash<T>Java API: Factory method to create a ConsistentHashbooleanisEmpty()Is the node ring empty, i.e.nodeFor(byte[] key) Get the node responsible for the data key.Get the node responsible for the data key.Java API: Removes a node from the node ring.int
-
Constructor Details
-
ConsistentHash
public ConsistentHash()
-
-
Method Details
-
apply
public static <T> ConsistentHash<T> apply(scala.collection.Iterable<T> nodes, int virtualNodesFactor, scala.reflect.ClassTag<T> evidence$2) -
create
Java API: Factory method to create a ConsistentHash -
virtualNodesFactor
public int virtualNodesFactor() -
$colon$plus
Adds a node to the node ring. Note that the instance is immutable and this operation returns a new instance. -
add
Java API: Adds a node to the node ring. Note that the instance is immutable and this operation returns a new instance. -
$colon$minus
Removes a node from the node ring. Note that the instance is immutable and this operation returns a new instance. -
remove
Java API: Removes a node from the node ring. Note that the instance is immutable and this operation returns a new instance. -
nodeFor
Get the node responsible for the data key. Can only be used if nodes exists in the node ring, otherwise throwsIllegalStateException -
nodeFor
Get the node responsible for the data key. Can only be used if nodes exists in the node ring, otherwise throwsIllegalStateException -
isEmpty
public boolean isEmpty()Is the node ring empty, i.e. no nodes added or all removed.
-