zookpeer安装说明:http://www.cnblogs.com/gpcuster/archive/2010/01/15/1648547.html
疑惑解答:http://www.cnblogs.com/gpcuster/archive/2010/12/29/1921213.html
其中简述了zookpeer是如何管理服务的,并通知客户端的事件方法,进行服务器参数的重新分配。
System.out.println("Starting ZK:"); zk = new ZooKeeper(address, 3000, this); System.out.println("Finished starting ZK: " + zk);
if (zk != null) { try { Stat s = zk.exists(root, false); if (s == null) { zk.create(root, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (KeeperException e) { System.out .println("Keeper exception when instantiating queue: " + e.toString()); } catch (InterruptedException e) { System.out.println("Interrupted exception"); } }
虽然上面的代码看起来简单明了,但是ZooKeeper的客户端在后台默默做了许多事情:
1 与ZooKeeper服务端进行通信,包括:连接,发送消息,接受消息。
2 发送心跳信息,保持与ZooKeeper服务端的有效连接与Session的有效性。
3 错误处理,如果客户端当前连接的ZooKeeper服务端失效,自动切换到另一台有效的ZooKeeper服务端。
4 管理Watcher,处理异常调用和Watcher。
zookpeer--zookpper学习与使用,布布扣,bubuko.com
原文:http://blog.csdn.net/gaopeng0071/article/details/20043149