zoukankan      html  css  js  c++  java
  • ZooKeeper 主要的操作演示样品

     // 创建一个与server的连接
     ZooKeeper zk = new ZooKeeper("localhost:" + CLIENT_PORT, 
            ClientBase.CONNECTION_TIMEOUT, new Watcher() { 
                // 监控全部被触发的事件
                public void process(WatchedEvent event) { 
                    System.out.println("已经触发了" + event.getType() + "事件!"); 
                } 
            }); 
     // 创建一个文件夹节点
     zk.create("/testRootPath", "testRootData".getBytes(), Ids.OPEN_ACL_UNSAFE,
       CreateMode.PERSISTENT); 
     // 创建一个子文件夹节点
     zk.create("/testRootPath/testChildPathOne", "testChildDataOne".getBytes(),
       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(), 
       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(); 

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    rsync 安装使用详解
    shell全备份脚本(借鉴别人的,在其基础上修复完善了bug)
    完全备份、差异备份以及增量备份的区别
    云主机格式化和挂载数据盘
    JSONP跨域
    php的多线程使用
    tp其他功能
    Zend Guard Loader和Zend Optimizer的安装(更新中)
    前端编码规范
    前端优化
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4729721.html
Copyright © 2011-2022 走看看