org.infinispan.distribution.ch
Class AbstractConsistentHash

java.lang.Object
  extended by org.infinispan.distribution.ch.AbstractConsistentHash
All Implemented Interfaces:
ConsistentHash
Direct Known Subclasses:
AbstractWheelConsistentHash, ExperimentalDefaultConsistentHash, UnionConsistentHash

public abstract class AbstractConsistentHash
extends Object
implements ConsistentHash

An abstract consistent hash implementation that handles common implementations of certain methods. In particular, default implementations of locateAll(java.util.Collection, int) and isKeyLocalToAddress(org.infinispan.remoting.transport.Address, Object, int).

The versions provided here are relatively inefficient in that they call ConsistentHash.locate(Object, int) first (and sometimes in a loop). Depending on the algorithm used, there may be more efficient ways to achieve the same results and in such cases the methods provided here should be overridden.

Since:
4.0
Author:
Manik Surtani, Mircea.Markus@jboss.com

Field Summary
protected  GroupManager groupManager
           
 
Constructor Summary
AbstractConsistentHash()
           
 
Method Summary
 List<Address> getBackupsForNode(Address node, int replCount)
          Returns the nodes that backup data for the supplied node including the node itself.
protected  Object getGrouping(Object key)
          Get the grouping, if any, for this key.
 List<Address> getStateProvidersOnJoin(Address joiner, int replCount)
          Returns the nodes that would act as state providers when a new node joins: - the nodes for which the joiner is a backup - the nodes that held joiner's state
 List<Address> getStateProvidersOnLeave(Address leaver, int replCount)
          Returns the nodes that need will replicate their state if the specified node crashes.
 boolean isKeyLocalToAddress(Address a, Object key, int replCount)
          Test to see whether a key is mapped to a given address.
 Map<Object,List<Address>> locateAll(Collection<Object> keys, int replCount)
          The logical equivalent of calling ConsistentHash.locate(Object, int) multiple times for each key in the collection of keys.
 void setGroupManager(GroupManager groupManager)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHash
getCaches, getHashIds, locate, setCaches
 

Field Detail

groupManager

protected GroupManager groupManager
Constructor Detail

AbstractConsistentHash

public AbstractConsistentHash()
Method Detail

locateAll

public Map<Object,List<Address>> locateAll(Collection<Object> keys,
                                           int replCount)
Description copied from interface: ConsistentHash
The logical equivalent of calling ConsistentHash.locate(Object, int) multiple times for each key in the collection of keys. Implementations may be optimised for such a bulk lookup, or may just repeatedly call ConsistentHash.locate(Object, int).

Specified by:
locateAll in interface ConsistentHash
Parameters:
keys - keys to locate
replCount - replication count (number of copies) for each key
Returns:
Map of locations, keyed on key.

isKeyLocalToAddress

public boolean isKeyLocalToAddress(Address a,
                                   Object key,
                                   int replCount)
Description copied from interface: ConsistentHash
Test to see whether a key is mapped to a given address.

Specified by:
isKeyLocalToAddress in interface ConsistentHash
Parameters:
a - address to test
key - key to test
replCount - repl count
Returns:
true if the key is mapped to the address; false otherwise

setGroupManager

public void setGroupManager(GroupManager groupManager)

getStateProvidersOnLeave

public List<Address> getStateProvidersOnLeave(Address leaver,
                                              int replCount)
Description copied from interface: ConsistentHash
Returns the nodes that need will replicate their state if the specified node crashes. The return collection should contain all the nodes that backup-ed on leaver and one of the nodes which acted as a backup for the leaver .

Pre: leaver must be present in the caches known to this CH, as returned by ConsistentHash.getCaches()

Specified by:
getStateProvidersOnLeave in interface ConsistentHash
Parameters:
leaver - the node that leaves the cluster

getStateProvidersOnJoin

public List<Address> getStateProvidersOnJoin(Address joiner,
                                             int replCount)
Description copied from interface: ConsistentHash
Returns the nodes that would act as state providers when a new node joins: - the nodes for which the joiner is a backup - the nodes that held joiner's state

Specified by:
getStateProvidersOnJoin in interface ConsistentHash

getBackupsForNode

public List<Address> getBackupsForNode(Address node,
                                       int replCount)
Description copied from interface: ConsistentHash
Returns the nodes that backup data for the supplied node including the node itself.

Specified by:
getBackupsForNode in interface ConsistentHash

toString

public String toString()
Overrides:
toString in class Object

getGrouping

protected Object getGrouping(Object key)
Get the grouping, if any, for this key.

Parameters:
key - the key to get the grouping for
Returns:
the group, or if no group is applicable, the key

-->

Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.