public class GridClientConsistentHash<N> extends Object
For a good explanation of what consistent hashing is, you can refer to Tom White's Blog.
| Constructor and Description |
|---|
GridClientConsistentHash()
Constructs consistent hash using empty affinity seed and
MD5 hasher function. |
GridClientConsistentHash(Comparator<N> nodesComp,
Object affSeed)
Constructs consistent hash using given affinity seed and hasher function.
|
GridClientConsistentHash(Object affSeed)
Constructs consistent hash using given affinity seed and
MD5 hasher function. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addNode(N node,
int replicas)
Adds a node to consistent hash algorithm.
|
void |
addNodes(Collection<N> nodes,
int replicas)
Adds nodes to consistent hash algorithm (if nodes are
null or empty, then no-op). |
int |
count()
Gets number of distinct nodes, excluding replicas, in consistent hash.
|
static int |
hash(Object o)
Gets hash code for a given object.
|
boolean |
isEmpty()
Checks if consistent hash has nodes added to it.
|
N |
node(Object key)
Gets node for a key.
|
N |
node(Object key,
Collection<N> inc)
Gets node for a given key.
|
N |
node(Object key,
Collection<N> inc,
Collection<N> exc)
Gets node for a given key.
|
N |
node(Object key,
GridClientPredicate<N>... p)
Gets node for a given key.
|
Set<N> |
nodes()
Gets set of all distinct nodes in the consistent hash (in no particular order).
|
N |
random()
Picks a random node from consistent hash.
|
boolean |
removeNode(N node)
Removes a node and all of its replicas.
|
int |
size()
Gets size of all nodes (including replicas) in consistent hash.
|
String |
toString() |
public GridClientConsistentHash()
MD5 hasher function.public GridClientConsistentHash(Object affSeed)
MD5 hasher function.affSeed - Affinity seed (will be used as key prefix for hashing).public GridClientConsistentHash(Comparator<N> nodesComp, Object affSeed)
nodesComp - Nodes comparator to resolve hash codes collisions.
If null natural order will be used.affSeed - Affinity seed (will be used as key prefix for hashing).public void addNodes(Collection<N> nodes, int replicas)
null or empty, then no-op).nodes - Nodes to add.replicas - Number of replicas for every node.public boolean addNode(N node, int replicas)
node - New node (if null then no-op).replicas - Number of replicas for the node.True if node was added, false if it is null or
is already contained in the hash.public boolean removeNode(N node)
node - Node to remove (if null, then no-op).True if node was removed, false if node is null or
not present in hash.public int count()
public int size()
public boolean isEmpty()
True if consistent hash is empty, false otherwise.public Set<N> nodes()
public N random()
null if there are no nodes.public N node(Object key, Collection<N> inc)
key - Key to get node for.inc - Optional inclusion set. Only nodes contained in this set may be returned.
If null, then all nodes may be included.null if node was not found.public N node(Object key, @Nullable Collection<N> inc, @Nullable Collection<N> exc)
key - Key to get node for.inc - Optional inclusion set. Only nodes contained in this set may be returned.
If null, then all nodes may be included.exc - Optional exclusion set. Only nodes not contained in this set may be returned.
If null, then all nodes may be returned.null if node was not found.public N node(Object key, GridClientPredicate<N>... p)
key - Key to get node for.p - Optional predicate for node filtering.null if node was not found.public static int hash(Object o)
o - Object to get hash code for.
Follow @ApacheIgnite
Ignite Fabric : ver. 2.2.0 Release Date : September 15 2017