org.apache.curator.framework.api.ProtectACLCreateModePathAndBytesable Java Examples

The following examples show how to use org.apache.curator.framework.api.ProtectACLCreateModePathAndBytesable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CuratorManager.java    From Singularity with Apache License 2.0 6 votes vote down vote up
private void privateCreate(String path, Optional<byte[]> data) throws Exception {
  final long start = System.currentTimeMillis();

  try {
    ProtectACLCreateModePathAndBytesable<String> createBuilder = curator
      .create()
      .creatingParentsIfNeeded();

    if (data.isPresent()) {
      createBuilder.forPath(path, data.get());
    } else {
      createBuilder.forPath(path);
    }
  } finally {
    log(
      OperationType.WRITE,
      Optional.empty(),
      Optional.of(data.orElse(EMPTY_BYTES).length),
      start,
      path
    );
  }
}
 
Example #2
Source File: TransactionalStateZkStorage.java    From jstorm with Apache License 2.0 6 votes vote down vote up
protected void createNode(CuratorFramework curator, String path,
                          byte[] data, List<ACL> acls, CreateMode mode) throws Exception {
    ProtectACLCreateModePathAndBytesable<String> builder =
            curator.create().creatingParentsIfNeeded();

    if (acls == null) {
        if (mode == null) {
            forPath(builder, path, data);
        } else {
            forPath(builder.withMode(mode), path, data);
        }
        return;
    }

    forPath(builder.withACL(acls), path, data);
}
 
Example #3
Source File: ZkState.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void writeBytes(String path, byte[] bytes) {
    try {
        if (_curator.checkExists().forPath(path) == null) {
            CreateBuilder builder = _curator.create();
            ProtectACLCreateModePathAndBytesable<String> createAble = (ProtectACLCreateModePathAndBytesable<String>) builder
                    .creatingParentsIfNeeded();
            createAble.withMode(CreateMode.PERSISTENT).forPath(path, bytes);
        } else {
            _curator.setData().forPath(path, bytes);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: TransactionalState.java    From jstorm with Apache License 2.0 5 votes vote down vote up
protected static void createNode(CuratorFramework curator, String path,
                                 byte[] data, List<ACL> acls, CreateMode mode) throws Exception {
    ProtectACLCreateModePathAndBytesable<String> builder = curator.create().creatingParentsIfNeeded();
    if (acls == null) {
        if (mode == null) {
            TransactionalState.forPath(builder, path, data);
        } else {
            TransactionalState.forPath(builder.withMode(mode), path, data);
        }
        return;
    }
    TransactionalState.forPath(builder.withACL(acls), path, data);
}
 
Example #5
Source File: MockCurator.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded() {
    createParents = true;
    return this;
}
 
Example #6
Source File: MockCurator.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded() {
    // TODO: Add proper support for container nodes, see https://issues.apache.org/jira/browse/ZOOKEEPER-2163.
    return creatingParentsIfNeeded();
}