net.spy.memcached
Class KetamaNodeLocator

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.KetamaNodeLocator
All Implemented Interfaces:
NodeLocator

public final class KetamaNodeLocator
extends SpyObject
implements NodeLocator

This is an implementation of the Ketama consistent hash strategy from last.fm. This implementation may not be compatible with libketama as hashing is considered separate from node location. Note that this implementation does not currently supported weighted nodes.

See Also:
RJ's blog post

Constructor Summary
KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg)
           
KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf)
           
 
Method Summary
 Collection<MemcachedNode> getAll()
          Get all memcached nodes.
 MemcachedNode getPrimary(String k)
          Get the primary location for the given key.
 NodeLocator getReadonlyCopy()
          Create a read-only copy of this NodeLocator.
 Iterator<MemcachedNode> getSequence(String k)
          Get an iterator over the sequence of nodes that make up the backup locations for a given key.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KetamaNodeLocator

public KetamaNodeLocator(List<MemcachedNode> nodes,
                         HashAlgorithm alg)

KetamaNodeLocator

public KetamaNodeLocator(List<MemcachedNode> nodes,
                         HashAlgorithm alg,
                         KetamaNodeLocatorConfiguration conf)
Method Detail

getAll

public Collection<MemcachedNode> getAll()
Description copied from interface: NodeLocator
Get all memcached nodes. This is useful for broadcasting messages.

Specified by:
getAll in interface NodeLocator

getPrimary

public MemcachedNode getPrimary(String k)
Description copied from interface: NodeLocator
Get the primary location for the given key.

Specified by:
getPrimary in interface NodeLocator
Parameters:
k - the object key
Returns:
the QueueAttachment containing the primary storage for a key

getSequence

public Iterator<MemcachedNode> getSequence(String k)
Description copied from interface: NodeLocator
Get an iterator over the sequence of nodes that make up the backup locations for a given key.

Specified by:
getSequence in interface NodeLocator
Parameters:
k - the object key
Returns:
the sequence of backup nodes.

getReadonlyCopy

public NodeLocator getReadonlyCopy()
Description copied from interface: NodeLocator
Create a read-only copy of this NodeLocator.

Specified by:
getReadonlyCopy in interface NodeLocator