org.infinispan.distribution
Class ExperimentalDefaultConsistentHash

java.lang.Object
  extended by org.infinispan.distribution.AbstractConsistentHash
      extended by org.infinispan.distribution.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
           
 
Constructor Summary
ExperimentalDefaultConsistentHash()
           
 
Method Summary
 boolean equals(Object other)
           
 List<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 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)
          Sets the collection of cache addresses in the cluster.
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.AbstractConsistentHash
isKeyLocalToAddress, locateAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExperimentalDefaultConsistentHash

public ExperimentalDefaultConsistentHash()
Method Detail

getCaches

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

Returns:
collection of cache addresses

setCaches

public void setCaches(List<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 - caches in cluster.

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.List). Should never be null, and should contain replCount elements or the max number of caches available, whichever is smaller.

toString

public String toString()
Overrides:
toString in class Object
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

Google Analytics

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