public class DefaultConsistentHashFactory extends Object implements ConsistentHashFactory<DefaultConsistentHash>
ConsistentHashFactory.
All methods except union(DefaultConsistentHash, DefaultConsistentHash) return a consistent hash
with floor(numOwners*numSegments/numNodes) <= segments per owner <= ceil(numOwners*numSegments/numNodes).| Modifier and Type | Class and Description |
|---|---|
protected static class |
DefaultConsistentHashFactory.Builder |
static class |
DefaultConsistentHashFactory.Externalizer |
| Constructor and Description |
|---|
DefaultConsistentHashFactory() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addBackupOwners(DefaultConsistentHashFactory.Builder builder) |
protected void |
addPrimaryOwners(DefaultConsistentHashFactory.Builder builder) |
DefaultConsistentHash |
create(Hash hashFunction,
int numOwners,
int numSegments,
List<Address> members,
Map<Address,Float> capacityFactors)
Create a new consistent hash instance.
|
protected void |
doAddBackupOwners(DefaultConsistentHashFactory.Builder builder) |
protected Address |
findNewBackupOwner(DefaultConsistentHashFactory.Builder builder,
Collection<Address> excludes,
Address owner) |
protected Address |
findNewPrimaryOwner(DefaultConsistentHashFactory.Builder builder,
Collection<Address> candidates,
Address primaryOwner) |
DefaultConsistentHash |
rebalance(DefaultConsistentHash baseCH)
Create a new consistent hash instance, based on an existing instance, but "balanced" according to
the implementation's rules.
|
protected void |
rebalanceBuilder(DefaultConsistentHashFactory.Builder builder) |
protected void |
removeExtraBackupOwners(DefaultConsistentHashFactory.Builder builder) |
protected void |
replaceBackupOwners(DefaultConsistentHashFactory.Builder builder) |
protected void |
replacePrimaryOwners(DefaultConsistentHashFactory.Builder builder,
int maxOwners) |
protected void |
swapPrimaryOwnersWithBackups(DefaultConsistentHashFactory.Builder builder) |
DefaultConsistentHash |
union(DefaultConsistentHash dch1,
DefaultConsistentHash dch2)
Merges two consistent hash objects that have the same number of segments, numOwners and hash function.
|
DefaultConsistentHash |
updateMembers(DefaultConsistentHash baseCH,
List<Address> actualMembers,
Map<Address,Float> actualCapacityFactors)
Leavers are removed and segments without owners are assigned new owners.
|
public DefaultConsistentHash create(Hash hashFunction, int numOwners, int numSegments, List<Address> members, Map<Address,Float> capacityFactors)
ConsistentHashFactorycreate in interface ConsistentHashFactory<DefaultConsistentHash>hashFunction - The hash function to use on top of the keys' own hashCode() implementation.numOwners - The ideal number of owners for each key. The created consistent hash
can have more or less owners, but each key will have at least one owner.numSegments - Number of hash-space segments. The implementation may round up the number
of segments for performance, or may ignore the parameter altogether.members - A list of addresses representing the new cache members.capacityFactors - The capacity factor of each member. Determines the relative capacity of each node compared
to the others. The implementation may ignore this parameter.
If null, all the members are assumed to have a capacity factor of 1.public DefaultConsistentHash updateMembers(DefaultConsistentHash baseCH, List<Address> actualMembers, Map<Address,Float> actualCapacityFactors)
updateMembers in interface ConsistentHashFactory<DefaultConsistentHash>baseCH - An existing consistent hash instance, should not be nullactualMembers - A list of addresses representing the new cache members.actualCapacityFactors - The capacity factor of each member. Determines the relative capacity of each node compared
to the others. The implementation may ignore this parameter.
If null, all the members are assumed to have a capacity factor of 1.public DefaultConsistentHash rebalance(DefaultConsistentHash baseCH)
ConsistentHashFactoryrebalance(rebalance(ch)) must be equivalent to rebalance(ch).rebalance in interface ConsistentHashFactory<DefaultConsistentHash>baseCH - An existing consistent hash instance, should not be nullConsistentHash instance, or baseCH if the existing instance
does not need any changes.public DefaultConsistentHash union(DefaultConsistentHash dch1, DefaultConsistentHash dch2)
union in interface ConsistentHashFactory<DefaultConsistentHash>protected void rebalanceBuilder(DefaultConsistentHashFactory.Builder builder)
protected void addPrimaryOwners(DefaultConsistentHashFactory.Builder builder)
protected void replacePrimaryOwners(DefaultConsistentHashFactory.Builder builder, int maxOwners)
protected void swapPrimaryOwnersWithBackups(DefaultConsistentHashFactory.Builder builder)
protected void addBackupOwners(DefaultConsistentHashFactory.Builder builder)
protected void removeExtraBackupOwners(DefaultConsistentHashFactory.Builder builder)
protected void doAddBackupOwners(DefaultConsistentHashFactory.Builder builder)
protected void replaceBackupOwners(DefaultConsistentHashFactory.Builder builder)
protected Address findNewBackupOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> excludes, Address owner)
protected Address findNewPrimaryOwner(DefaultConsistentHashFactory.Builder builder, Collection<Address> candidates, Address primaryOwner)
Copyright © 2013 JBoss, a division of Red Hat. All rights reserved.