java读取zookeeper中的配置文件信息

来源:互联网 发布:worknc软件怎么样 编辑:程序博客网 时间:2024/06/06 00:07
public static void main(String[] args) {        String connectString = "127.0.0.1:2181";        int sessionTimeout = 4000;        Watcher watcher = new Watcher() {            public void process(WatchedEvent event) {                //System.out.println(event.getPath());            }        };        try {            ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, watcher);            List<String> list = zooKeeper.getChildren("/config", false);            for (String path : list) {                System.out.println(path);                byte[] b = zooKeeper.getData("/config/"+path, false, null) ;                System.out.println( new String(b) );            }        } catch (IOException e) {            e.printStackTrace();        } catch (KeeperException e) {            e.printStackTrace();        } catch (InterruptedException e) {            e.printStackTrace();        }    }