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

Field Summary
protected  ArrayList<Address> addresses
           
protected  Map<Address,Integer> addressToHashIds
           
protected  SortedMap<Integer,Address> positions
           
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
caches, topologyInfo
 
Constructor Summary
AbstractWheelConsistentHash()
           
 
Method Summary
 List<Address> getBackupsForNode(Address node, int replCount)
          Returns the nodes that backup data for the supplied node including the node itself.
 List<Address> getCaches()
          Should return a collection of cache addresses in the cluster.
 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.
protected  int getNormalizedHash(Object key)
           
 void setCaches(List<Address> caches)
          Sets the collection of cache addresses in the cluster.
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getTopologyInfo, 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

addresses

protected ArrayList<Address> addresses

positions

protected SortedMap<Integer,Address> positions

addressToHashIds

protected Map<Address,Integer> addressToHashIds
Constructor Detail

AbstractWheelConsistentHash

public AbstractWheelConsistentHash()
Method Detail

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.

Specified by:
setCaches in interface ConsistentHash
Overrides:
setCaches in class AbstractConsistentHash
Parameters:
caches - 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.


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

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

protected int getNormalizedHash(Object key)

toString

public String toString()
Overrides:
toString in class AbstractConsistentHash

Google Analytics

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