package zookeeper.test;
import java.io.IOException;
import java.util.List;
public class ListGroup extends ConnectionWatcher{
public void list(String groupname) {
String path = "/" + groupname;
try {
List<String> children = zk.getChildren(path, false);
if(children.isEmpty()) {
System.out.println("no member in group "+groupname);
System.exit(1);
}
for(String s:children) {
System.out.println(s);
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException, IOException {
ListGroup lg = new ListGroup();
lg.connect("localhost");
lg.list("test");
lg.close();
}
}
|