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


本文标签: 连接 服务器 破解版