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.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractWheelConsistentHash.Externalizer<T extends AbstractWheelConsistentHash> |
Modifier and Type | Field and Description |
---|---|
protected Set<Address> |
caches |
protected Hash |
hashFunction |
protected int |
numVirtualNodes |
protected int[] |
positionKeys |
protected Address[] |
positionValues |
protected boolean |
trace |
groupManager
Modifier | Constructor and Description |
---|---|
protected |
AbstractWheelConsistentHash() |
Modifier and Type | Method and Description |
---|---|
Set<Address> |
getCaches()
Should return a collection of cache addresses in the cluster.
|
List<Integer> |
getHashIds(Address a)
Returns a list of values between 0 and the hash space limit, or hash id,
for a particular address.
|
protected Log |
getLog() |
int |
getNormalizedHash(Object key) |
protected int |
getPositionIndex(int normalizedHash) |
protected Iterator<Address> |
getPositionsIterator(int normalizedHash)
Creates an iterator over the positions "map" starting at the index specified by the
normalizedHash . |
boolean |
isVirtualNodesEnabled() |
Address |
primaryLocation(Object key)
Should be equivalent to return the first element of
ConsistentHash.locate(Object, int) . |
void |
setCaches(Set<Address> newCaches)
Sets the collection of cache addresses in the cluster.
|
void |
setHashFunction(Hash h) |
void |
setNumVirtualNodes(Integer numVirtualNodes) |
String |
toString() |
getBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, isKeyLocalToAddress, locateAll, setGroupManager
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
locate
protected final boolean trace
protected Hash hashFunction
protected int numVirtualNodes
protected int[] positionKeys
protected Address[] positionValues
public void setHashFunction(Hash h)
public void setNumVirtualNodes(Integer numVirtualNodes)
public void setCaches(Set<Address> newCaches)
ConsistentHash
newCaches
- A set of unique caches in cluster.public final Set<Address> getCaches()
ConsistentHash
protected final int getPositionIndex(int normalizedHash)
protected final Iterator<Address> getPositionsIterator(int normalizedHash)
normalizedHash
.public final List<Integer> getHashIds(Address a)
ConsistentHash
public final int getNormalizedHash(Object key)
public final boolean isVirtualNodesEnabled()
public String toString()
toString
in class AbstractConsistentHash
public final Address primaryLocation(Object key)
ConsistentHash
ConsistentHash.locate(Object, int)
.
Useful as a performance optimization, as this is a frequently needed information.primaryLocation
in interface ConsistentHash
primaryLocation
in class AbstractConsistentHash
key
- key to locateprotected Log getLog()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.