本文整理汇总了Java中org.apache.zookeeper.proto.GetDataRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetDataRequest类的具体用法?Java GetDataRequest怎么用?Java GetDataRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetDataRequest类属于org.apache.zookeeper.proto包,在下文中一共展示了GetDataRequest类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getData
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* The asynchronous version of getData.
*
* @see #getData(String, Watcher, Stat)
*/
public void getData(final String path, Watcher watcher,
DataCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new DataWatchRegistration(watcher, clientPath);
}
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.getData);
GetDataRequest request = new GetDataRequest();
request.setPath(serverPath);
request.setWatch(watcher != null);
GetDataResponse response = new GetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, wcb);
}
示例2: getConfig
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* The asynchronous version of getConfig.
*
* @see #getConfig(Watcher, Stat)
*/
public void getConfig(Watcher watcher,
DataCallback cb, Object ctx)
{
final String configZnode = ZooDefs.CONFIG_NODE;
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new DataWatchRegistration(watcher, configZnode);
}
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.getData);
GetDataRequest request = new GetDataRequest();
request.setPath(configZnode);
request.setWatch(watcher != null);
GetDataResponse response = new GetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
configZnode, configZnode, ctx, wcb);
}
示例3: getData
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* The Asynchronous version of getData. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #getData(String, Watcher, Stat)
*/
public void getData(final String path, Watcher watcher,
DataCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath);
// the watch contains the un-chroot path
WatchRegistration wcb = null;
if (watcher != null) {
wcb = new DataWatchRegistration(watcher, clientPath);
}
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.getData);
GetDataRequest request = new GetDataRequest();
request.setPath(serverPath);
request.setWatch(watcher != null);
GetDataResponse response = new GetDataResponse();
cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
clientPath, serverPath, ctx, wcb);
}
示例4: sendReadRequest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
public void sendReadRequest() throws Exception {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
GetDataRequest getDataRequest = new GetDataRequest(
"/session" + Long.toHexString(sessionId) + "-" + nodeId, false);
getDataRequest.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
Request req = new Request(null, sessionId, ++cxid, OpCode.getData,
bb, new ArrayList<Id>());
zks.getFirstProcessor().processRequest(req);
}
示例5: poll
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
public Request poll() {
readReqId++;
try {
return newRequest(new GetDataRequest("/", false),
OpCode.getData, readReqId % 50, readReqId);
} catch (IOException e) {
e.printStackTrace();
}
;
return null;
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:12,代码来源:CommitProcessorConcurrencyTest.java
示例6: committedAndUncommittedOfTheSameSessionRaceTest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* We place a read request followed by committed update request of the same
* session in queuedRequests. We verify that both requests are processed,
* according to the order of the session (first read, then the write).
*/
@Test
public void committedAndUncommittedOfTheSameSessionRaceTest()
throws Exception {
final String path = "/testCvsUCRace";
Request readReq = newRequest(new GetDataRequest(path, false),
OpCode.getData, 0x0, 0);
Request writeReq = newRequest(
new SetDataRequest(path, new byte[16], -1), OpCode.setData, 0x0,
1);
processor.committedRequests.add(writeReq);
processor.queuedRequests.add(readReq);
processor.queuedRequests.add(writeReq);
processor.initThreads(1);
processor.stoppedMainLoop = true;
processor.run();
Assert.assertTrue(
"Request was not processed " + readReq + " instead "
+ processedRequests.peek(),
processedRequests.peek() != null
&& processedRequests.peek().equals(readReq));
processedRequests.poll();
Assert.assertTrue(
"Request was not processed " + writeReq + " instead "
+ processedRequests.peek(),
processedRequests.peek() != null
&& processedRequests.peek().equals(writeReq));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:37,代码来源:CommitProcessorConcurrencyTest.java
示例7: makeGetDataRequest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
private Request makeGetDataRequest(String path, long sessionId) throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
GetDataRequest getDataRequest = new GetDataRequest(path, false);
getDataRequest.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
return new Request(null, sessionId, 1, ZooDefs.OpCode.getData, bb, new ArrayList<Id>());
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:9,代码来源:MultiOpSessionUpgradeTest.java
示例8: checkType
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
private EventType checkType(Record response) {
if (response == null) {
return EventType.other;
} else if (response instanceof ConnectRequest) {
return EventType.write;
} else if (response instanceof CreateRequest) {
return EventType.write;
} else if (response instanceof DeleteRequest) {
return EventType.write;
} else if (response instanceof SetDataRequest) {
return EventType.write;
} else if (response instanceof SetACLRequest) {
return EventType.write;
} else if (response instanceof SetMaxChildrenRequest) {
return EventType.write;
} else if (response instanceof SetSASLRequest) {
return EventType.write;
} else if (response instanceof SetWatches) {
return EventType.write;
} else if (response instanceof SyncRequest) {
return EventType.write;
} else if (response instanceof ExistsRequest) {
return EventType.read;
} else if (response instanceof GetDataRequest) {
return EventType.read;
} else if (response instanceof GetMaxChildrenRequest) {
return EventType.read;
} else if (response instanceof GetACLRequest) {
return EventType.read;
} else if (response instanceof GetChildrenRequest) {
return EventType.read;
} else if (response instanceof GetChildren2Request) {
return EventType.read;
} else if (response instanceof GetSASLRequest) {
return EventType.read;
} else {
return EventType.other;
}
}
示例9: sendReadRequest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
public void sendReadRequest() throws Exception {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
GetDataRequest getDataRequest = new GetDataRequest(
"/session" + Long.toHexString(sessionId) + "-" + nodeId, false);
getDataRequest.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
Request req = new Request(null, sessionId, ++cxid, OpCode.getData,
bb, new ArrayList<Id>());
zks.firstProcessor.processRequest(req);
}
示例10: raceTest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
@Test
public void raceTest()
throws Exception {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
GetDataRequest getReq = new GetDataRequest("/testrace", false);
getReq.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
Request readReq = new Request(null, 0x0, 0, OpCode.getData,
bb, new ArrayList<Id>());
boas.reset();
SyncRequest syncReq = new SyncRequest("/testrace");
syncReq.serialize(boa, "request");
bb = ByteBuffer.wrap(boas.toByteArray());
Request writeReq = new Request(null, 0x0, 0, OpCode.sync,
bb, new ArrayList<Id>());
processor.addToCommittedRequests(writeReq);
processor.addToQueuedRequests(readReq);
processor.addToQueuedRequests(writeReq);
processor.testStart();
processor.testProcessCommitted();
Assert.assertFalse("Next request processor executed", executedFlag);
}
示例11: processAllFollowingUncommittedAfterFirstCommitTest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* In the following test, we add a write request followed by several read
* requests of the same session, and we verify several things - 1. The write
* is not processed until commit arrives. 2. Once the write is processed,
* all the read requests are processed as well. 3. All read requests are
* executed after the write, before any other write, along with new reads.
*/
@Test
public void processAllFollowingUncommittedAfterFirstCommitTest()
throws Exception {
final String path = "/testUncommittedFollowingCommited";
Set<Request> shouldBeInPending = new HashSet<Request>();
Set<Request> shouldBeProcessedAfterPending = new HashSet<Request>();
Request writeReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, 0x1, 1);
processor.queuedRequests.add(writeReq);
shouldBeInPending.add(writeReq);
for (int readReqId = 2; readReqId <= 5; ++readReqId) {
Request readReq = newRequest(new GetDataRequest(path, false),
OpCode.getData, 0x1, readReqId);
processor.queuedRequests.add(readReq);
shouldBeInPending.add(readReq);
shouldBeProcessedAfterPending.add(readReq);
}
processor.initThreads(defaultSizeOfThreadPool);
processor.stoppedMainLoop = true;
processor.run();
Assert.assertTrue("Processed without waiting for commit",
processedRequests.isEmpty());
Assert.assertTrue("Did not handled all of queuedRequests' requests",
processor.queuedRequests.isEmpty());
shouldBeInPending
.removeAll(processor.pendingRequests.get(writeReq.sessionId));
for (Request r : shouldBeInPending) {
LOG.error("Should be in pending " + r);
}
Assert.assertTrue(
"Not all requests moved to pending from queuedRequests",
shouldBeInPending.isEmpty());
processor.committedRequests.add(writeReq);
processor.stoppedMainLoop = true;
processor.run();
processor.initThreads(defaultSizeOfThreadPool);
Thread.sleep(500);
Assert.assertTrue("Did not process committed request",
processedRequests.peek() == writeReq);
Assert.assertTrue("Did not process following read request",
processedRequests.containsAll(shouldBeProcessedAfterPending));
Assert.assertTrue("Did not process committed request",
processor.committedRequests.isEmpty());
Assert.assertTrue("Did not process committed request",
processor.pendingRequests.isEmpty());
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:62,代码来源:CommitProcessorConcurrencyTest.java
示例12: noCrashOnCommittedRequestsOfUnseenRequestTest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* In the following test, we verify that we can handle the case that we got a commit
* of a request we never seen since the session that we just established. This can happen
* when a session is just established and there is request waiting to be committed in the
* session queue but it sees a commit for a request that belongs to the previous connection.
*/
@Test(timeout = 5000)
public void noCrashOnCommittedRequestsOfUnseenRequestTest() throws Exception {
final String path = "/noCrash/OnCommittedRequests/OfUnseenRequestTest";
final int numberofReads = 10;
final int sessionid = 0x123456;
final int firstCXid = 0x100;
int readReqId = firstCXid;
processor.stoppedMainLoop = true;
HashSet<Request> localRequests = new HashSet<Request>();
// queue the blocking write request to queuedRequests
Request firstCommittedReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, sessionid, readReqId++);
processor.queuedRequests.add(firstCommittedReq);
localRequests.add(firstCommittedReq);
// queue read requests to queuedRequests
for (; readReqId <= numberofReads+firstCXid; ++readReqId) {
Request readReq = newRequest(new GetDataRequest(path, false),
OpCode.getData, sessionid, readReqId);
processor.queuedRequests.add(readReq);
localRequests.add(readReq);
}
//run once
Assert.assertTrue(processor.queuedRequests.containsAll(localRequests));
processor.initThreads(defaultSizeOfThreadPool);
processor.run();
Thread.sleep(1000);
//We verify that the processor is waiting for the commit
Assert.assertTrue(processedRequests.isEmpty());
// We add a commit that belongs to the same session but with smaller cxid,
// i.e., commit of an update from previous connection of this session.
Request preSessionCommittedReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, sessionid, firstCXid - 2);
processor.committedRequests.add(preSessionCommittedReq);
processor.committedRequests.add(firstCommittedReq);
processor.run();
Thread.sleep(1000);
//We verify that the commit processor processed the old commit prior to the newer messages
Assert.assertTrue(processedRequests.peek() == preSessionCommittedReq);
processor.run();
Thread.sleep(1000);
//We verify that the commit processor handle all messages.
Assert.assertTrue(processedRequests.containsAll(localRequests));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:61,代码来源:CommitProcessorConcurrencyTest.java
示例13: noCrashOnOutofOrderCommittedRequestTest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
/**
* In the following test, we verify if we handle the case in which we get a commit
* for a request that has higher Cxid than the one we are waiting. This can happen
* when a session connection is lost but there is a request waiting to be committed in the
* session queue. However, since the session has moved, new requests can get to
* the leader out of order. Hence, the commits can also arrive "out of order" w.r.t. cxid.
* We should commit the requests according to the order we receive from the leader, i.e., wait for the relevant commit.
*/
@Test(timeout = 5000)
public void noCrashOnOutofOrderCommittedRequestTest() throws Exception {
final String path = "/noCrash/OnCommittedRequests/OfUnSeenRequestTest";
final int sessionid = 0x123456;
final int lastCXid = 0x100;
final int numberofReads = 10;
int readReqId = lastCXid;
processor.stoppedMainLoop = true;
HashSet<Request> localRequests = new HashSet<Request>();
// queue the blocking write request to queuedRequests
Request orphanCommittedReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, sessionid, lastCXid);
processor.queuedRequests.add(orphanCommittedReq);
localRequests.add(orphanCommittedReq);
// queue read requests to queuedRequests
for (; readReqId <= numberofReads+lastCXid; ++readReqId) {
Request readReq = newRequest(new GetDataRequest(path, false),
OpCode.getData, sessionid, readReqId);
processor.queuedRequests.add(readReq);
localRequests.add(readReq);
}
//run once
processor.initThreads(defaultSizeOfThreadPool);
processor.run();
Thread.sleep(1000);
//We verify that the processor is waiting for the commit
Assert.assertTrue(processedRequests.isEmpty());
// We add a commit that belongs to the same session but with larger cxid,
// i.e., commit of an update from the next connection of this session.
Request otherSessionCommittedReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, sessionid, lastCXid+10);
processor.committedRequests.add(otherSessionCommittedReq);
processor.committedRequests.add(orphanCommittedReq);
processor.run();
Thread.sleep(1000);
//We verify that the commit processor processed the old commit prior to the newer messages
Assert.assertTrue(processedRequests.size() == 1);
Assert.assertTrue(processedRequests.contains(otherSessionCommittedReq));
processor.run();
Thread.sleep(1000);
//We verify that the commit processor handle all messages.
Assert.assertTrue(processedRequests.containsAll(localRequests));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:64,代码来源:CommitProcessorConcurrencyTest.java
示例14: IGetDataRequest
import org.apache.zookeeper.proto.GetDataRequest; //导入依赖的package包/类
public IGetDataRequest() {
this(new GetDataRequest());
}