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


Java CreateRequest.serialize方法代码示例

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


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

示例1: sendWriteRequest

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
public void sendWriteRequest() throws Exception {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createReq = new CreateRequest(
        "/session" + Long.toHexString(sessionId) + "-" + (++nodeId),
        new byte[0], Ids.OPEN_ACL_UNSAFE, 1);
    createReq.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    Request req = new Request(null, sessionId, ++cxid, OpCode.create,
                              bb, new ArrayList<Id>());
    zks.getFirstProcessor().processRequest(req);

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:14,代码来源:CommitProcessorTest.java

示例2: makeCreateRequest

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
private Request makeCreateRequest(String path, long sessionId) throws IOException {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createRequest = new CreateRequest(path,
            "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    return new Request(null, sessionId, 1, ZooDefs.OpCode.create2, bb, new ArrayList<Id>());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:10,代码来源:MultiOpSessionUpgradeTest.java

示例3: testCreateEphemeral

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * When we create ephemeral node, we need to check against global
 * session, so the leader never accept request from an expired session
 * (that we no longer track)
 *
 * This is not the same as SessionInvalidationTest since session
 * is not in closing state
 */
public void testCreateEphemeral(boolean localSessionEnabled) throws Exception {
    if (localSessionEnabled) {
        qu.enableLocalSession(true);
    }
    qu.startAll();
    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));

    CreateRequest createRequest = new CreateRequest("/impossible",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long fakeSessionId = (sid << 56) + 1;

    LOG.info("Fake session Id: " + Long.toHexString(fakeSessionId));

    Request request = new Request(null, fakeSessionId, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/impossible", null);
    Assert.assertEquals("Node from fake session get created", null, stat);

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:46,代码来源:LeaderSessionTrackerTest.java

示例4: testCreatePersistent

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * When local session is enabled, leader will allow persistent node
 * to be create for unknown session
 */
@Test
public void testCreatePersistent() throws Exception {
    qu.enableLocalSession(true);
    qu.startAll();

    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));

    CreateRequest createRequest = new CreateRequest("/success",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long locallSession = (sid << 56) + 1;

    LOG.info("Local session Id: " + Long.toHexString(locallSession));

    Request request = new Request(null, locallSession, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/success", null);
    Assert.assertTrue("Request from local sesson failed", stat != null);

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:42,代码来源:LeaderSessionTrackerTest.java

示例5: sendWriteRequest

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
public void sendWriteRequest() throws Exception {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createReq = new CreateRequest(
        "/session" + Long.toHexString(sessionId) + "-" + (++nodeId),
        new byte[0], Ids.OPEN_ACL_UNSAFE, 1);
    createReq.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    Request req = new Request(null, sessionId, ++cxid, OpCode.create,
                              bb, new ArrayList<Id>());
    zks.firstProcessor.processRequest(req);
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:13,代码来源:CommitProcessorTest.java

示例6: testCreatePersistent

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * When local session is enabled, leader will allow persistent node
 * to be create for unknown session
 */
@Test
public void testCreatePersistent() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.enableLocalSession(true);
    qu.startAll();

    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader),
            CONNECTION_TIMEOUT, this);

    CreateRequest createRequest = new CreateRequest("/success",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long locallSession = (sid << 56) + 1;

    LOG.info("Local session Id: " + Long.toHexString(locallSession));

    Request request = new Request(null, locallSession, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/success", null);
    Assert.assertTrue("Request from local sesson failed", stat != null);

}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:44,代码来源:LeaderSessionTrackerTest.java

示例7: testCreateAfterCloseShouldFail

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * Test solution for ZOOKEEPER-1208. Verify that operations are not
 * accepted after a close session.
 * 
 * We're using our own marshalling here in order to force an operation
 * after the session is closed (ZooKeeper.class will not allow this). Also
 * by filling the pipe with operations it increases the likelyhood that
 * the server will process the create before FinalRequestProcessor
 * removes the session from the tracker.
 */
@Test
public void testCreateAfterCloseShouldFail() throws Exception {
    for (int i = 0; i < 10; i++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);

        // open a connection
        boa.writeInt(44, "len");
        ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]);
        conReq.serialize(boa, "connect");

        // close connection
        boa.writeInt(8, "len");
        RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession);
        h.serialize(boa, "header");

        // create ephemeral znode
        boa.writeInt(52, "len"); // We'll fill this in later
        RequestHeader header = new RequestHeader(2, OpCode.create);
        header.serialize(boa, "header");
        CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0],
                Ids.OPEN_ACL_UNSAFE, 1);
        createReq.serialize(boa, "request");
        baos.close();
        
        System.out.println("Length:" + baos.toByteArray().length);
        
        String hp[] = hostPort.split(":");
        Socket sock = new Socket(hp[0], Integer.parseInt(hp[1]));
        InputStream resultStream = null;
        try {
            OutputStream outstream = sock.getOutputStream();
            byte[] data = baos.toByteArray();
            outstream.write(data);
            outstream.flush();
            
            resultStream = sock.getInputStream();
            byte[] b = new byte[10000];
            int len;
            while ((len = resultStream.read(b)) >= 0) {
                // got results
                System.out.println("gotlen:" + len);
            }
        } finally {
            if (resultStream != null) {
                resultStream.close();
            }
            sock.close();
        }
    }
    
    ZooKeeper zk = createClient();
    Assert.assertEquals(1, zk.getChildren("/", false).size());

    zk.close();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:67,代码来源:SessionInvalidationTest.java

示例8: testCreateEphemeral

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * When we create ephemeral node, we need to check against global
 * session, so the leader never accept request from an expired session
 * (that we no longer track)
 *
 * This is not the same as SessionInvalidationTest since session
 * is not in closing state
 */
public void testCreateEphemeral(boolean localSessionEnabled) throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    if (localSessionEnabled) {
        qu.enableLocalSession(true);
    }
    qu.startAll();

    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = new ZooKeeper(qu.getConnectString(leader),
            CONNECTION_TIMEOUT, this);

    CreateRequest createRequest = new CreateRequest("/impossible",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long fakeSessionId = (sid << 56) + 1;

    LOG.info("Fake session Id: " + Long.toHexString(fakeSessionId));

    Request request = new Request(null, fakeSessionId, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/impossible", null);
    Assert.assertEquals("Node from fake session get created", null, stat);

}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:49,代码来源:LeaderSessionTrackerTest.java

示例9: testCreateAfterCloseShouldFail

import org.apache.zookeeper.proto.CreateRequest; //导入方法依赖的package包/类
/**
 * Test solution for ZOOKEEPER-1208. Verify that operations are not
 * accepted after a close session.
 * 
 * We're using our own marshalling here in order to force an operation
 * after the session is closed (ZooKeeper.class will not allow this). Also
 * by filling the pipe with operations it increases the likelyhood that
 * the server will process the create before FinalRequestProcessor
 * removes the session from the tracker.
 */
public void testCreateAfterCloseShouldFail() throws Exception {
    for (int i = 0; i < 10; i++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);

        // open a connection
        boa.writeInt(44, "len");
        ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]);
        conReq.serialize(boa, "connect");

        // close connection
        boa.writeInt(8, "len");
        RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession);
        h.serialize(boa, "header");

        // create ephemeral znode
        boa.writeInt(52, "len"); // We'll fill this in later
        RequestHeader header = new RequestHeader(2, OpCode.create);
        header.serialize(boa, "header");
        CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0],
                Ids.OPEN_ACL_UNSAFE, 1);
        createReq.serialize(boa, "request");
        baos.close();
        
        System.out.println("Length:" + baos.toByteArray().length);
        
        String hp[] = hostPort.split(":");
        Socket sock = new Socket(hp[0], Integer.parseInt(hp[1]));
        InputStream resultStream = null;
        try {
            OutputStream outstream = sock.getOutputStream();
            byte[] data = baos.toByteArray();
            outstream.write(data);
            outstream.flush();
            
            resultStream = sock.getInputStream();
            byte[] b = new byte[10000];
            int len;
            while ((len = resultStream.read(b)) >= 0) {
                // got results
                System.out.println("gotlen:" + len);
            }
        } finally {
            if (resultStream != null) {
                resultStream.close();
            }
            sock.close();
        }
    }
    
    ZooKeeper zk = createClient();
    assertEquals(1, zk.getChildren("/", false).size());

    zk.close();
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:66,代码来源:SessionInvalidationTest.java


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