packagehash;importhash.Shard.Node;importjava.nio.ByteBuffer;importjava.nio.ByteOrder;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.List;importjava.util.SortedMap;importjava.util.TreeMap;
@SuppressWarnings("hiding")public class Shard { //S类封装了机器节点的信息 ,如name、password、ip、port等
static private TreeMap nodes; //虚拟节点到真实节点的映射
static private TreeMap treeKey; //key到真实节点的映射
static private List shards = new ArrayList(); //真实机器节点
private final int NODE_NUM = 100; //每个机器节点关联的虚拟节点个数
boolean flag = false;
@SuppressWarnings("static-access")public Shard(Listshards) {super();this.shards =shards;
init();
}public static voidmain(String[] args) {
Node s1= new Node("s1", "192.168.1.1");
Node s2= new Node("s2", "192.168.1.2");
Node s3= new Node("s3", "192.168.1.3");
Node s4= new Node("s4", "192.168.1.4");
shards.add(s1);
shards.add(s2);
shards.add(s3);
shards.add(s4);
Shard sh = new Shard(shards);
System.out.println("添加客户端,一开始有4个主机,分别为s1,s2,s3,s4,每个主机有100个虚拟主机:");
sh.keyToNode("101客户端");
sh.keyToNode