publicvoidtest3()throws KeeperException, InterruptedException {//world授权模式//1.权限列表
List<ACL> aclList=newArrayList<>();//2.权限模式(scheme)、授权对象(id)
Id id=newId("world","anyone");//3.权限设置:// int READ = 1;// int WRITE = 2;// int CREATE = 4;// int DELETE = 8;// int ADMIN = 16;// int ALL = 31;
aclList.add(newACL(ZooDefs.Perms.READ,id));
aclList.add(newACL(ZooDefs.Perms.WRITE,id));
aclList.add(newACL(ZooDefs.Perms.CREATE,id));
aclList.add(newACL(ZooDefs.Perms.DELETE,id));
aclList.add(newACL(ZooDefs.Perms.ADMIN,id));
zooKeeper.create("/test/node3","abc".getBytes(), aclList, CreateMode.PERSISTENT);}
1.2.4.ip授权模式
publicvoidtest4()throws KeeperException, InterruptedException {//ip授权模式//1.权限列表
List<ACL> aclList=newArrayList<>();//2.权限模式(scheme)、授权对象(id)
Id id=newId("ip","192.168.31.220");//3.权限设置:// int ALL = 31;
aclList.add(newACL(ZooDefs.Perms.ALL,id));
zooKeeper.create("/test/node4","abc".getBytes(), aclList, CreateMode.PERSISTENT);}
publicvoidtest12()throws KeeperException, InterruptedException {//1.path: 节点路径//2.watch: 是否使用创建连接中注册的监听器//注意:stat为null代表节点不存在
Stat stat = zooKeeper.exists("/test",false);}
1.7.2.异步获取
publicvoidtest12()throws KeeperException, InterruptedException {//1.path: 节点路径//2.watch: 是否使用创建连接中注册的监听器//3.StatCallback: 回调接口//4.ctx: 上下文参数
zooKeeper.exists("/test/node1",false,newAsyncCallback.StatCallback(){@OverridepublicvoidprocessResult(int i, String path, Object ctx, Stat stat){}},"Object ctx");}