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


Java BinaryInputArchive.getArchive方法代码示例

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


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

示例1: loadThisSnapShot

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
 * create the old snapshot database
 * apply logs to it and create the final
 * database
 * @throws IOException
 */
private void loadThisSnapShot() throws IOException {  
    // pick the most recent snapshot
    File snapshot = findMostRecentSnapshot();
    if (snapshot == null) {
        throw new IOException("Invalid snapshots " +
        		"or not snapshots in " + snapShotDir);
    }
    InputStream inputstream = new BufferedInputStream(
            new FileInputStream(snapshot));
    InputArchive ia = BinaryInputArchive.getArchive(inputstream);
    deserializeSnapshot(oldDataTree, ia, sessionsWithTimeouts);
    //ok done with the snapshot 
    // now apply the logs
    long snapshotZxid = oldDataTree.lastProcessedZxid;
    File[] files = FileTxnLog.getLogFiles(
            dataDir.listFiles(), snapshotZxid);
    long zxid = processLogFiles(oldDataTree, files);
    //check for this zxid to be sane
    if (zxid != oldDataTree.lastProcessedZxid) {
        LOG.error("Zxids not equal " + " log zxid " +
                zxid + " datatree processed " + oldDataTree.lastProcessedZxid);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:30,代码来源:UpgradeSnapShotV1.java

示例2: testPad

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:LoadFromLogTest.java

示例3: getCheckSum

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
    DataTree dt = new DataTree();
    Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
    InputStream snapIS = new BufferedInputStream(new FileInputStream(
            snapFile));
    CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(crcIn);
    try {
        snap.deserialize(dt, sessions, ia);
    } catch (IOException ie) {
        // we failed on the most recent snapshot
        // must be incomplete
        // try reading the next one
        // after corrupting
        snapIS.close();
        crcIn.close();
        throw ie;
    }

    long checksum = crcIn.getChecksum().getValue();
    long val = ia.readLong("val");
    snapIS.close();
    crcIn.close();
    return (val != checksum);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:CRCTest.java

示例4: readHeader

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
 * read the header of the transaction file
 * @param file the transaction file to read
 * @return header that was read fomr the file
 * @throws IOException
 */
private static FileHeader readHeader(File file) throws IOException {
    InputStream is =null;
    try {
        is = new BufferedInputStream(new FileInputStream(file));
        InputArchive ia=BinaryInputArchive.getArchive(is);
        FileHeader hdr = new FileHeader();
        hdr.deserialize(ia, "fileheader");
        return hdr;
     } finally {
         try {
             if (is != null) is.close();
         } catch (IOException e) {
             LOG.warn("Ignoring exception during close", e);
         }
     }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:23,代码来源:FileTxnLog.java

示例5: createInputArchive

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
 * Invoked to indicate that the input stream has been created.
 * @param ia input archive
 * @param is file input stream associated with the input archive.
 * @throws IOException
 **/
protected InputArchive createInputArchive(File logFile) throws IOException {
    if(inputStream==null){
        inputStream= new PositionInputStream(new BufferedInputStream(new FileInputStream(logFile)));
        LOG.debug("Created new input stream " + logFile);
        ia  = BinaryInputArchive.getArchive(inputStream);
        inStreamCreated(ia,inputStream);
        LOG.debug("Created new input archive " + logFile);
    }
    return ia;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:FileTxnLog.java

示例6: testPurgeUnused

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
@Test
public void testPurgeUnused() throws IOException {
    ReferenceCountedACLCache cache = new ReferenceCountedACLCache();

    List<ACL> acl1 = createACL("one");
    List<ACL> acl2 = createACL("two");
    List<ACL> acl3 = createACL("three");
    List<ACL> acl4 = createACL("four");
    List<ACL> acl5 = createACL("five");

    Long aclId1 = convertACLsNTimes(cache, acl1, 1);
    Long aclId2 = convertACLsNTimes(cache, acl2, 2);
    Long aclId3 = convertACLsNTimes(cache, acl3, 3);
    Long aclId4 = convertACLsNTimes(cache, acl4, 4);
    Long aclId5 = convertACLsNTimes(cache, acl5, 5);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos);
    cache.serialize(archive);

    BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
    ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache();
    deserializedCache.deserialize(inArchive);
    callAddUsageNTimes(deserializedCache, aclId1, 1);
    callAddUsageNTimes(deserializedCache, aclId2, 2);
    deserializedCache.purgeUnused();

    assertEquals(2, deserializedCache.size());
    assertEquals(aclId1, deserializedCache.convertAcls(acl1));
    assertEquals(aclId2, deserializedCache.convertAcls(acl2));
    assertFalse(acl3.equals(deserializedCache.convertAcls(acl3)));
    assertFalse(acl4.equals(deserializedCache.convertAcls(acl4)));
    assertFalse(acl5.equals(deserializedCache.convertAcls(acl5)));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:35,代码来源:ReferenceCountedACLCacheTest.java

示例7: run

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
public void run(String snapshotFileName) throws IOException {
    InputStream is = new CheckedInputStream(
            new BufferedInputStream(new FileInputStream(snapshotFileName)),
            new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(is);
    
    FileSnap fileSnap = new FileSnap(null);

    DataTree dataTree = new DataTree();
    Map<Long, Integer> sessions = new HashMap<Long, Integer>();
    
    fileSnap.deserialize(dataTree, sessions, ia);

    printDetails(dataTree, sessions);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:16,代码来源:SnapshotFormatter.java

示例8: deserializeTree

import org.apache.jute.BinaryInputArchive; //导入方法依赖的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

示例9: deserialize

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
/**
 * deserialize a data tree from the most recent snapshot
 * @return the zxid of the snapshot
 */
public long deserialize(DataTree dt, Map<Long, Integer> sessions)
        throws IOException {
    // we run through 100 snapshots (not all of them)
    // if we cannot get it running within 100 snapshots
    // we should  give up
    List<File> snapList = findNValidSnapshots(100);
    if (snapList.size() == 0) {
        return -1L;
    }
    File snap = null;
    boolean foundValid = false;
    for (int i = 0, snapListSize = snapList.size(); i < snapListSize; i++) {
        snap = snapList.get(i);
        LOG.info("Reading snapshot " + snap);
        try (InputStream snapIS = new BufferedInputStream(new FileInputStream(snap));
             CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32())) {
            InputArchive ia = BinaryInputArchive.getArchive(crcIn);
            deserialize(dt, sessions, ia);
            long checkSum = crcIn.getChecksum().getValue();
            long val = ia.readLong("val");
            if (val != checkSum) {
                throw new IOException("CRC corruption in snapshot :  " + snap);
            }
            foundValid = true;
            break;
        } catch (IOException e) {
            LOG.warn("problem reading snap file " + snap, e);
        }
    }
    if (!foundValid) {
        throw new IOException("Not able to find valid snapshots in " + snapDir);
    }
    dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), "snapshot");
    return dt.lastProcessedZxid;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:40,代码来源:FileSnap.java

示例10: testPathTrieClearOnDeserialize

import org.apache.jute.BinaryInputArchive; //导入方法依赖的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

示例11: testPathTrieClearOnDeserialize

import org.apache.jute.BinaryInputArchive; //导入方法依赖的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:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:31,代码来源:DataTreeTest.java

示例12: codeDecode

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
private MultiResponse codeDecode(MultiResponse request) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    request.serialize(boa, "result");
    baos.close();
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
    bb.rewind();

    BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb));
    MultiResponse decodedRequest = new MultiResponse();
    decodedRequest.deserialize(bia, "result");
    return decodedRequest;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:MultiResponseTest.java

示例13: deserializeTree

import org.apache.jute.BinaryInputArchive; //导入方法依赖的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:sereca,项目名称:SecureKeeper,代码行数:34,代码来源:DeserializationPerfTest.java

示例14: testSerializeDeserialize

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
@Test
public void testSerializeDeserialize() throws IOException {
    ReferenceCountedACLCache cache = new ReferenceCountedACLCache();

    List<ACL> acl1 = createACL("one");
    List<ACL> acl2 = createACL("two");
    List<ACL> acl3 = createACL("three");
    List<ACL> acl4 = createACL("four");
    List<ACL> acl5 = createACL("five");

    Long aclId1 = convertACLsNTimes(cache, acl1, 1);
    Long aclId2 = convertACLsNTimes(cache, acl2, 2);
    Long aclId3 = convertACLsNTimes(cache, acl3, 3);
    Long aclId4 = convertACLsNTimes(cache, acl4, 4);
    Long aclId5 = convertACLsNTimes(cache, acl5, 5);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos);
    cache.serialize(archive);

    BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
    ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache();
    deserializedCache.deserialize(inArchive);
    callAddUsageNTimes(deserializedCache, aclId1, 1);
    callAddUsageNTimes(deserializedCache, aclId2, 2);
    callAddUsageNTimes(deserializedCache, aclId3, 3);
    callAddUsageNTimes(deserializedCache, aclId4, 4);
    callAddUsageNTimes(deserializedCache, aclId5, 5);

    assertCachesEqual(cache, deserializedCache);
}
 
开发者ID:jdc91,项目名称:StreamProcessingInfrastructure,代码行数:32,代码来源:ReferenceCountedACLCacheTest.java

示例15: testFollowerConversation

import org.apache.jute.BinaryInputArchive; //导入方法依赖的package包/类
public void testFollowerConversation(FollowerConversation conversation) throws Exception {
    File tmpDir = File.createTempFile("test", "dir", testData);
    tmpDir.delete();
    tmpDir.mkdir();
    Thread followerThread = null;
    ConversableFollower follower = null;
    QuorumPeer peer = null;
    try {
        peer = createQuorumPeer(tmpDir);
        follower = createFollower(tmpDir, peer);
        peer.follower = follower;
        
        ServerSocket ss = new ServerSocket();
        ss.bind(null);
        QuorumServer leaderQS = new QuorumServer(1,
                (InetSocketAddress) ss.getLocalSocketAddress());
        follower.setLeaderQuorumServer(leaderQS);
        final Follower followerForThread = follower;
        
        followerThread = new Thread() {
            public void run() {
                try {
                    followerForThread.followLeader();
                } catch (InterruptedException e) {
                    LOG.info("Follower thread interrupted", e);
                } catch (Exception e) {
                    LOG.warn("Unexpected exception in follower thread", e);
                }
            }
        };
        followerThread.start();
        Socket leaderSocket = ss.accept();
        
        InputArchive ia = BinaryInputArchive.getArchive(leaderSocket
                .getInputStream());
        OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket
                .getOutputStream());

        conversation.converseWithFollower(ia, oa, follower);
    } finally {
        if (follower != null) {
            follower.shutdown();
        }
        if (followerThread != null) {
            followerThread.interrupt();
            followerThread.join();
        }
        if (peer != null) {
            peer.shutdown();
        }
        recursiveDelete(tmpDir);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:54,代码来源:Zab1_0Test.java


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