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.

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

Nested Class Summary
static class AbstractWheelConsistentHash.Externalizer<T extends AbstractWheelConsistentHash>
           
 
Field Summary
protected  Set<Address> caches
           
protected  Hash hashFunction
           
protected  int numVirtualNodes
           
protected  int[] positionKeys
           
protected  Address[] positionValues
           
protected  boolean trace
           
 
Fields inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
groupManager
 
Constructor Summary
protected AbstractWheelConsistentHash()
           
 
Method Summary
 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()
           
 
Methods inherited from class org.infinispan.distribution.ch.AbstractConsistentHash
getBackupsForNode, getGrouping, getStateProvidersOnJoin, getStateProvidersOnLeave, isKeyLocalToAddress, locateAll, setGroupManager
 
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
locate
 

Field Detail

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
Constructor Detail

AbstractWheelConsistentHash

protected AbstractWheelConsistentHash()
Method Detail

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 final 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 final int getPositionIndex(int normalizedHash)

getPositionsIterator

protected final Iterator<Address> getPositionsIterator(int normalizedHash)
Creates an iterator over the positions "map" starting at the index specified by the normalizedHash.


getHashIds

public final 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 final int getNormalizedHash(Object key)

isVirtualNodesEnabled

public final boolean isVirtualNodesEnabled()

toString

public String toString()
Overrides:
toString in class AbstractConsistentHash

primaryLocation

public final Address primaryLocation(Object key)
Description copied from interface: ConsistentHash
Should be equivalent to return the first element of ConsistentHash.locate(Object, int). Useful as a performance optimization, as this is a frequently needed information.

Specified by:
primaryLocation in interface ConsistentHash
Overrides:
primaryLocation in class AbstractConsistentHash
Parameters:
key - key to locate
Returns:

getLog

protected Log getLog()

-->

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