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


Java SetDataTxn类代码示例

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


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

示例1: addRequestToSyncProcessor

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
private void addRequestToSyncProcessor() {
    long zxid = ZxidUtils.makeZxid(3, 7);
    TxnHeader hdr = new TxnHeader(1, 1, zxid, 1,
            ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo" + zxid, new byte[0], 1);
    byte[] buf;
    try {
        buf = Util.marshallTxnEntry(hdr, txn);
    } catch (IOException e) {
        LOG.error("IOException while adding request to SyncRequestProcessor", e);
        Assert.fail("IOException while adding request to SyncRequestProcessor!");
        return;
    }
    NettyServerCnxnFactory factory = new NettyServerCnxnFactory();
    final MockNettyServerCnxn nettyCnxn = new MockNettyServerCnxn(null,
            this, factory);
    Request req = new Request(nettyCnxn, 1, 1, ZooDefs.OpCode.setData,
            ByteBuffer.wrap(buf), null);
    req.hdr = hdr;
    req.txn = txn;
    syncProcessor.processRequest(req);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:ZooKeeperServerMainTest.java

示例2: testGetTxnLogSyncElapsedTime

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@Test
public void testGetTxnLogSyncElapsedTime() throws IOException {
    File tmpDir = ClientBase.createEmptyTestDir();
    FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"),
            new File(tmpDir, "data_txnlog"));

    TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo", new byte[0], 1);
    Request req = new Request(0, 0, 0, hdr, txn, 0);

    try {
        fileTxnSnapLog.append(req);
        fileTxnSnapLog.commit();
        long syncElapsedTime = fileTxnSnapLog.getTxnLogElapsedSyncTime();
        Assert.assertNotEquals("Did not update syncElapsedTime!", -1L, syncElapsedTime);
    } finally {
        fileTxnSnapLog.close();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:20,代码来源:FileTxnSnapLogTest.java

示例3: testTruncationStreamReset

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.close();
    ClientBase.recursiveDelete(tmpdir);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:36,代码来源:TruncateTest.java

示例4: append

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
private void append(ZKDatabase zkdb, int i) throws IOException {
    TxnHeader hdr = new TxnHeader(1, 1, i, 1, ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo" + i, new byte[0], 1);
    Request req = new Request(null, 0, 0, 0, null, null);
    req.hdr = hdr;
    req.txn = txn;

    zkdb.append(req);
    zkdb.commit();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:11,代码来源:TruncateTest.java

示例5: testTxnLogElapsedSyncTime

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@Test
public void testTxnLogElapsedSyncTime() throws IOException {

    File tmpDir = ClientBase.createEmptyTestDir();
    FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"),
            new File(tmpDir, "data_txnlog"));

    ZooKeeperServer zks = new ZooKeeperServer();
    zks.setTxnLogFactory(fileTxnSnapLog);

    ZooKeeperServerBean serverBean = new ZooKeeperServerBean(zks);
    long elapsedTime = serverBean.getTxnLogElapsedSyncTime();
    assertEquals(-1, elapsedTime);

    TxnHeader hdr = new TxnHeader(1, 1, 1, 1, ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo", new byte[0], 1);
    Request req = new Request(0, 0, 0, hdr, txn, 0);

    try {

        zks.getTxnLogFactory().append(req);
        zks.getTxnLogFactory().commit();
        elapsedTime = serverBean.getTxnLogElapsedSyncTime();

        assertNotEquals(-1, elapsedTime);

        assertEquals(elapsedTime, serverBean.getTxnLogElapsedSyncTime());

    } finally {
        fileTxnSnapLog.close();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:33,代码来源:ZooKeeperServerBeanTest.java

示例6: testTruncationStreamReset

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);
    // make sure to snapshot, so that we have something there when
    // truncateLog reloads the db
    snaplog.save(zkdb.getDataTree(), zkdb.getSessionWithTimeOuts(), false);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
    iter.close();
    ClientBase.recursiveDelete(tmpdir);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:39,代码来源:TruncateTest.java

示例7: append

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
private void append(ZKDatabase zkdb, int i) throws IOException {
    TxnHeader hdr = new TxnHeader(1, 1, i, 1, ZooDefs.OpCode.setData);
    Record txn = new SetDataTxn("/foo" + i, new byte[0], 1);
    Request req = new Request(0, 0, 0, hdr, txn, 0);

    zkdb.append(req);
    zkdb.commit();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:9,代码来源:TruncateTest.java

示例8: testTruncationStreamReset

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@Test
public void testTruncationStreamReset() throws Exception {
    File tmpdir = ClientBase.createTmpDir();
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir);
    ZKDatabase zkdb = new ZKDatabase(snaplog);

    for (int i = 1; i <= 100; i++) {
        append(zkdb, i);
    }

    zkdb.truncateLog(1);

    append(zkdb, 200);

    zkdb.close();

    // verify that the truncation and subsequent append were processed
    // correctly
    FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2"));
    TxnIterator iter = txnlog.read(1);

    TxnHeader hdr = iter.getHeader();
    Record txn = iter.getTxn();
    Assert.assertEquals(1, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);

    iter.next();

    hdr = iter.getHeader();
    txn = iter.getTxn();
    Assert.assertEquals(200, hdr.getZxid());
    Assert.assertTrue(txn instanceof SetDataTxn);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:34,代码来源:TruncateTest.java

示例9: processTxn

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ProcessTxnResult processTxn(TxnHeader header, Record txn) {
    ProcessTxnResult rc = new ProcessTxnResult();

    String debug = "";
    try {
        rc.clientId = header.getClientId();
        rc.cxid = header.getCxid();
        rc.zxid = header.getZxid();
        rc.type = header.getType();
        rc.err = 0;
        if (rc.zxid > lastProcessedZxid) {
            lastProcessedZxid = rc.zxid;
        }
        switch (header.getType()) {
        case OpCode.create:
            CreateTxn createTxn = (CreateTxn) txn;
            debug = "Create transaction for " + createTxn.getPath();
            createNode(createTxn.getPath(), createTxn.getData(), createTxn
                    .getAcl(), createTxn.getEphemeral() ? header
                    .getClientId() : 0, header.getZxid(), header.getTime());
            rc.path = createTxn.getPath();
            break;
        case OpCode.delete:
            DeleteTxn deleteTxn = (DeleteTxn) txn;
            debug = "Delete transaction for " + deleteTxn.getPath();
            deleteNode(deleteTxn.getPath());
            break;
        case OpCode.setData:
            SetDataTxn setDataTxn = (SetDataTxn) txn;
            debug = "Set data for  transaction for " + setDataTxn.getPath();
            rc.stat = setData(setDataTxn.getPath(), setDataTxn.getData(),
                    setDataTxn.getVersion(), header.getZxid(), header
                            .getTime());
            break;
        case OpCode.setACL:
            SetACLTxn setACLTxn = (SetACLTxn) txn;
            debug = "Set ACL for  transaction for " + setACLTxn.getPath();
            rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(),
                    setACLTxn.getVersion());
            break;
        case OpCode.closeSession:
            killSession(header.getClientId());
            break;
        case OpCode.error:
            ErrorTxn errTxn = (ErrorTxn) txn;
            rc.err = errTxn.getErr();
            break;
        }
    } catch (KeeperException e) {
        // These are expected errors since we take a lazy snapshot
        if (initialized
                || (e.code() != Code.NONODE 
                        && e.code() != Code.NODEEXISTS)) {
            LOG.warn("Failed:" + debug, e);
        }
    }
    return rc;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:60,代码来源:DataTreeV1.java

示例10: processTxn

import org.apache.zookeeper.txn.SetDataTxn; //导入依赖的package包/类
public ProcessTxnResult processTxn(TxnHeader header, Record txn) {
    ProcessTxnResult rc = new ProcessTxnResult();

    String debug = "";
    try {
        rc.clientId = header.getClientId();
        rc.cxid = header.getCxid();
        rc.zxid = header.getZxid();
        rc.type = header.getType();
        rc.err = 0;
        if (rc.zxid > lastProcessedZxid) {
            lastProcessedZxid = rc.zxid;
        }
        switch (header.getType()) {
            case OpCode.create:
                CreateTxn createTxn = (CreateTxn) txn;
                debug = "Create transaction for " + createTxn.getPath();
                rc.path = createTxn.getPath();
                createNode(
                        createTxn.getPath(),
                        createTxn.getData(),
                        createTxn.getAcl(),
                        createTxn.getEphemeral() ? header.getClientId() : 0,
                        createTxn.getParentCVersion(),
                        header.getZxid(), header.getTime());
                break;
            case OpCode.delete:
                DeleteTxn deleteTxn = (DeleteTxn) txn;
                debug = "Delete transaction for " + deleteTxn.getPath();
                rc.path = deleteTxn.getPath();
                deleteNode(deleteTxn.getPath(), header.getZxid());
                break;
            case OpCode.setData:
                SetDataTxn setDataTxn = (SetDataTxn) txn;
                debug = "Set data for  transaction for "
                        + setDataTxn.getPath();
                rc.stat = setData(setDataTxn.getPath(), setDataTxn
                        .getData(), setDataTxn.getVersion(), header
                        .getZxid(), header.getTime());
                break;
            case OpCode.setACL:
                SetACLTxn setACLTxn = (SetACLTxn) txn;
                debug = "Set ACL for  transaction for "
                        + setACLTxn.getPath();
                rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(),
                        setACLTxn.getVersion());
                break;
            case OpCode.closeSession:
                killSession(header.getClientId(), header.getZxid());
                break;
            case OpCode.error:
                ErrorTxn errTxn = (ErrorTxn) txn;
                rc.err = errTxn.getErr();
                break;
        }
    } catch (KeeperException e) {
         LOG.debug("Failed: " + debug, e);
         rc.err = e.code().intValue();
    }
    return rc;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:62,代码来源:DataTree.java


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