Example usage for org.apache.zookeeper.server DataNode getChildren

List of usage examples for org.apache.zookeeper.server DataNode getChildren

Introduction

In this page you can find the example usage for org.apache.zookeeper.server DataNode getChildren.

Prototype

public synchronized Set<String> getChildren() 

Source Link

Document

convenience methods to get the children

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 {//  ww w. j  a v a  2s.  com
            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;
    }

}