zookeeper通知watcher
来源:互联网 发布:php钩子是什么意思 编辑:程序博客网 时间:2024/06/08 14:31
import org.apache.zookeeper.*;import java.io.IOException;/** * Created with IntelliJ IDEA. * User: Administrator * Date: 17-7-12 * Time: 下午3:03 * To change this template use File | Settings | File Templates. */public class ZkWatchTest { // 创建一个与服务器的连接 public static void main(String args[]) throws IOException, InterruptedException, KeeperException { int sessionTime = 2000; ZooKeeper zk = new ZooKeeper("10.2.4.12:2181,10.2.4.13:2181,10.2.4.14:2181", 3000, new Watcher() { @Override public void process(WatchedEvent watchedEvent) { System.out.println("已经触发了" + watchedEvent.getType() + "事件!"); } }); // 创建一个目录节点 zk.create("/testRootPath", "testRootData".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT);// 创建一个子目录节点 zk.create("/testRootPath/testChildPathOne", "testChildDataOne".getBytes(),ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT); System.out.println(new String(zk.getData("/testRootPath",false,null)));// 取出子目录节点列表 System.out.println(zk.getChildren("/testRootPath",true));// 修改子目录节点数据 zk.setData("/testRootPath/testChildPathOne","modifyChildDataOne".getBytes(),-1); System.out.println("目录节点状态:["+zk.exists("/testRootPath",true)+"]");// 创建另外一个子目录节点 zk.create("/testRootPath/testChildPathTwo", "testChildDataTwo".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT); System.out.println(new String(zk.getData("/testRootPath/testChildPathTwo",true,null)));// 删除子目录节点 zk.delete("/testRootPath/testChildPathTwo",-1); zk.delete("/testRootPath/testChildPathOne",-1);// 删除父目录节点 zk.delete("/testRootPath",-1);// 关闭连接 zk.close(); }}
阅读全文
0 0
- zookeeper通知watcher
- Zookeeper异步通知模式--watcher
- zookeeper系列之异步通知模式-Watcher
- zookeeper系列之异步通知模式-Watcher
- zookeeper系列之异步通知模式-Watcher
- Zookeeper的watcher数据变更通知机制
- zookeeper系列之异步通知模式-Watcher
- 【ZooKeeper Notes 13】ZooKeeper Watcher的事件通知类型
- Zookeeper--Watcher
- Zookeeper(十)Watcher——数据变更的通知
- zookeeper 中 Watcher 通知机制的一点理解
- ZooKeeper Watcher执行顺序
- zookeeper watcher功能分析
- zookeeper watcher功能分析
- zookeeper watcher功能分析
- ZooKeeper Watcher执行顺序 ********************
- ZooKeeper watcher和version
- zookeeper Watcher API 说明
- 微信小程序 Picker
- Cannot create a session after the response has been committed
- jdbc--数据库操作
- 各地图API坐标系统比较与转换
- iptables的基本语法格式
- zookeeper通知watcher
- MyEclipse将普通项目转换成maven
- 最新Java面试题(附答案)
- 图片压缩之-JPEGCodec失效替换方案
- 快速排序,希尔排序以及KMP字符查找算法
- 黑客学习顺序书单
- while(scanf(“%d%d”,&a,&b)!=EOF)循环无法退出问题
- 三天入门Python---基本语法(第一天)
- 多分辨率适配常用目录