本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}