org.infinispan.distribution.ch
Class ExperimentalDefaultConsistentHash

java.lang.Object
  extended by org.infinispan.distribution.ch.AbstractConsistentHash
      extended by org.infinispan.distribution.ch.ExperimentalDefaultConsistentHash
All Implemented Interfaces:
ConsistentHash

public class ExperimentalDefaultConsistentHash
extends AbstractConsistentHash

Consistent hashing algorithm. Each target is entered into the pool weight[i]*weightFactor times. Where weight[i] and weightFactor are integers greater than zero.

Based on akluge's impl on http://www.vizitsolutions.com/ConsistentHashingCaching.html

Author:
akluge, Manik Surtani

Nested Class Summary
static class ExperimentalDefaultConsistentHash.Entry
          An entry into a consistent hash.
static class ExperimentalDefaultConsistentHash.Externalizer
           
 
Field Summary
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
caches, groupManager
 
Constructor Summary
ExperimentalDefaultConsistentHash()
           
 
Method Summary
 boolean equals(Object other)
           
 List<Address> getBackupsForNode(Address node, int replCount)
          Returns the nodes that backup data for the supplied node including the node itself.
 Set<Address> getCaches()
          Should return a collection of cache addresses in the cluster.
 int getDistance(Address a1, Address a2)
          The distance between the first entries in the address array for two caches, a1 and a2.
 int getHashId(Address a)
          Returns the value between 0 and the hash space limit, or hash id, for a particular address.
 int getHashSpace()
          Returns the hash space constant for this consistent hash algorithm class.
 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.
 int hashCode()
           
 boolean isAdjacent(Address a1, Address a2)
          Two hashes are adjacent if they are next to each other in the consistent hash.
 List<Address> locate(Object key, int replCount)
          Locates a key, given a replication count (number of copies).
 void setCaches(List<Address> caches)
           
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getGrouping, isKeyLocalToAddress, locateAll, setCaches, setGroupManager
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExperimentalDefaultConsistentHash

public ExperimentalDefaultConsistentHash()
Method Detail

getCaches

public Set<Address> getCaches()
Description copied from interface: ConsistentHash
Should return a collection of cache addresses in the cluster.

Specified by:
getCaches in interface ConsistentHash
Overrides:
getCaches in class AbstractConsistentHash
Returns:
set of unique of cache addresses

setCaches

public void setCaches(List<Address> caches)

getDistance

public int getDistance(Address a1,
                       Address a2)
The distance between the first entries in the address array for two caches, a1 and a2. Of questionable use when virtual nodes are employed.

Parameters:
a1 - The address of the first cache.
a2 - The address of the second cache.
Returns:
Am int containing the difference between these two indices.

isAdjacent

public boolean isAdjacent(Address a1,
                          Address a2)
Two hashes are adjacent if they are next to each other in the consistent hash.

Parameters:
a1 - The address of the first cache.
a2 - The address of the second cache.
Returns:
A boolean, true if they are adjacent, false if not.

locate

public List<Address> locate(Object key,
                            int replCount)
Description copied from interface: ConsistentHash
Locates a key, given a replication count (number of copies).

Parameters:
key - key to locate
replCount - replication count (number of copies)
Returns:
a list of addresses where the key resides, where this list is a subset of the addresses set in ConsistentHash.setCaches(java.util.Set). Should never be null, and should contain replCount elements or the max number of caches available, whichever is smaller.

getHashId

public int getHashId(Address a)
Description copied from interface: ConsistentHash
Returns the value between 0 and the hash space limit, or hash id, for a particular address. If there's no such value for an address, this method will return -1.

Returns:
An int between 0 and hash space if the address is present in the hash wheel, otherwise it returns -1.

getHashSpace

public int getHashSpace()
Description copied from interface: ConsistentHash
Returns the hash space constant for this consistent hash algorithm class. This integer is often used as modulus for arithmetic operations within the algorithm, for example, limiting the range of possible hash values.

Returns:
A positive integer containing the hash space constant or 0 is not supported by implementation.

toString

public String toString()
Overrides:
toString in class AbstractConsistentHash
Returns:
A String representing the object pool.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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

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


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.


-->

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