Package org.forgerock.opendj.ldap
Class ConsistentHashMap<P>
- java.lang.Object
-
- org.forgerock.opendj.ldap.ConsistentHashMap<P>
-
- Type Parameters:
P
- The type of partition object.
public final class ConsistentHashMap<P> extends Object
An implementation of "consistent hashing" supporting per-partition weighting. This implementation is thread safe and allows partitions to be added and removed during use.This implementation maps partitions to one or more points on a circle ranging from
Integer.MIN_VALUE
toInteger.MAX_VALUE
. The number of points per partition is dictated by the partition's weight. A partition with a weight which is higher than another partition will receive a proportionally higher load.
-
-
Constructor Summary
Constructors Constructor Description ConsistentHashMap()
Creates a new consistent hash map which will hash keys using MD5.ConsistentHashMap(Function<Object,Integer,NeverThrowsException> hashFunction)
Creates a new consistent hash map which will hash keys using the provided hash function.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ConsistentHashMap<T>
newMurmur3ConsistentHashMap()
Creates a new consistent hash map which will hash keys using Murmur3.ConsistentHashMap<P>
put(String partitionId, P partition)
Puts a partition into this consistent hash map using the default weight which is sufficiently high to ensure a reasonably uniform distribution among all partitions having the same weight.ConsistentHashMap<P>
put(String partitionId, P partition, int weight)
Puts a partition into this consistent hash map using the specified weight.ConsistentHashMap<P>
putAll(Map<String,P> map)
Copies all the partitions from the specifiedmap
to this consistent hash map..ConsistentHashMap<P>
remove(String partitionId)
Removes the partition that was previously added using the provided partition ID.String
toString()
-
-
-
Constructor Detail
-
ConsistentHashMap
public ConsistentHashMap()
Creates a new consistent hash map which will hash keys using MD5.This constructor is kept for compatibility purpose and should not be used in new code. For new code, prefer
newMurmur3ConsistentHashMap()
.- See Also:
newMurmur3ConsistentHashMap()
-
ConsistentHashMap
public ConsistentHashMap(Function<Object,Integer,NeverThrowsException> hashFunction)
Creates a new consistent hash map which will hash keys using the provided hash function.This constructor is kept for compatibility purpose and should not be used in new code. For new code, prefer
newMurmur3ConsistentHashMap()
.- Parameters:
hashFunction
- The function which should be used for hashing keys.- See Also:
newMurmur3ConsistentHashMap()
-
-
Method Detail
-
newMurmur3ConsistentHashMap
public static <T> ConsistentHashMap<T> newMurmur3ConsistentHashMap()
Creates a new consistent hash map which will hash keys using Murmur3.- Type Parameters:
T
- The type of partition object.- Returns:
- A new consistent hash map which will hash keys using Murmur3.
-
put
public ConsistentHashMap<P> put(String partitionId, P partition)
Puts a partition into this consistent hash map using the default weight which is sufficiently high to ensure a reasonably uniform distribution among all partitions having the same weight.- Parameters:
partitionId
- The partition ID.partition
- The partition.- Returns:
- This consistent hash map.
-
put
public ConsistentHashMap<P> put(String partitionId, P partition, int weight)
Puts a partition into this consistent hash map using the specified weight. If all partitions have the same weight then they will each receive a similar amount of load. A partition having a weight which is twice that of another will receive twice the load. Weight values should generally be great than 200 in order to minimize the risk of unexpected imbalances due to the way in which logical partitions are mapped to real partitions.- Parameters:
partitionId
- The partition ID.partition
- The partition.weight
- The partition's weight, which should typically be over 200 and never negative.- Returns:
- This consistent hash map.
-
putAll
public ConsistentHashMap<P> putAll(Map<String,P> map)
Copies all the partitions from the specifiedmap
to this consistent hash map..- Parameters:
map
- The map containing the partitions to add.- Returns:
- This consistent hash map.
-
remove
public ConsistentHashMap<P> remove(String partitionId)
Removes the partition that was previously added using the provided partition ID.- Parameters:
partitionId
- The partition ID.- Returns:
- This consistent hash map.
-
-