net.spy.memcached.util
Class DefaultKetamaNodeLocatorConfiguration

java.lang.Object
  extended by net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration
All Implemented Interfaces:
KetamaNodeLocatorConfiguration

public class DefaultKetamaNodeLocatorConfiguration
extends Object
implements KetamaNodeLocatorConfiguration

A Default implementation of the configuration required for the KetamaNodeLocator algorithm to run.


Field Summary
protected  Map<MemcachedNode,String> socketAddresses
           
 
Constructor Summary
DefaultKetamaNodeLocatorConfiguration()
           
 
Method Summary
 String getKeyForNode(MemcachedNode node, int repetition)
          Returns a uniquely identifying key, suitable for hashing by the KetamaNodeLocator algorithm.
 int getNodeRepetitions()
          Returns the number of discrete hashes that should be defined for each node in the continuum.
protected  String getSocketAddressForNode(MemcachedNode node)
          Returns the socket address of a given MemcachedNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socketAddresses

protected Map<MemcachedNode,String> socketAddresses
Constructor Detail

DefaultKetamaNodeLocatorConfiguration

public DefaultKetamaNodeLocatorConfiguration()
Method Detail

getSocketAddressForNode

protected String getSocketAddressForNode(MemcachedNode node)
Returns the socket address of a given MemcachedNode.

Parameters:
node - The node which we're interested in
Returns:
String the socket address of that node.

getNodeRepetitions

public int getNodeRepetitions()
Returns the number of discrete hashes that should be defined for each node in the continuum.

Specified by:
getNodeRepetitions in interface KetamaNodeLocatorConfiguration
Returns:
NUM_REPS repetitions.

getKeyForNode

public String getKeyForNode(MemcachedNode node,
                            int repetition)
Returns a uniquely identifying key, suitable for hashing by the KetamaNodeLocator algorithm.

This default implementation uses the socket-address of the MemcachedNode and concatenates it with a hyphen directly against the repetition number for example a key for a particular server's first repetition may look like:

myhost/10.0.2.1-0

for the second repetition

myhost/10.0.2.1-1

for a server where reverse lookups are failing the returned keys may look like

/10.0.2.1-0 and /10.0.2.1-1

Specified by:
getKeyForNode in interface KetamaNodeLocatorConfiguration
Parameters:
node - The MemcachedNode to use to form the unique identifier
repetition - The repetition number for the particular node in question (0 is the first repetition)
Returns:
The key that represents the specific repetition of the node