public class ReplicatedConsistentHash extends Object implements ConsistentHash
ConsistentHash for replicated caches.
The hash-space has several segments owned by all members and the primary ownership of each segment is evenly
spread between members.| Modifier and Type | Class and Description |
|---|---|
static class |
ReplicatedConsistentHash.Externalizer |
| Constructor and Description |
|---|
ReplicatedConsistentHash(List<Address> members,
int[] primaryOwners) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
List<Address> |
getMembers()
Should return the addresses of the nodes used to create this consistent hash.
|
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 |
isReplicated() |
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) |
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() |
ReplicatedConsistentHash |
union(ReplicatedConsistentHash ch2) |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetCapacityFactorspublic ReplicatedConsistentHash union(ReplicatedConsistentHash ch2)
public int getNumSegments()
getNumSegments in interface ConsistentHashpublic int getNumOwners()
public List<Address> getMembers()
ConsistentHashgetMembers in interface ConsistentHashpublic List<Address> locateOwnersForSegment(int segmentId)
locateOwnersForSegment in interface ConsistentHashpublic Address locatePrimaryOwnerForSegment(int segmentId)
locatePrimaryOwnerForSegment in interface ConsistentHashlocateOwnersForSegment(segmentId).get(0) but is more efficientpublic Set<Integer> getSegmentsForOwner(Address owner)
ConsistentHashgetSegmentsForOwner in interface ConsistentHashowner - the address of the memberpublic Set<Integer> getPrimarySegmentsForOwner(Address owner)
ConsistentHashgetPrimarySegmentsForOwner in interface ConsistentHashowner - the address of the memberpublic String getRoutingTableAsString()
ConsistentHashgetRoutingTableAsString in interface ConsistentHashpublic boolean isSegmentLocalToNode(Address nodeAddress, int segmentId)
ConsistentHashImplementation 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.
isSegmentLocalToNode in interface ConsistentHashpublic boolean isReplicated()
isReplicated in interface ConsistentHashtrue if every member owns every segment. This allows callers to skip computing the
segment of a key in some cases.public void toScopedState(ScopedPersistentState state)
ConsistentHashPersistentUUIDstoScopedState in interface ConsistentHashstate - the state to which this ConsistentHash will be writtenpublic ConsistentHash remapAddresses(UnaryOperator<Address> remapper)
ConsistentHashUnaryOperator.
If an address cannot me remapped (i.e. the remapper returns null) this method should return null.remapAddresses in interface ConsistentHashremapper - the remapper which given an address replaces it with another oneCopyright © 2021 JBoss by Red Hat. All rights reserved.