org.infinispan.distribution.ch
Class AbstractWheelConsistentHash
java.lang.Object
org.infinispan.distribution.ch.AbstractConsistentHash
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.
This base class supports virtual nodes. To enable virtual nodes you must set
numVirtualNodes
to a number > 1.
Enabling virtual nodes means that a cache will appear multiple times on the hash
wheel. If an implementation doesn't want to support this, it should override
setNumVirtualNodes(Integer)
to throw an IllegalArgumentException
for values != 1.
- Since:
- 4.2
- Author:
- Mircea.Markus@jboss.com, Pete Muir, Dan Berindei
log
protected final Log log
trace
protected final boolean trace
hashFunction
protected Hash hashFunction
numVirtualNodes
protected int numVirtualNodes
caches
protected Set<Address> caches
positionKeys
protected int[] positionKeys
positionValues
protected Address[] positionValues
AbstractWheelConsistentHash
protected AbstractWheelConsistentHash()
setHashFunction
public void setHashFunction(Hash h)
setNumVirtualNodes
public void setNumVirtualNodes(Integer numVirtualNodes)
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.
- Parameters:
newCaches
- A set of unique caches in cluster.
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
getPositionIndex
protected int getPositionIndex(int normalizedHash)
getPositionsIterator
protected Iterator<Map.Entry<Integer,Address>> getPositionsIterator(int normalizedHash)
- Creates an iterator over the positions "map" starting at the index specified by the
normalizedHash
.
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.
getNormalizedHash
public int getNormalizedHash(Object key)
isVirtualNodesEnabled
protected boolean isVirtualNodesEnabled()
toString
public String toString()
- Overrides:
toString
in class AbstractConsistentHash
Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.