Class AbstractConsistentHash
- java.lang.Object
-
- org.infinispan.distribution.ch.impl.AbstractConsistentHash
-
- All Implemented Interfaces:
ConsistentHash
- Direct Known Subclasses:
DefaultConsistentHash
,ScatteredConsistentHash
public abstract class AbstractConsistentHash extends Object implements ConsistentHash
- Author:
- Radim Vansa <rvansa@redhat.com>
-
-
Field Summary
Fields Modifier and Type Field Description protected float[]
capacityFactors
protected org.infinispan.commons.hash.Hash
hashFunction
protected List<Address>
members
The membership of the cache topology that uses this CH.protected int
segmentSize
protected static String
STATE_CAPACITY_FACTOR
protected static String
STATE_CAPACITY_FACTORS
protected static String
STATE_NUM_SEGMENTS
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConsistentHash(org.infinispan.commons.hash.Hash hashFunction, int numSegments, List<Address> members, float[] capacityFactors)
protected
AbstractConsistentHash(org.infinispan.commons.hash.Hash hashFunction, int numSegments, List<Address> members, Map<Address,Float> capacityFactors)
protected
AbstractConsistentHash(ScopedPersistentState state)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkSameHashAndSegments(AbstractConsistentHash dch2)
Map<Address,Float>
getCapacityFactors()
The capacity factor of each member.org.infinispan.commons.hash.Hash
getHashFunction()
List<Address>
getMembers()
Should return the addresses of the nodes used to create this consistent hash.int
getNormalizedHash(Object key)
int
getSegment(Object key)
boolean
isKeyLocalToNode(Address nodeAddress, Object key)
Test to see whether a key is owned by a given node.protected static void
mergeLists(List<Address> dest, List<Address> src)
Adds all elements fromsrc
list that do not already exist indest
list to the latter.protected static float[]
parseCapacityFactors(ScopedPersistentState state)
protected static org.infinispan.commons.hash.Hash
parseHashFunction(ScopedPersistentState state)
protected static List<Address>
parseMembers(ScopedPersistentState state)
protected static int
parseNumSegments(ScopedPersistentState state)
protected Map<Address,Float>
remapCapacityFactors(UnaryOperator<Address> remapper)
protected List<Address>
remapMembers(UnaryOperator<Address> remapper)
void
toScopedState(ScopedPersistentState state)
Writes this ConsistentHash to the specified scoped state.protected Map<Address,Float>
unionCapacityFactors(AbstractConsistentHash ch2)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.distribution.ch.ConsistentHash
getNumOwners, getNumSegments, getPrimarySegmentsForOwner, getRoutingTableAsString, getSegmentsForOwner, isReplicated, isSegmentLocalToNode, locateAllOwners, locateOwners, locateOwnersForSegment, locatePrimaryOwner, locatePrimaryOwnerForSegment, remapAddresses
-
-
-
-
Field Detail
-
STATE_CAPACITY_FACTOR
protected static final String STATE_CAPACITY_FACTOR
- See Also:
- Constant Field Values
-
STATE_CAPACITY_FACTORS
protected static final String STATE_CAPACITY_FACTORS
- See Also:
- Constant Field Values
-
STATE_NUM_SEGMENTS
protected static final String STATE_NUM_SEGMENTS
- See Also:
- Constant Field Values
-
hashFunction
protected final org.infinispan.commons.hash.Hash hashFunction
-
members
protected final List<Address> members
The membership of the cache topology that uses this CH.
-
capacityFactors
protected final float[] capacityFactors
-
segmentSize
protected final int segmentSize
-
-
Constructor Detail
-
AbstractConsistentHash
protected AbstractConsistentHash(org.infinispan.commons.hash.Hash hashFunction, int numSegments, List<Address> members, Map<Address,Float> capacityFactors)
-
AbstractConsistentHash
protected AbstractConsistentHash(org.infinispan.commons.hash.Hash hashFunction, int numSegments, List<Address> members, float[] capacityFactors)
-
AbstractConsistentHash
protected AbstractConsistentHash(ScopedPersistentState state)
-
-
Method Detail
-
parseNumSegments
protected static int parseNumSegments(ScopedPersistentState state)
-
parseMembers
protected static List<Address> parseMembers(ScopedPersistentState state)
-
parseHashFunction
protected static org.infinispan.commons.hash.Hash parseHashFunction(ScopedPersistentState state)
-
parseCapacityFactors
protected static float[] parseCapacityFactors(ScopedPersistentState state)
-
toScopedState
public void toScopedState(ScopedPersistentState state)
Description copied from interface:ConsistentHash
Writes this ConsistentHash to the specified scoped state. Before invoking this method, the ConsistentHash addresses will have to be replaced with their correspondingPersistentUUID
s- Specified by:
toScopedState
in interfaceConsistentHash
- Parameters:
state
- the state to which this ConsistentHash will be written
-
getHashFunction
public org.infinispan.commons.hash.Hash getHashFunction()
- Specified by:
getHashFunction
in interfaceConsistentHash
-
getSegment
public int getSegment(Object key)
- Specified by:
getSegment
in interfaceConsistentHash
- Returns:
- The hash space segment that a key maps to.
-
getNormalizedHash
public int getNormalizedHash(Object key)
-
getMembers
public List<Address> getMembers()
Description copied from interface:ConsistentHash
Should return the addresses of the nodes used to create this consistent hash.- Specified by:
getMembers
in interfaceConsistentHash
- Returns:
- set of node addresses.
-
isKeyLocalToNode
public boolean isKeyLocalToNode(Address nodeAddress, Object key)
Description copied from interface:ConsistentHash
Test to see whether a key is owned by a given node.- Specified by:
isKeyLocalToNode
in interfaceConsistentHash
- Parameters:
nodeAddress
- address of the node to testkey
- key to test- Returns:
true
if the key is mapped to the address;false
otherwise
-
mergeLists
protected static void mergeLists(List<Address> dest, List<Address> src)
Adds all elements fromsrc
list that do not already exist indest
list to the latter.- Parameters:
dest
- List where elements are addedsrc
- List of elements to add - this is never modified
-
getCapacityFactors
public Map<Address,Float> getCapacityFactors()
Description copied from interface:ConsistentHash
The capacity factor of each member. Determines the relative capacity of each node compared to the others. Ifnull
, all the members are assumed to have a capacity factor of 1.- Specified by:
getCapacityFactors
in interfaceConsistentHash
-
unionCapacityFactors
protected Map<Address,Float> unionCapacityFactors(AbstractConsistentHash ch2)
-
checkSameHashAndSegments
protected void checkSameHashAndSegments(AbstractConsistentHash dch2)
-
remapCapacityFactors
protected Map<Address,Float> remapCapacityFactors(UnaryOperator<Address> remapper)
-
remapMembers
protected List<Address> remapMembers(UnaryOperator<Address> remapper)
-
-