akka.routing
Class ConsistentHash<T>

java.lang.Object
  extended by akka.routing.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 Summary
 ConsistentHash<T> add(T node)
          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>
create(java.lang.Iterable<T> nodes, int virtualNodesFactor)
          Java API: Factory method to create a ConsistentHash
 boolean isEmpty()
          Is the node ring empty, i.e. no nodes added or all removed.
 T nodeFor(byte[] key)
          Get the node responsible for the data key.
 T nodeFor(java.lang.String key)
          Get the node responsible for the data key.
 ConsistentHash<T> remove(T node)
          Java API: Removes a node from the node ring.
 int virtualNodesFactor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()

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.


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.