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
groupManager
 
Constructor Summary
ExperimentalDefaultConsistentHash()
           
 
Method Summary
 boolean equals(Object other)
           
 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.
 List<Integer> getHashIds(Address a)
          Returns a list of values between 0 and the hash space limit, or hash id, for a particular address.
 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(Collection<Address> caches)
           
 void setCaches(Set<Address> caches)
          Sets the collection of cache addresses in the cluster.
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, isKeyLocalToAddress, locateAll, primaryLocation, 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.

Returns:
set of unique of cache addresses

setCaches

public void setCaches(Set<Address> caches)
Description copied from interface: ConsistentHash
Sets the collection of cache addresses in the cluster. The implementation should store these internally and use these to locate keys.

Parameters:
caches - A set of unique caches in cluster.

setCaches

public void setCaches(Collection<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.

getHashIds

public List<Integer> getHashIds(Address a)
Description copied from interface: ConsistentHash
Returns a list of values between 0 and the hash space limit, or hash id, for a particular address. If virtual nodes are disabled, the list will only contain a single element, whereas if virtual nodes are enabled, this list's size will be the number of virtual nodes configured. If there are no hash ids for that address, it returns an empty list.

Returns:
A list of N size where N is the configured number of virtual nodes, or an empty list if there're no hash ids associated with the address.

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

-->

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