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


Java DataTree.serialize方法代码示例

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


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

示例1: serializeSnapshot

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
public static void serializeSnapshot(DataTree dt,OutputArchive oa,
        Map<Long, Integer> sessions) throws IOException {
    HashMap<Long, Integer> sessSnap = new HashMap<Long, Integer>(sessions);
    oa.writeInt(sessSnap.size(), "count");
    for (Entry<Long, Integer> entry : sessSnap.entrySet()) {
        oa.writeLong(entry.getKey().longValue(), "id");
        oa.writeInt(entry.getValue().intValue(), "timeout");
    }
    dt.serialize(oa, "tree");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:11,代码来源:SerializeUtils.java

示例2: testPathTrieClearOnDeserialize

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

示例3: testPathTrieClearOnDeserialize

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

示例4: testSerializeDoesntLockDataNodeWhileWriting

import org.apache.zookeeper.server.DataTree; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSerializeDoesntLockDataNodeWhileWriting() throws Exception {
    DataTree tree = new DataTree();
    tree.createNode("/marker", new byte[] {42}, null, -1, 1, 1, 1);
    final DataNode markerNode = tree.getNode("/marker");
    final AtomicBoolean ranTestCase = new AtomicBoolean();
    DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream());
    BinaryOutputArchive oa = new BinaryOutputArchive(out) {
        @Override
        public void writeRecord(Record r, String tag) throws IOException {
            DataNode node = (DataNode) r;
            if (node.data.length == 1 && node.data[0] == 42) {
                final Semaphore semaphore = new Semaphore(0);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (markerNode) {
                            //When we lock markerNode, allow writeRecord to continue
                            semaphore.release();
                        }
                    }
                }).start();

                try {
                    boolean acquired = semaphore.tryAcquire(30, TimeUnit.SECONDS);
                    //This is the real assertion - could another thread lock
                    //the DataNode we're currently writing
                    Assert.assertTrue("Couldn't acquire a lock on the DataNode while we were calling tree.serialize", acquired);
                } catch (InterruptedException e1) {
                    throw new RuntimeException(e1);
                }
                ranTestCase.set(true);
            }
            super.writeRecord(r, tag);
        }
    };

    tree.serialize(oa, "test");

    //Let's make sure that we hit the code that ran the real assertion above
    Assert.assertTrue("Didn't find the expected node", ranTestCase.get());
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:43,代码来源:DataTreeTest.java


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