Import java.io.IOException;
Import java.util.ArrayList;
Import java.util.List;
Import org.apache.hadoop.hbase.util.Bytes;
Import Org.apache.zookeeper.CreateMode;
Import org.apache.zookeeper.KeeperException;
Import Org.apache.zookeeper.Watcher;
Import Org.apache.zookeeper.ZooDefs;
Import Org.apache.zookeeper.ZooKeeper;
Import Org.apache.zookeeper.data.ACL;
Import Org.apache.zookeeper.data.Id;
Import Org.apache.zookeeper.data.Stat;
public class Zkgetchild_setacl {//Session timeout, set to coincide with system default time private static final int session_timeout=30000;
Create zookeeper instance zookeeper ZK; Create watcher Instance Watcher Wh=new watcher () {public void process (org.apache.zookeeper.WatchedEvent
Event) {System.out.println (event.tostring ());
}
}; Initializes the zookeeper instance private void Createzkinstance () throws IOException {
Zk=new Zookeeper ("10.xxx.xxx.24:2181", ZKGETCHILD_SETACL.SESSION_TIMEOUT,THIS.WH);
private void Getchild (String path) throws Ioexception,interruptedexception,keeperexception {
ID ID = new ID ("IP", "10.XXX.XXX.23/27");
ACL ACL = new ACL (ZooDefs.Perms.ALL, id);
List<acl> ACLS = new arraylist<acl> ();
Acls.add (ACL);
Zk.setacl (Path, ACLs,-1);
System.out.println ("Set ACL succ:" +path);
List<string> Child_list=zk.getchildren (path, false);
for (String child:child_list) {System.out.println ("Child:" +child);
if (Path.equals ("/")) {child=path+ "" +child;
System.out.println ("A:" +child);
}else{child=path+ "/" +child;
System.out.println ("B:" +child);
} System.out.println (New String (Zk.getdata (child,false,null));child=path+ "" +child;
Stat Stat = Zk.exists (child, false);
List<acl> Child_acl=zk.getacl (child, stat);
for (ACL a:child_acl) {//system.out.println (a.getperms ());
System.out.println (a);
System.out.println ("**********");
} getchild (child);
} private void Confacl (String path) throws Keeperexception, Interruptedexception { ID ID = new ID ("World", "anyone"); Release permission id ID2 = new ID ("IP", "10.xxx.xxx.24");
Qualify IP ACL ACL = new ACL (ZooDefs.Perms.ALL, id);
ACL Acl2 = new ACL (ZooDefs.Perms.ALL, ID2);
List<acl> ACLS = new arraylist<acl> ();
Acls.add (ACL);
Acls.add (ACL2);
Zk.setacl (Path, ACLs,-1);
System.out.println ("Set ACL succ:" +path); private void Zkclose () throws Interruptedexception {
Zk.close ();
public static void Main (string[] args) throws Ioexception,interruptedexception,keeperexception {
Zkgetchild_setacl dm=new Zkgetchild_setacl ();
Dm.createzkinstance ();
Dm.confacl ("/hbase/master"); Dm.
Zkclose (); }
}