zooKeeper = new ZooKeeper("192.168.2.103:2181", 4000, new Watcher() { @Override publicvoidprocess(WatchedEvent watchedEvent){ System.out.println("init:"+watchedEvent.getPath()); } });
创建、查看节点
创建节点
通过org.apache.zookeeper.ZooKeeper#create()即可创建节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
publicvoidcreateData()throws InterruptedException, KeeperException { List<ACL> aclList = new ArrayList<>(); int perm = ZooDefs.Perms.ADMIN | ZooDefs.Perms.READ;
// perms 对应权限位permission // id 对应权限模式scheme + id ACL acl1 = new ACL(perm, new Id("world","anyone")); ACL acl2 = new ACL(perm, new Id("ip","192.168.2.103")); ACL acl3 = new ACL(perm, new Id("ip","127.0.0.1"));
[zk: 127.0.0.1:2181(CONNECTED) 64] getAcl /hello 'world,'anyone : ra 'ip,'192.168.2.103 : ra 'ip,'127.0.0.1 : ra [zk: 127.0.0.1:2181(CONNECTED) 65] get /hello hello word