public class HashRing<Node,Resource> extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_WEIGHT |
static Hasher |
TO_STRING_HASHER
The Hasher.ToStringHasher implemenation is as the hasher when none is specifed in the constructor.
|
| Constructor and Description |
|---|
HashRing()
Constructs a HashRing which uses the OBJECT_HASHER to hash the nodes and values.
|
HashRing(Hasher hasher)
Constructs a HashRing with the specified
hasher.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Node... nodes)
Adds all the specified nodes to the HashRing using the default
weight of 200 for each node.
|
ArrayList<Iterator<Node>> |
add(Node node)
Adds a node to the HashRing using the default
weight of 200 for the node.
|
ArrayList<Iterator<Node>> |
add(Node node,
int weight)
Adds a node to the HashRing using the specified weight.
|
void |
addAll(Iterable<Node> nodes)
Adds all the specified nodes to the HashRing using the default
weight of 200 for each node.
|
void |
clear()
Removes all previously added nodes.
|
Node |
get(Resource resource)
Maps a resource value to a node.
|
List<Node> |
getNodes() |
Iterator<Node> |
iterator(Resource resource)
Maps a resource value to an interator to the nodes in the HashRing
starting at the Node which resource maps to.
|
boolean |
remove(Node node)
Removes a previously added node from the HashRing
|
public static int DEFAULT_WEIGHT
public static Hasher TO_STRING_HASHER
public HashRing()
public HashRing(Hasher hasher)
hasher - public void addAll(Iterable<Node> nodes)
nodes - the nodes to addpublic void add(Node... nodes)
nodes - the nodes to addpublic ArrayList<Iterator<Node>> add(Node node)
node - the node to addpublic ArrayList<Iterator<Node>> add(Node node, int weight)
node - the node to addweight - the number of hash replicas to create the node in the HashRingIllegalArgumentException - if the weight is less than 1public boolean remove(Node node)
node - the node to removepublic void clear()
public Node get(Resource resource)
resource - the resource to mapCopyright © 2005–2015 The Apache Software Foundation. All rights reserved.