zookpeer安装说明:http://www.cnblogs.com/gpcuster/archive/2010/01/15/1648547.html
疑惑解答:http://www.cnblogs.com/gpcuster/archive/2010/12/29/1921213.html
其中简述了zookpeer是如何管理服务的,并通知客户端的事件方法,进行服务器参数的重新分配。
感觉不错的博客:
http://blog.sina.com.cn/s/blog_56dee71a0100wcvu.html
http://www.cnblogs.com/ggjucheng/p/3370359.html
APACHE官网对java 操作zookpeer给出的例子
http://zookeeper.apache.org/doc/trunk/javaExample.html
ZOOKEEPER在客户端究竟做了什么事情
<span style="font-family:Comic Sans MS;">System.out.println("Starting ZK:");
zk = new ZooKeeper(address, 3000, this);
System.out.println("Finished starting ZK: " + zk);</span>
完成客户段的初始化之后,就可以对ZooKeeper进行相应的操作了:
<span style="font-family:Comic Sans MS;">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");
}
}</span>
虽然上面的代码看起来简单明了,但是ZooKeeper的客户端在后台默默做了许多事情:
1 与ZooKeeper服务端进行通信,包括:连接,发送消息,接受消息。
2 发送心跳信息,保持与ZooKeeper服务端的有效连接与Session的有效性。
3 错误处理,如果客户端当前连接的ZooKeeper服务端失效,自动切换到另一台有效的ZooKeeper服务端。
4 管理Watcher,处理异常调用和Watcher。