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


Java CreateMode.PERSISTENT属性代码示例

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


在下文中一共展示了CreateMode.PERSISTENT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:22,代码来源:CreateModeTest.java

示例2: createNode

/**
 * 创建节点
 *
 * @param path
 * @param data
 * @param mode
 * @return
 */
public boolean createNode(String path, String data, CreateMode mode) {
    if (!ObjectUtils.allNotNull(zkClient, path)) {
        return Boolean.FALSE;
    }
    try {
        Stat stat = exists(path);
        if (stat == null) {
            mode = mode == null ? CreateMode.PERSISTENT : mode;
            String opResult;
            if (ObjectUtils.allNotNull(data)) {
                opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path, data.getBytes(Charsets.UTF_8));
            } else {
                opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path);
            }
            return Objects.equal(opResult, path);
        }
        return Boolean.TRUE;
    } catch (Exception e) {
        log.error("create node fail! path: {}, error: {}", path, e);
    }
    return Boolean.FALSE;
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:30,代码来源:ZkUtils.java

示例3: 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;
}
 
开发者ID:baloise,项目名称:eZooKeeper,代码行数:29,代码来源:ZnodeModelSource.java

示例4: mknod

private void mknod(String path, CreateMode mode) throws KeeperException, InterruptedException {
    String subpath[] = path.split("/");
    StringBuilder sb = new StringBuilder();
    // We start at 1 because / will create an empty part first
    for(int i = 1; i < subpath.length; i++) {
        sb.append("/");
        sb.append(subpath[i]);
        CreateMode m = CreateMode.PERSISTENT;
        if (i == subpath.length-1) {
            m = mode;
        }
        mknod_inner(sb.toString(), m);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:InstanceContainer.java

示例5: 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());
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:32,代码来源:CreateModeTest.java

示例6: bind

@Override
public void bind(String path,
    ServiceRecord record,
    int flags) throws IOException {
  Preconditions.checkArgument(record != null, "null record");
  validatePath(path);
  // validate the record before putting it
  RegistryTypeUtils.validateServiceRecord(path, record);
  LOG.info("Bound at {} : {}", path, record);

  CreateMode mode = CreateMode.PERSISTENT;
  byte[] bytes = serviceRecordMarshal.toBytes(record);
  zkSet(path, mode, bytes, getClientAcls(),
      ((flags & BindFlags.OVERWRITE) != 0));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:RegistryOperationsService.java

示例7: 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();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:55,代码来源:ZNodeResource.java

示例8: createZNodeAsOctet

@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response createZNodeAsOctet(@PathParam("path") String path,
        @DefaultValue("create") @QueryParam("op") String op,
        @QueryParam("name") String name,
        @DefaultValue("false") @QueryParam("null") String setNull,
        @DefaultValue("false") @QueryParam("sequence") String sequence,
        @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")) {
        createMode = CreateMode.PERSISTENT_SEQUENTIAL;
    } else {
        createMode = CreateMode.PERSISTENT;
    }

    String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);

    URI uri = ui.getAbsolutePathBuilder().path(newPath).build();

    return Response.created(uri).entity(
            new ZPath(newPath, ui.getAbsolutePath().toString())).build();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:43,代码来源:ZNodeResource.java


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