本文整理匯總了Java中org.apache.zookeeper.CreateMode.EPHEMERAL_SEQUENTIAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java CreateMode.EPHEMERAL_SEQUENTIAL屬性的具體用法?Java CreateMode.EPHEMERAL_SEQUENTIAL怎麽用?Java CreateMode.EPHEMERAL_SEQUENTIAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.zookeeper.CreateMode
的用法示例。
在下文中一共展示了CreateMode.EPHEMERAL_SEQUENTIAL屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testBasicCreateMode
@Test
public void testBasicCreateMode() {
CreateMode cm = CreateMode.PERSISTENT;
Assert.assertEquals(cm.toFlag(), 0);
Assert.assertFalse(cm.isEphemeral());
Assert.assertFalse(cm.isSequential());
cm = CreateMode.EPHEMERAL;
Assert.assertEquals(cm.toFlag(), 1);
Assert.assertTrue(cm.isEphemeral());
Assert.assertFalse(cm.isSequential());
cm = CreateMode.PERSISTENT_SEQUENTIAL;
Assert.assertEquals(cm.toFlag(), 2);
Assert.assertFalse(cm.isEphemeral());
Assert.assertTrue(cm.isSequential());
cm = CreateMode.EPHEMERAL_SEQUENTIAL;
Assert.assertEquals(cm.toFlag(), 3);
Assert.assertTrue(cm.isEphemeral());
Assert.assertTrue(cm.isSequential());
}
示例2: insertData
@Override
public String insertData(String path, Znode znode) throws DataModelSourceException {
ZooKeeperConnection zooKeeperConnection = getZooKeeperConnection();
CreateMode createMode = CreateMode.PERSISTENT;
if (znode.isEphemeral()) {
createMode = CreateMode.EPHEMERAL;
}
if (znode.isSequential()) {
createMode = CreateMode.PERSISTENT_SEQUENTIAL;
}
if (znode.isEphemeral() && znode.isSequential()) {
createMode = CreateMode.EPHEMERAL_SEQUENTIAL;
}
byte[] data = znode.getData();
List<ACL> acl = znode.getAcl();
try {
zooKeeperConnection.create(path, data, acl, createMode);
}
catch (Exception e) {
throw new DataModelSourceException(e);
}
return path;
}
示例3: testBasicCreateMode
@Test
public void testBasicCreateMode() {
CreateMode cm = CreateMode.PERSISTENT;
Assert.assertEquals(cm.toFlag(), 0);
Assert.assertFalse(cm.isEphemeral());
Assert.assertFalse(cm.isSequential());
Assert.assertFalse(cm.isContainer());
cm = CreateMode.EPHEMERAL;
Assert.assertEquals(cm.toFlag(), 1);
Assert.assertTrue(cm.isEphemeral());
Assert.assertFalse(cm.isSequential());
Assert.assertFalse(cm.isContainer());
cm = CreateMode.PERSISTENT_SEQUENTIAL;
Assert.assertEquals(cm.toFlag(), 2);
Assert.assertFalse(cm.isEphemeral());
Assert.assertTrue(cm.isSequential());
Assert.assertFalse(cm.isContainer());
cm = CreateMode.EPHEMERAL_SEQUENTIAL;
Assert.assertEquals(cm.toFlag(), 3);
Assert.assertTrue(cm.isEphemeral());
Assert.assertTrue(cm.isSequential());
Assert.assertFalse(cm.isContainer());
cm = CreateMode.CONTAINER;
Assert.assertEquals(cm.toFlag(), 4);
Assert.assertFalse(cm.isEphemeral());
Assert.assertFalse(cm.isSequential());
Assert.assertTrue(cm.isContainer());
}
示例4: createZNode
@POST
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response createZNode(
@PathParam("path") String path,
@QueryParam("callback") String callback,
@DefaultValue("create") @QueryParam("op") String op,
@QueryParam("name") String name,
@DefaultValue("base64") @QueryParam("dataformat") String dataformat,
@DefaultValue("false") @QueryParam("null") String setNull,
@DefaultValue("false") @QueryParam("sequence") String sequence,
@DefaultValue("false") @QueryParam("ephemeral") String ephemeral,
@Context UriInfo ui, byte[] data) throws InterruptedException,
KeeperException {
ensurePathNotNull(path);
if (path.equals("/")) {
path += name;
} else {
path += "/" + name;
}
if (!op.equals("create")) {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(
new ZError(ui.getRequestUri().toString(), path
+ " bad operaton " + op)).build());
}
if (setNull.equals("true")) {
data = null;
}
CreateMode createMode;
if (sequence.equals("true")) {
if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT_SEQUENTIAL;
} else {
createMode = CreateMode.EPHEMERAL_SEQUENTIAL;
}
} else if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT;
} else {
createMode = CreateMode.EPHEMERAL;
}
String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
URI uri = ui.getAbsolutePathBuilder().path(newPath).build();
return Response.created(uri).entity(
new JSONWithPadding(new ZPath(newPath, ui.getAbsolutePath()
.toString()))).build();
}