当前位置: 首页>>代码示例>>Java>>正文


Java DataTree类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.DataTree的典型用法代码示例。如果您正苦于以下问题:Java DataTree类的具体用法?Java DataTree怎么用?Java DataTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataTree类属于org.apache.zookeeper.server包,在下文中一共展示了DataTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * serialize the datatree and session into the file snapshot
 * @param dt the datatree to be serialized
 * @param sessions the sessions to be serialized
 * @param snapShot the file to store snapshot into
 */
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot)
        throws IOException {
    if (!close) {
        OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
        CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
        //CheckedOutputStream cout = new CheckedOutputStream()
        OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
        FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
        serialize(dt,sessions,oa, header);
        long val = crcOut.getChecksum().getValue();
        oa.writeLong(val, "val");
        oa.writeString("/", "path");
        sessOS.flush();
        crcOut.close();
        sessOS.close();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:24,代码来源:FileSnap.java

示例2: deserializeSnapshot

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
public static void deserializeSnapshot(DataTree dt,InputArchive ia,
        Map<Long, Integer> sessions) throws IOException {
    int count = ia.readInt("count");
    while (count > 0) {
        long id = ia.readLong("id");
        int to = ia.readInt("timeout");
        sessions.put(id, to);
        if (LOG.isTraceEnabled()) {
            ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
                    "loadData --- session in archive: " + id
                    + " with timeout: " + to);
        }
        count--;
    }
    dt.deserialize(ia, "tree");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:SerializeUtils.java

示例3: getACL

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * Return the ACL and stat of the node of the given path.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 *
 * @param path
 *                the given path for the node
 * @param stat
 *                the stat of the node will be copied to this parameter if
 *                not null.
 * @return the ACL array of the given node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public List<ACL> getACL(final String path, Stat stat)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getAcl();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:40,代码来源:ZooKeeper.java

示例4: serialize

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * serialize the datatree and session into the file snapshot
 * @param dt the datatree to be serialized
 * @param sessions the sessions to be serialized
 * @param snapShot the file to store snapshot into
 * @param fsync sync the file immediately after write
 */
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot, boolean fsync)
        throws IOException {
    if (!close) {
        try (CheckedOutputStream crcOut =
                     new CheckedOutputStream(new BufferedOutputStream(fsync ? new AtomicFileOutputStream(snapShot) :
                                                                              new FileOutputStream(snapShot)),
                                             new Adler32())) {
            //CheckedOutputStream cout = new CheckedOutputStream()
            OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
            FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
            serialize(dt, sessions, oa, header);
            long val = crcOut.getChecksum().getValue();
            oa.writeLong(val, "val");
            oa.writeString("/", "path");
            crcOut.flush();
        }
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:26,代码来源:FileSnap.java

示例5: commandRun

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
@Override
public void commandRun() {
    if (!isZKServerRunning()) {
        pw.println(ZK_NOT_SERVING);
    } else {
        DataTree dt = zkServer.getZKDatabase().getDataTree();
        if (len == FourLetterCommands.wchsCmd) {
            dt.dumpWatchesSummary(pw);
        } else if (len == FourLetterCommands.wchpCmd) {
            dt.dumpWatches(pw, true);
        } else {
            dt.dumpWatches(pw, false);
        }
        pw.println();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:WatchCommand.java

示例6: attemptAutoCreateDb

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
private void attemptAutoCreateDb(File dataDir, File snapDir, Map<Long, Integer> sessions,
                                 String priorAutocreateDbValue, String autoCreateValue,
                                 long expectedValue) throws IOException {
    sessions.clear();
    System.setProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE, autoCreateValue);
    FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(dataDir, snapDir);

    try {
        long zxid = fileTxnSnapLog.restore(new DataTree(), sessions, new FileTxnSnapLog.PlayBackListener() {
            @Override
            public void onTxnLoaded(TxnHeader hdr, Record rec) {
                // empty by default
            }
        });
        Assert.assertEquals("unexpected zxid", expectedValue, zxid);
    } finally {
        if (priorAutocreateDbValue == null) {
            System.clearProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE);
        } else {
            System.setProperty(FileTxnSnapLog.ZOOKEEPER_DB_AUTOCREATE, priorAutocreateDbValue);
        }
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:24,代码来源:FileTxnSnapLogTest.java

示例7: getACL

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * Return the ACL and stat of the node of the given path.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 *
 * @param path
 *                the given path for the node
 * @param stat
 *                the stat of the node will be copied to this parameter.
 * @return the ACL array of the given node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public List<ACL> getACL(final String path, Stat stat)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    DataTree.copyStat(response.getStat(), stat);
    return response.getAcl();
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:37,代码来源:ZooKeeper.java

示例8: commandRun

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
@Override
public void commandRun() {
    if (zkServer == null) {
        pw.println(ZK_NOT_SERVING);
    } else {
        DataTree dt = zkServer.getZKDatabase().getDataTree();
        if (len == FourLetterCommands.wchsCmd) {
            dt.dumpWatchesSummary(pw);
        } else if (len == FourLetterCommands.wchpCmd) {
            dt.dumpWatches(pw, true);
        } else {
            dt.dumpWatches(pw, false);
        }
        pw.println();
    }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:17,代码来源:WatchCommand.java

示例9: testTxnFailure

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * For ZOOKEEPER-1046. Verify if cversion and pzxid if incremented
 * after create/delete failure during restore.
 */
@Test
public void testTxnFailure() throws Exception {
    long count = 1;
    File tmpDir = ClientBase.createTmpDir();
    FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir);
    DataTree dt = new DataTree();
    dt.createNode("/test", new byte[0], null, 0, -1, 1, 1);
    for (count = 1; count <= 3; count++) {
        dt.createNode("/test/" + count, new byte[0], null, 0, -1, count,
                System.currentTimeMillis());
    }
    DataNode zk = dt.getNode("/test");

    // Make create to fail, then verify cversion.
    LOG.info("Attempting to create " + "/test/" + (count - 1));
    doOp(logFile, OpCode.create, "/test/" + (count - 1), dt, zk);

    // Make delete fo fail, then verify cversion.
    // this doesn't happen anymore, we only set the cversion on create
    // LOG.info("Attempting to delete " + "/test/" + (count + 1));
    // doOp(logFile, OpCode.delete, "/test/" + (count + 1), dt, zk);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:LoadFromLogTest.java

示例10: deserializeSnapshot

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
public static void deserializeSnapshot(DataTree dt,InputArchive ia,
        Map<Long, Integer> sessions) throws IOException {
    // 读取session个数
    int count = ia.readInt("count");
    while (count > 0) {
        // session id
        long id = ia.readLong("id");
        // session超时时间
        int to = ia.readInt("timeout");
        // 解析session集合
        sessions.put(id, to);
        if (LOG.isTraceEnabled()) {
            ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
                    "loadData --- session in archive: " + id
                    + " with timeout: " + to);
        }
        count--;
    }
    // 反序列化tree
    dt.deserialize(ia, "tree");
}
 
开发者ID:txazo,项目名称:zookeeper,代码行数:22,代码来源:SerializeUtils.java

示例11: convertDataNode

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * convert a given old datanode to new datanode
 * @param dt the new datatree
 * @param parent the parent of the datanode to be constructed
 * @param oldDataNode the old datanode 
 * @return the new datanode
 */
private DataNode convertDataNode(DataTree dt, DataNode parent, 
        DataNodeV1 oldDataNode) {
    StatPersisted stat = convertStat(oldDataNode.stat);
    DataNode dataNode =  new DataNode(parent, oldDataNode.data,
            dt.getACL(oldDataNode), stat);
    dataNode.setChildren(oldDataNode.children);
    return dataNode;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:16,代码来源:UpgradeSnapShotV1.java

示例12: recurseThroughDataTree

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * recurse through the old datatree and construct the 
 * new data tree
 * @param dataTree the new datatree to be constructed
 * @param path the path to start with
 */
private void recurseThroughDataTree(DataTree dataTree, String path) {
    if (path == null)
        return;
    DataNodeV1 oldDataNode = oldDataTree.getNode(path);
    HashSet<String> children = oldDataNode.children;
    DataNode parent = null;
    if ("".equals(path)) {
        parent = null;
    }
    else {
        int lastSlash = path.lastIndexOf('/');
        String parentPath = path.substring(0, lastSlash);
        parent = dataTree.getNode(parentPath);
    }
    DataNode thisDatNode = convertDataNode(dataTree, parent,
                                oldDataNode);
    dataTree.addDataNode(path, thisDatNode);
    if (children == null || children.size() == 0) {
        return;
    }
    else {
        for (String child: children) {
            recurseThroughDataTree(dataTree, path + "/" +child);
        }
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:33,代码来源:UpgradeSnapShotV1.java

示例13: convertThisSnapShot

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
private DataTree convertThisSnapShot() throws IOException {
    // create a datatree 
    DataTree dataTree = new DataTree();
    DataNodeV1 oldDataNode = oldDataTree.getNode("");
    if (oldDataNode == null) {
        //should never happen
        LOG.error("Upgrading from an empty snapshot.");
    }
    
    recurseThroughDataTree(dataTree, "");
    dataTree.lastProcessedZxid = oldDataTree.lastProcessedZxid;
    return dataTree;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:UpgradeSnapShotV1.java

示例14: runUpgrade

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * run the upgrade
 * @throws IOException
 */
public void runUpgrade() throws IOException {
    if (!dataDir.exists()) {
        throw new IOException(dataDir + " does not exist");
    }
    if (!snapShotDir.exists()) {
        throw new IOException(snapShotDir + " does not exist");
    }
    // create the bkup directorya
    createAllDirs();
    //copy all the files for backup
    try {
        copyFiles(dataDir, bkupdataDir, "log");
        copyFiles(snapShotDir, bkupsnapShotDir, "snapshot");
    } catch(IOException io) {
        LOG.error("Failed in backing up.");
        throw io;
    }

    //evrything is backed up
    // read old database and create 
    // an old snapshot
    UpgradeSnapShotV1 upgrade = new UpgradeSnapShotV1(bkupdataDir, 
            bkupsnapShotDir);
    LOG.info("Creating new data tree");
    DataTree dt = upgrade.getNewDataTree();
    FileTxnSnapLog filesnapLog = new FileTxnSnapLog(dataDir, 
            snapShotDir);
    LOG.info("snapshotting the new datatree");
    filesnapLog.save(dt, upgrade.getSessionWithTimeOuts());
    //done saving.
    LOG.info("Upgrade is complete");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:37,代码来源:UpgradeMain.java

示例15: deserialize

import org.apache.zookeeper.server.DataTree; //导入依赖的package包/类
/**
 * deserialize the datatree from an inputarchive
 * @param dt the datatree to be serialized into
 * @param sessions the sessions to be filled up
 * @param ia the input archive to restore from
 * @throws IOException
 */
public void deserialize(DataTree dt, Map<Long, Integer> sessions,
        InputArchive ia) throws IOException {
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    if (header.getMagic() != SNAP_MAGIC) {
        throw new IOException("mismatching magic headers "
                + header.getMagic() + 
                " !=  " + FileSnap.SNAP_MAGIC);
    }
    SerializeUtils.deserializeSnapshot(dt,ia,sessions);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:FileSnap.java


注:本文中的org.apache.zookeeper.server.DataTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。