ZkClient(节点数据监听,节点监听)

编程

笔记

/**

* 添加节点监控

*/

public void watchServer(String path) {

zc.subscribeDataChanges(ZkServerRegistry.PINGPANG_REGIST_SERVER + "/" + path, new IZkDataListener() {

@Override

public void handleDataChange(String path, Object data) throws Exception {

System.out.println("变更的节点为:" + path + ", 变更内容为:" + data);

}

@Override

public void handleDataDeleted(String path) throws Exception {

System.out.println("删除的节点为:" + path);

}

});

zc.subscribeChildChanges(ZkServerRegistry.PINGPANG_REGIST_SERVER+"/"+path, new IZkChildListener() {

@Override

public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {

System.out.println("parentPath: " + parentPath);

System.out.println("currentChilds: " + currentChilds);

}

});

}

以上是 ZkClient(节点数据监听,节点监听) 的全部内容, 来源链接: utcz.com/z/516756.html

回到顶部