Example usage for org.apache.zookeeper.server DataTree getNode

List of usage examples for org.apache.zookeeper.server DataTree getNode

Introduction

In this page you can find the example usage for org.apache.zookeeper.server DataTree getNode.

Prototype

public DataNode getNode(String path) 

Source Link

Usage

From source file:com.linkedin.helix.tools.ZKLogFormatter.java

License:Apache License

private static void traverse(DataTree dt, int startId, String startPath) throws Exception {
    LinkedList<Pair> queue = new LinkedList<Pair>();
    queue.add(new Pair(startPath, startId));
    while (!queue.isEmpty()) {
        Pair pair = queue.removeFirst();
        String path = pair._path;
        DataNode head = dt.getNode(path);
        Stat stat = new Stat();
        byte[] data = null;
        try {/*from w w w.  j av a2s .c  om*/
            data = dt.getData(path, stat, null);
        } catch (NoNodeException e) {
            e.printStackTrace();
        }
        // print the node
        format(startId, pair, head, data);
        Set<String> children = head.getChildren();
        if (children != null) {
            for (String child : children) {
                String childPath;
                if (path.endsWith("/")) {
                    childPath = path + child;
                } else {
                    childPath = path + "/" + child;
                }
                queue.add(new Pair(childPath, startId));
            }
        }
        startId = startId + 1;
    }

}