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: http://weblogs.java.net/blog/tomwhite/archive/2007/11/consistent_hash.html

    Note that toString of the ring nodes are used for the node hash, i.e. make sure it is different for different nodes.

    • 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
        Parameters:
        nodes - (undocumented)
        virtualNodesFactor - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        node - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        node - (undocumented)
        Returns:
        (undocumented)
      • $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.
        Parameters:
        node - (undocumented)
        Returns:
        (undocumented)
      • 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.
        Parameters:
        node - (undocumented)
        Returns:
        (undocumented)
      • 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
        Parameters:
        key - (undocumented)
        Returns:
        (undocumented)
      • 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
        Parameters:
        key - (undocumented)
        Returns:
        (undocumented)
      • isEmpty

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