@Immutable public class DefaultConsistentHash extends AbstractConsistentHash
ConsistentHash
implementation. This object is immutable.
Every segment must have a primary owner.Modifier and Type | Class and Description |
---|---|
static class |
DefaultConsistentHash.Externalizer |
capacityFactors, members, STATE_CAPACITY_FACTOR, STATE_CAPACITY_FACTORS, STATE_NUM_SEGMENTS
Constructor and Description |
---|
DefaultConsistentHash(int numOwners,
int numSegments,
List<Address> members,
Map<Address,Float> capacityFactors,
List<Address>[] segmentOwners) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
int |
getNumOwners() |
int |
getNumSegments() |
Set<Integer> |
getPrimarySegmentsForOwner(Address owner)
Returns the segments that this cache member is the primary owner for.
|
String |
getRoutingTableAsString()
Returns a string containing all the segments and their associated addresses.
|
Set<Integer> |
getSegmentsForOwner(Address owner)
Returns the segments owned by a cache member.
|
int |
hashCode() |
boolean |
isSegmentLocalToNode(Address nodeAddress,
int segmentId)
Check if a segment is local to a given member.
|
List<Address> |
locateOwnersForSegment(int segmentId) |
Address |
locatePrimaryOwnerForSegment(int segmentId) |
String |
prettyPrintOwnership() |
ConsistentHash |
remapAddresses(UnaryOperator<Address> remapper)
Returns a new ConsistentHash with the addresses remapped according to the provided
UnaryOperator . |
void |
toScopedState(ScopedPersistentState state)
Writes this ConsistentHash to the specified scoped state.
|
String |
toString() |
DefaultConsistentHash |
union(DefaultConsistentHash dch2)
Merges two consistent hash objects that have the same number of segments, numOwners and hash function.
|
checkSameHashAndSegments, getCapacityFactors, getMembers, mergeLists, parseCapacityFactors, parseHashFunction, parseMembers, parseNumSegments, remapCapacityFactors, remapMembers, unionCapacityFactors
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isReplicated
public int getNumSegments()
public Set<Integer> getSegmentsForOwner(Address owner)
ConsistentHash
owner
- the address of the memberpublic Set<Integer> getPrimarySegmentsForOwner(Address owner)
ConsistentHash
owner
- the address of the memberpublic List<Address> locateOwnersForSegment(int segmentId)
public Address locatePrimaryOwnerForSegment(int segmentId)
locateOwnersForSegment(segmentId).get(0)
but is more efficientpublic int getNumOwners()
public boolean isSegmentLocalToNode(Address nodeAddress, int segmentId)
ConsistentHash
Implementation note: normally key-based method are implemented based on segment-based methods. Here, however, we need a default implementation for the segment-based method for backwards-compatibility reasons.
public String getRoutingTableAsString()
ConsistentHash
public DefaultConsistentHash union(DefaultConsistentHash dch2)
public String prettyPrintOwnership()
public void toScopedState(ScopedPersistentState state)
ConsistentHash
PersistentUUID
stoScopedState
in interface ConsistentHash
toScopedState
in class AbstractConsistentHash
state
- the state to which this ConsistentHash will be writtenpublic ConsistentHash remapAddresses(UnaryOperator<Address> remapper)
ConsistentHash
UnaryOperator
.
If an address cannot me remapped (i.e. the remapper returns null) this method should return null.remapper
- the remapper which given an address replaces it with another oneCopyright © 2021 JBoss by Red Hat. All rights reserved.