public class ConsistentHash extends Object implements Externalizable
Modifier and Type | Class and Description |
---|---|
static class |
ConsistentHash.Member
Represents a member in a consistently hashed cluster.
|
Constructor and Description |
---|
ConsistentHash()
Initializes an empty hash.
|
Modifier and Type | Method and Description |
---|---|
static ConsistentHash |
emptyRing()
Returns an instance of an empty Ring, which can be used to add members.
|
boolean |
equals(Object o) |
String |
getMember(String item,
String commandType)
Returns the member for the given
item , that supports given commandType . |
Set<ConsistentHash.Member> |
getMembers()
Returns the set of members part of this hash ring.
|
int |
hashCode() |
void |
readExternal(ObjectInput in) |
String |
toString() |
ConsistentHash |
withAdditionalNode(String nodeName,
int segmentCount,
Set<String> supportedCommandTypes)
Returns a ConsistentHash with the given additional
nodeName , which is given
segmentCount segments on the ring. |
ConsistentHash |
withExclusively(Collection<String> nodes)
Returns a ConsistentHash instance where only segments leading to the given
nodes are available. |
void |
writeExternal(ObjectOutput out) |
public ConsistentHash()
emptyRing()
to
obtain an instance.public static ConsistentHash emptyRing()
public ConsistentHash withAdditionalNode(String nodeName, int segmentCount, Set<String> supportedCommandTypes)
nodeName
, which is given
segmentCount
segments on the ring. A registration of a node will completely override any previous
registration known for that node.nodeName
- The name of the node to add. This will be used to compute the segmentssegmentCount
- The number of segments to add the given nodesupportedCommandTypes
- The fully qualified names of command (payload) types this node supportspublic ConsistentHash withExclusively(Collection<String> nodes)
nodes
are available.
Each
lookup will always result in one of the given nodes
.nodes
- The nodes to keep in the consistent hashnodes
are availablepublic String getMember(String item, String commandType)
item
, that supports given commandType
. If no such
member is available, this method returns null
.item
- The item to find a node name forcommandType
- The type of command the member must supportitem
, or null
if not foundpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public Set<ConsistentHash.Member> getMembers()
Copyright © 2010-2014. All Rights Reserved.