admin 管理员组文章数量: 1086019
2024年4月30日发(作者:mydockfinder破解版)
1 Create a Demo Class and run
import ption;
import Exception;
import dEvent;
import r;
import ype;
import per;
public class ZoomkeepTest2 {
// 创建一个与服务器的连接
ZooKeeper zk = null;
public ZoomkeepTest2() {
try {
zk = new ZooKeeper("127.0.0.1:2181", 500000, new WatcherImpl());
// a("/zk-demo/watch-this", true, null);
while (true) {
}
} catch (IOException e) {
tackTrace();
} finally {
// 关闭连接
if (null != zk) {
try {
();
} catch (InterruptedException e) {
tackTrace();
}
}
}
}
public class WatcherImpl implements Watcher {
public void process(WatchedEvent event) {
System.
out
.println("已经触发了" + e() + "事件!");
if (e().equals(EventType.
NodeDataChanged
)) {
try {
System.
out
.println(new
String(a("/zk-demo/watch-this", false, null)));
} catch (KeeperException e) {
tackTrace();
} catch (InterruptedException e) {
tackTrace();
}
}
er(new WatcherImpl());
try {
a("/zk-demo/watch-this", true, null);
} catch (KeeperException e) {
tackTrace();
} catch (InterruptedException e) {
tackTrace();
}
}
}
public static void main(String[] args) throws IOException, KeeperException,
InterruptedException {
ZoomkeepTest2 zt = new ZoomkeepTest2();
}
}
2 Run “” and set node date:
set /zk-demo/watch-this data3333dsafsa
set /zk-demo/watch-this data3333dsafsa12
3 The Console will output:
已经触发了NodeDataChanged事件!
data3333dsafsa
已经触发了NodeDataChanged事件!
data3333dsafsa12
版权声明:本文标题:zookeeper 实现 配置管理(Configuration Management) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1714438601a680168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论