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 |
static class |
ReplicatedConsistentHash.RangeSet |
Constructor and Description |
---|
ReplicatedConsistentHash(Hash hashFunction,
List<Address> members,
int[] primaryOwners) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Hash |
getHashFunction() |
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.
|
int |
getSegment(Object key) |
Set<Integer> |
getSegmentsForOwner(Address owner)
Returns the segments owned by a cache member.
|
int |
hashCode() |
boolean |
isKeyLocalToNode(Address nodeAddress,
Object key)
Test to see whether a key is owned by a given node.
|
boolean |
isReplicated() |
boolean |
isSegmentLocalToNode(Address nodeAddress,
int segmentId)
Check if a segment is local to a given member.
|
Set<Address> |
locateAllOwners(Collection<Object> keys) |
List<Address> |
locateOwners(Object key)
Finds all the owners of a key.
|
List<Address> |
locateOwnersForSegment(int segmentId) |
Address |
locatePrimaryOwner(Object key)
Should be equivalent to return the first element of
ConsistentHash.locateOwners(java.lang.Object) . |
Address |
locatePrimaryOwnerForSegment(int segmentId) |
void |
toScopedState(ScopedPersistentState state)
Writes this ConsistentHash to the specified scoped state.
|
String |
toString() |
ReplicatedConsistentHash |
union(ReplicatedConsistentHash ch2) |
public ReplicatedConsistentHash union(ReplicatedConsistentHash ch2)
public int getNumSegments()
getNumSegments
in interface ConsistentHash
public int getNumOwners()
getNumOwners
in interface ConsistentHash
public List<Address> getMembers()
ConsistentHash
getMembers
in interface ConsistentHash
public Hash getHashFunction()
getHashFunction
in interface ConsistentHash
public int getSegment(Object key)
getSegment
in interface ConsistentHash
public List<Address> locateOwnersForSegment(int segmentId)
locateOwnersForSegment
in interface ConsistentHash
public Address locatePrimaryOwnerForSegment(int segmentId)
locatePrimaryOwnerForSegment
in interface ConsistentHash
locateOwnersForSegment(segmentId).get(0)
but is more efficientpublic Set<Integer> getSegmentsForOwner(Address owner)
ConsistentHash
getSegmentsForOwner
in interface ConsistentHash
owner
- the address of the memberpublic Set<Integer> getPrimarySegmentsForOwner(Address owner)
ConsistentHash
getPrimarySegmentsForOwner
in interface ConsistentHash
owner
- the address of the memberpublic String getRoutingTableAsString()
ConsistentHash
getRoutingTableAsString
in interface ConsistentHash
public Address locatePrimaryOwner(Object key)
ConsistentHash
ConsistentHash.locateOwners(java.lang.Object)
.
Useful as a performance optimization, as this is a frequently needed information.locatePrimaryOwner
in interface ConsistentHash
key
- key to locatepublic List<Address> locateOwners(Object key)
ConsistentHash
locateOwners
in interface ConsistentHash
key
- key to locatenull
, and it will always have at least 1 element.public Set<Address> locateAllOwners(Collection<Object> keys)
locateAllOwners
in interface ConsistentHash
public boolean isKeyLocalToNode(Address nodeAddress, Object key)
ConsistentHash
isKeyLocalToNode
in interface ConsistentHash
nodeAddress
- address of the node to testkey
- key to testtrue
if the key is mapped to the address; false
otherwisepublic 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.
isSegmentLocalToNode
in interface ConsistentHash
public boolean isReplicated()
isReplicated
in interface ConsistentHash
true
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)
ConsistentHash
toScopedState
in interface ConsistentHash
state
- the state to which this ConsistentHash will be writtenCopyright © 2020 JBoss, a division of Red Hat. All rights reserved.