@Immutable public class DefaultConsistentHash extends Object implements ConsistentHash
ConsistentHash
implementation. This object is immutable.Modifier and Type | Class and Description |
---|---|
static class |
DefaultConsistentHash.Externalizer |
Constructor and Description |
---|
DefaultConsistentHash(Hash hashFunction,
int numOwners,
int numSegments,
List<Address> members,
Map<Address,Float> capacityFactors,
List<Address>[] segmentOwners) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Map<Address,Float> |
getCapacityFactors() |
Hash |
getHashFunction() |
List<Address> |
getMembers()
Should return the addresses of the nodes used to create this consistent hash.
|
int |
getNormalizedHash(Object key) |
int |
getNumOwners() |
int |
getNumSegments() |
String |
getRoutingTableAsString()
Returns a string containing all the segments and their associated addresses.
|
int |
getSegment(Object key) |
List<Integer> |
getSegmentEndHashes() |
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.
|
Set<Address> |
locateAllOwners(Collection<Object> keys)
The logical equivalent of calling
ConsistentHash.locateOwners(java.lang.Object) multiple times for each key in the collection of
keys and merging the results. |
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) |
String |
toString() |
DefaultConsistentHash |
union(DefaultConsistentHash dch2)
Merges two consistent hash objects that have the same number of segments, numOwners and hash function.
|
public Hash getHashFunction()
getHashFunction
in interface ConsistentHash
public int getNumSegments()
getNumSegments
in interface ConsistentHash
public Set<Integer> getSegmentsForOwner(Address owner)
ConsistentHash
getSegmentsForOwner
in interface ConsistentHash
owner
- the address of the memberpublic int getSegment(Object key)
getSegment
in interface ConsistentHash
public int getNormalizedHash(Object key)
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 List<Address> getMembers()
ConsistentHash
getMembers
in interface ConsistentHash
public int getNumOwners()
getNumOwners
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)
ConsistentHash
ConsistentHash.locateOwners(java.lang.Object)
multiple times for each key in the collection of
keys and merging the results. Implementations may be optimised for such a bulk lookup.locateAllOwners
in interface ConsistentHash
keys
- keys to locate.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 String getRoutingTableAsString()
ConsistentHash
getRoutingTableAsString
in interface ConsistentHash
public DefaultConsistentHash union(DefaultConsistentHash dch2)
Copyright © 2014 JBoss, a division of Red Hat. All Rights Reserved.