Search in sources :

Example 16 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method serializeNode.

/**
     * this method uses a stringbuilder to create a new path for children. This
     * is faster than string appends ( str1 + str2).
     *
     * @param oa
     *            OutputArchive to write to.
     * @param path
     *            a string builder.
     * @throws IOException
     * @throws InterruptedException
     */
void serializeNode(OutputArchive oa, StringBuilder path) throws IOException {
    String pathString = path.toString();
    DataNode node = getNode(pathString);
    if (node == null) {
        return;
    }
    String[] children = null;
    synchronized (node) {
        scount++;
        oa.writeString(pathString, "path");
        oa.writeRecord(node, "node");
        Set<String> childs = node.getChildren();
        if (childs != null) {
            children = childs.toArray(new String[childs.size()]);
        }
    }
    path.append('/');
    int off = path.length();
    if (children != null) {
        for (String child : children) {
            // since this is single buffer being resused
            // we need
            // to truncate the previous bytes of string.
            path.delete(off, Integer.MAX_VALUE);
            path.append(child);
            serializeNode(oa, path);
        }
    }
}
Also used : DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Aggregations

DataNode (org.apache.zookeeper_voltpatches.server.DataNode)16 NoNodeException (org.apache.zookeeper_voltpatches.KeeperException.NoNodeException)6 StatsTrack (org.apache.zookeeper_voltpatches.StatsTrack)3 Stat (org.apache.zookeeper_voltpatches.data.Stat)3 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)1 Watcher (org.apache.zookeeper_voltpatches.Watcher)1 StatPersisted (org.apache.zookeeper_voltpatches.data.StatPersisted)1