本文整理汇总了Java中org.apache.zookeeper.proto.CreateRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateRequest类的具体用法?Java CreateRequest怎么用?Java CreateRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateRequest类属于org.apache.zookeeper.proto包,在下文中一共展示了CreateRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
/**
* The asynchronous version of create.
*
* @see #create(String, byte[], List, CreateMode)
*/
public void create(final String path, byte data[], List<ACL> acl,
CreateMode createMode, StringCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath, createMode.isSequential());
EphemeralType.validateTTL(createMode, -1);
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
CreateRequest request = new CreateRequest();
CreateResponse response = new CreateResponse();
ReplyHeader r = new ReplyHeader();
request.setData(data);
request.setFlags(createMode.toFlag());
request.setPath(serverPath);
request.setAcl(acl);
cnxn.queuePacket(h, r, request, response, cb, clientPath,
serverPath, ctx, null);
}
示例2: noStarvationOfNonLocalCommittedRequestsTest
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
/**
* In the following test, we verify that committed requests are processed
* even when queuedRequests never gets empty. We add 10 committed request
* and use infinite queuedRequests. We verify that the committed request was
* processed.
*/
@Test(timeout = 1000)
public void noStarvationOfNonLocalCommittedRequestsTest() throws Exception {
final String path = "/noStarvationOfCommittedRequests";
processor.queuedRequests = new MockRequestsQueue();
Set<Request> nonLocalCommits = new HashSet<Request>();
for (int i = 0; i < 10; i++) {
Request nonLocalCommitReq = newRequest(
new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
OpCode.create, 51, i + 1);
processor.committedRequests.add(nonLocalCommitReq);
nonLocalCommits.add(nonLocalCommitReq);
}
for (int i = 0; i < 10; i++) {
processor.initThreads(defaultSizeOfThreadPool);
processor.stoppedMainLoop = true;
processor.run();
}
Assert.assertTrue("commit request was not processed",
processedRequests.containsAll(nonLocalCommits));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:28,代码来源:CommitProcessorConcurrencyTest.java
示例3: create
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
/**
* The Asynchronous version of create. The request doesn't actually until
* the asynchronous callback is called.
*
* @see #create(String, byte[], List, CreateMode)
*/
public void create(final String path, byte data[], List<ACL> acl,
CreateMode createMode, StringCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath, createMode.isSequential());
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.create);
CreateRequest request = new CreateRequest();
CreateResponse response = new CreateResponse();
ReplyHeader r = new ReplyHeader();
request.setData(data);
request.setFlags(createMode.toFlag());
request.setPath(serverPath);
request.setAcl(acl);
cnxn.queuePacket(h, r, request, response, cb, clientPath,
serverPath, ctx, null);
}
示例4: create
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
/**
* The asynchronous version of create.
*
* @see #create(String, byte[], List, CreateMode)
*/
public void create(final String path, byte data[], List<ACL> acl,
CreateMode createMode, StringCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath, createMode.isSequential());
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(ZooDefs.OpCode.create);
CreateRequest request = new CreateRequest();
CreateResponse response = new CreateResponse();
ReplyHeader r = new ReplyHeader();
request.setData(data);
request.setFlags(createMode.toFlag());
request.setPath(serverPath);
request.setAcl(acl);
cnxn.queuePacket(h, r, request, response, cb, clientPath,
serverPath, ctx, null);
}
示例5: create
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
/**
* The asynchronous version of create.
*
* @see #create(String, byte[], List, CreateMode)
*/
public void create(final String path, byte data[], List<ACL> acl,
CreateMode createMode, StringCallback cb, Object ctx)
{
final String clientPath = path;
PathUtils.validatePath(clientPath, createMode.isSequential());
final String serverPath = prependChroot(clientPath);
RequestHeader h = new RequestHeader();
h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
CreateRequest request = new CreateRequest();
CreateResponse response = new CreateResponse();
ReplyHeader r = new ReplyHeader();
request.setData(data);
request.setFlags(createMode.toFlag());
request.setPath(serverPath);
request.setAcl(acl);
cnxn.queuePacket(h, r, request, response, cb, clientPath,
serverPath, ctx, null);
}
示例6: 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);
}
示例7: 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
示例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 {
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
示例9: 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
示例10: checkType
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的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;
}
}
示例11: checkUpgradeSession
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
public Request checkUpgradeSession(Request request)
throws IOException, KeeperException {
// If this is a request for a local session and it is to
// create an ephemeral node, then upgrade the session and return
// a new session request for the leader.
// This is called by the request processor thread (either follower
// or observer request processor), which is unique to a learner.
// So will not be called concurrently by two threads.
if (request.type != OpCode.create ||
!upgradeableSessionTracker.isLocalSession(request.sessionId)) {
return null;
}
CreateRequest createRequest = new CreateRequest();
request.request.rewind();
ByteBufferInputStream.byteBuffer2Record(request.request, createRequest);
request.request.rewind();
CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags());
if (!createMode.isEphemeral()) {
return null;
}
// Uh oh. We need to upgrade before we can proceed.
if (!self.isLocalSessionsUpgradingEnabled()) {
throw new KeeperException.EphemeralOnLocalSessionException();
}
return makeUpgradeRequest(request.sessionId);
}
示例12: 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);
}
示例13: 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);
}
示例14: toRequestRecord
import org.apache.zookeeper.proto.CreateRequest; //导入依赖的package包/类
@Override
public Record toRequestRecord() {
return new CreateRequest(getPath(), data, acl, flags);
}
示例15: 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();
}