Package akka.routing

Class ConsistentHash<T>


  • public class ConsistentHash<T>
    extends java.lang.Object
    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 Detail

      • ConsistentHash

        public ConsistentHash()
    • Method Detail

      • apply

        public static <T> ConsistentHash<T> apply​(scala.collection.Iterable<T> nodes,
                                                  int virtualNodesFactor,
                                                  scala.reflect.ClassTag<T> evidence$2)
      • create

        public static <T> ConsistentHash<T> create​(java.lang.Iterable<T> nodes,
                                                   int virtualNodesFactor)
        Java API: Factory method to create a ConsistentHash
      • virtualNodesFactor

        public int virtualNodesFactor()
      • $colon$plus

        public ConsistentHash<T> $colon$plus​(T node)
        Adds a node to the node ring. Note that the instance is immutable and this operation returns a new instance.
      • add

        public ConsistentHash<T> add​(T node)
        Java API: Adds a node to the node ring. Note that the instance is immutable and this operation returns a new instance.
      • $colon$minus

        public ConsistentHash<T> $colon$minus​(T node)
        Removes a node from the node ring. Note that the instance is immutable and this operation returns a new instance.
      • remove

        public ConsistentHash<T> remove​(T node)
        Java API: Removes a node from the node ring. Note that the instance is immutable and this operation returns a new instance.
      • nodeFor

        public T nodeFor​(byte[] key)
        Get the node responsible for the data key. Can only be used if nodes exists in the node ring, otherwise throws IllegalStateException
      • nodeFor

        public T nodeFor​(java.lang.String key)
        Get the node responsible for the data key. Can only be used if nodes exists in the node ring, otherwise throws IllegalStateException
      • isEmpty

        public boolean isEmpty()
        Is the node ring empty, i.e. no nodes added or all removed.