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


Java BinaryOutputArchive类代码示例

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


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

示例1: serialize

import org.apache.jute.BinaryOutputArchive; //导入依赖的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: createBB

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
public void createBB() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        boa.writeInt(-1, "len"); // We'll fill this in later
        if (requestHeader != null) {
            requestHeader.serialize(boa, "header");
        }
        if (request instanceof ConnectRequest) {
            request.serialize(boa, "connect");
            // append "am-I-allowed-to-be-readonly" flag
            boa.writeBool(readOnly, "readOnly");
        } else if (request != null) {
            request.serialize(boa, "request");
        }
        baos.close();
        this.bb = ByteBuffer.wrap(baos.toByteArray());
        this.bb.putInt(this.bb.capacity() - 4);
        this.bb.rewind();
    } catch (IOException e) {
        LOG.warn("Ignoring unexpected exception", e);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:24,代码来源:ClientCnxn.java

示例3: serializeTree

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private static void serializeTree(int depth, int width, int len)
        throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    DataTree tree = new DataTree();
    createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]);
    int count = tree.getNodeCount();

    BinaryOutputArchive oa =
        BinaryOutputArchive.getArchive(new NullOutputStream());
    System.gc();
    long start = System.nanoTime();
    tree.serialize(oa, "test");
    long end = System.nanoTime();
    long durationms = (end - start)/1000000L;
    long pernodeus = ((end - start)/1000L)/count;
    LOG.info("Serialized " + count + " nodes in "
            + durationms + " ms (" + pernodeus + "us/node), depth="
            + depth + " width=" + width + " datalen=" + len);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:SerializationPerfTest.java

示例4: serialize

import org.apache.jute.BinaryOutputArchive; //导入依赖的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: deserializeTree

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private static void deserializeTree(int depth, int width, int len)
        throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    BinaryInputArchive ia;
    int count;
    {
        DataTree tree = new DataTree();
        SerializationPerfTest.createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]);
        count = tree.getNodeCount();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
        tree.serialize(oa, "test");
        baos.flush();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ia = BinaryInputArchive.getArchive(bais);
    }

    DataTree dserTree = new DataTree();

    System.gc();
    long start = System.nanoTime();
    dserTree.deserialize(ia, "test");
    long end = System.nanoTime();
    long durationms = (end - start) / 1000000L;
    long pernodeus = ((end - start) / 1000L) / count;

    Assert.assertEquals(count, dserTree.getNodeCount());

    LOG.info("Deserialized " + count + " nodes in " + durationms
            + " ms (" + pernodeus + "us/node), depth=" + depth + " width="
            + width + " datalen=" + len);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:DeserializationPerfTest.java

示例6: send

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private void send(DataOutputStream dout, byte[] response)
        throws IOException {
    QuorumAuthPacket authPacket;
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
    BinaryOutputArchive boa = BinaryOutputArchive
            .getArchive(bufferedOutput);
    if (response != null && response.length < 0) {
        throw new IOException("Response length < 0");
    } else if (response == null) {
        authPacket = QuorumAuth.createPacket(
                QuorumAuth.Status.IN_PROGRESS, response);
    } else {
        authPacket = QuorumAuth.createPacket(
                QuorumAuth.Status.IN_PROGRESS, response);
    }

    boa.writeRecord(authPacket, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
    bufferedOutput.flush();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:SaslQuorumAuthLearner.java

示例7: send

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private void send(DataOutputStream dout, byte[] challenge,
        QuorumAuth.Status s) throws IOException {
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
    BinaryOutputArchive boa = BinaryOutputArchive
            .getArchive(bufferedOutput);
    QuorumAuthPacket authPacket;
    if (challenge != null && challenge.length < 0) {
        throw new IOException("Response length < 0");
    } else if (challenge == null && s != QuorumAuth.Status.SUCCESS) {
        authPacket = QuorumAuth.createPacket(
                QuorumAuth.Status.IN_PROGRESS, challenge);
    } else {
        authPacket = QuorumAuth.createPacket(s, challenge);
    }

    boa.writeRecord(authPacket, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
    bufferedOutput.flush();
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:19,代码来源:SaslQuorumAuthServer.java

示例8: testSaslQuorumAuthServerWithInvalidQuorumAuthPacket

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
/**
 * SaslQuorumAuthServer throws exception on receiving an invalid quorum
 * auth packet.
 */
@Test(timeout = 30000)
public void testSaslQuorumAuthServerWithInvalidQuorumAuthPacket()
        throws Exception {
    Socket socket = getSocketPair();
    DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
    BinaryOutputArchive boa = BinaryOutputArchive
            .getArchive(bufferedOutput);
    QuorumAuthPacket authPacket = QuorumAuth
            .createPacket(QuorumAuth.Status.IN_PROGRESS, null);
    authPacket.setMagic(Long.MAX_VALUE); // invalid magic number
    boa.writeRecord(authPacket, null);
    bufferedOutput.flush();
    QuorumAuthServer authServer = new SaslQuorumAuthServer(true,
            "QuorumServer", authzHosts);
    BufferedInputStream is = new BufferedInputStream(
            socket.getInputStream());
    try {
        authServer.authenticate(socket, new DataInputStream(is));
        Assert.fail("Must throw exception as QuorumAuthPacket is invalid");
    } catch (SaslException e) {
        // expected
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:29,代码来源:QuorumCnxManagerTest.java

示例9: testNullQuorumAuthServerWithValidQuorumAuthPacket

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
/**
 * NullQuorumAuthServer should return true on receiving a valid quorum auth
 * packet.
 */
@Test(timeout = 30000)
public void testNullQuorumAuthServerWithValidQuorumAuthPacket()
        throws Exception {
    Socket socket = getSocketPair();
    DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
    BinaryOutputArchive boa = BinaryOutputArchive
            .getArchive(bufferedOutput);
    QuorumAuthPacket authPacket = QuorumAuth
            .createPacket(QuorumAuth.Status.IN_PROGRESS, null);
    boa.writeRecord(authPacket, null);
    bufferedOutput.flush();
    QuorumAuthServer authServer = new NullQuorumAuthServer();
    BufferedInputStream is = new BufferedInputStream(
            socket.getInputStream());
    // It will throw exception and fail the
    // test if any unexpected error. Not adding any extra assertion.
    authServer.authenticate(socket, new DataInputStream(is));
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:24,代码来源:QuorumCnxManagerTest.java

示例10: marshallTxnEntry

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
/**
 * Serializes transaction header and transaction data into a byte buffer.
 *  
 * @param hdr transaction header
 * @param txn transaction data
 * @return serialized transaction record
 * @throws IOException
 */
public static byte[] marshallTxnEntry(TxnHeader hdr, Record txn)
        throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputArchive boa = BinaryOutputArchive.getArchive(baos);

    hdr.serialize(boa, "hdr");
    if (txn != null) {
        txn.serialize(boa, "txn");
    }
    return baos.toByteArray();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:Util.java

示例11: sendResponse

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
@Override
public void sendResponse(ReplyHeader h, Record r, String tag)
        throws IOException {
    if (!channel.isOpen()) {
        return;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Make space for length
    BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
    try {
        baos.write(fourBytes);
        bos.writeRecord(h, "header");
        if (r != null) {
            bos.writeRecord(r, tag);
        }
        baos.close();
    } catch (IOException e) {
        LOG.error("Error serializing response");
    }
    byte b[] = baos.toByteArray();
    ByteBuffer bb = ByteBuffer.wrap(b);
    bb.putInt(b.length - 4).rewind();
    sendBuffer(bb);
    if (h.getXid() > 0) {
        // zks cannot be null otherwise we would not have gotten here!
        if (!zkServer.shouldThrottle(outstandingCount.decrementAndGet())) {
            enableRecv();
        }
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:NettyServerCnxn.java

示例12: addCommittedProposal

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
/**
 * maintains a list of last <i>committedLog</i>
 *  or so committed requests. This is used for
 * fast follower synchronization.
 * @param request committed request
 */
public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
        wl.lock();
        if (committedLog.size() > commitLogCount) {
            committedLog.removeFirst();
            minCommittedLog = committedLog.getFirst().packet.getZxid();
        }
        if (committedLog.size() == 0) {
            minCommittedLog = request.zxid;
            maxCommittedLog = request.zxid;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.hdr.serialize(boa, "hdr");
            if (request.txn != null) {
                request.txn.serialize(boa, "txn");
            }
            baos.close();
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
                baos.toByteArray(), null);
        Proposal p = new Proposal();
        p.packet = pp;
        p.request = request;
        committedLog.add(p);
        maxCommittedLog = p.packet.getZxid();
    } finally {
        wl.unlock();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:42,代码来源:ZKDatabase.java

示例13: deserializeTree

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private static void deserializeTree(int depth, int width, int len)
        throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
    BinaryInputArchive ia;
    int count;
    {
        DataTree tree = new DataTree();
        SerializationPerfTest.createNodes(tree, "/", depth, tree.getNode("/").stat.getCversion(), width, new byte[len]);
        count = tree.getNodeCount();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
        tree.serialize(oa, "test");
        baos.flush();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ia = BinaryInputArchive.getArchive(bais);
    }

    DataTree dserTree = new DataTree();

    System.gc();
    long start = System.nanoTime();
    dserTree.deserialize(ia, "test");
    long end = System.nanoTime();
    long durationms = (end - start) / 1000000L;
    long pernodeus = ((end - start) / 1000L) / count;

    Assert.assertEquals(count, dserTree.getNodeCount());

    LOG.info("Deserialized " + count + " nodes in " + durationms
            + " ms (" + pernodeus + "us/node), depth=" + depth + " width="
            + width + " datalen=" + len);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:DeserializationPerfTest.java

示例14: createRequest

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
private Request createRequest(Record record, int opCode) throws IOException {
    // encoding
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    record.serialize(boa, "request");
    baos.close();

    // Id
    List<Id> ids = Arrays.asList(Ids.ANYONE_ID_UNSAFE);

    return new Request(null, 1l, 0, opCode, ByteBuffer.wrap(baos.toByteArray()), ids);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:13,代码来源:PrepRequestProcessorTest.java

示例15: testPathTrieClearOnDeserialize

import org.apache.jute.BinaryOutputArchive; //导入依赖的package包/类
@Test(timeout = 60000)
public void testPathTrieClearOnDeserialize() throws Exception {

    //Create a DataTree with quota nodes so PathTrie get updated
    DataTree dserTree = new DataTree();
    
    dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1);
    dserTree.createNode(Quotas.quotaZookeeper+"/bug", null, null, -1, 1, 1, 1);
    dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1);
    dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1);
    
    //deserialize a DataTree; this should clear the old /bug nodes and pathTrie
    DataTree tree = new DataTree();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
    tree.serialize(oa, "test");
    baos.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    BinaryInputArchive ia = BinaryInputArchive.getArchive(bais);
    dserTree.deserialize(ia, "test");

    Field pfield = DataTree.class.getDeclaredField("pTrie");
    pfield.setAccessible(true);
    PathTrie pTrie = (PathTrie)pfield.get(dserTree);

    //Check that the node path is removed from pTrie
    Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug"));       
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:DataTreeTest.java


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