org.infinispan.distribution.ch
Class AbstractWheelConsistentHash

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

public abstract class AbstractWheelConsistentHash
extends AbstractConsistentHash

Abstract class for the wheel-based CH implementations.

Since:
4.2
Author:
Mircea.Markus@jboss.com

Nested Class Summary
protected static class AbstractWheelConsistentHash.Externalizer
           
 
Field Summary
protected  Map<Address,Integer> addressToHashIds
           
protected  Hash hashFunction
           
protected  Log log
           
protected  SortedMap<Integer,Address> positions
           
protected  boolean trace
           
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
caches
 
Constructor Summary
protected AbstractWheelConsistentHash()
           
 
Method Summary
 List<Address> getBackupsForNode(Address node, int replCount)
          Returns the nodes that backup data for the supplied node including the node itself.
 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.
 int getNormalizedHash(Object key)
           
 void setCaches(Set<Address> newCaches)
          Sets the collection of cache addresses in the cluster.
 void setHashFunction(Hash h)
           
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getCaches, isKeyLocalToAddress, locateAll, setTopologyInfo
 
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
getStateProvidersOnJoin, getStateProvidersOnLeave, locate
 

Field Detail

log

protected final Log log

trace

protected final boolean trace

positions

protected SortedMap<Integer,Address> positions

addressToHashIds

protected Map<Address,Integer> addressToHashIds

hashFunction

protected Hash hashFunction
Constructor Detail

AbstractWheelConsistentHash

protected AbstractWheelConsistentHash()
Method Detail

setHashFunction

public void setHashFunction(Hash h)

setCaches

public void setCaches(Set<Address> newCaches)
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.

Specified by:
setCaches in interface ConsistentHash
Overrides:
setCaches in class AbstractConsistentHash
Parameters:
newCaches - A set of unique caches in cluster.

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.


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.

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.

getNormalizedHash

public int getNormalizedHash(Object key)

toString

public String toString()
Overrides:
toString in class AbstractConsistentHash


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