org.apache.zookeeper.ZooKeeper.prependChroot()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中org.apache.zookeeper.ZooKeeper.prependChroot()方法的一些代码示例,展示了ZooKeeper.prependChroot()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeper.prependChroot()方法的具体详情如下:
包路径:org.apache.zookeeper.ZooKeeper
类名称:ZooKeeper
方法名:prependChroot

ZooKeeper.prependChroot介绍

[英]Prepend the chroot to the client path (if present). The expectation of this function is that the client path has been validated before this function is called
[中]将chroot前置到客户端路径(如果存在)。此函数的期望是,在调用此函数之前,客户端路径已经过验证

代码示例

代码示例来源:origin: apache/zookeeper

private Op withRootPrefix(Op op) {
  if (null != op.getPath()) {
    final String serverPath = prependChroot(op.getPath());
    if (!op.getPath().equals(serverPath)) {
      return op.withChroot(serverPath);
    }
  }
  return op;
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

private Op withRootPrefix(Op op) {
  if (null != op.getPath()) {
    final String serverPath = prependChroot(op.getPath());
    if (!op.getPath().equals(serverPath)) {
      return op.withChroot(serverPath);
    }
  }
  return op;
}

代码示例来源:origin: apache/zookeeper

private void removeWatches(int opCode, String path, Watcher watcher,
    WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) {
  PathUtils.validatePath(path);
  final String clientPath = path;
  final String serverPath = prependChroot(clientPath);
  WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
      watcherType, local, watchManager);
  RequestHeader h = new RequestHeader();
  h.setType(opCode);
  Record request = getRemoveWatchesRequest(opCode, watcherType,
      serverPath);
  cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
      serverPath, ctx, null, wcb);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of delete.
 *
 * @see #delete(String, int)
 */
public void delete(final String path, int version, VoidCallback cb,
    Object ctx)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath;
  // maintain semantics even in chroot case
  // specifically - root cannot be deleted
  // I think this makes sense even in chroot case.
  if (clientPath.equals("/")) {
    // a bit of a hack, but delete(/) will never succeed and ensures
    // that the same semantics are maintained
    serverPath = clientPath;
  } else {
    serverPath = prependChroot(clientPath);
  }
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.delete);
  DeleteRequest request = new DeleteRequest();
  request.setPath(serverPath);
  request.setVersion(version);
  cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
      serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of getACL.
 *
 * @see #getACL(String, Stat)
 */
public void getACL(final String path, Stat stat, ACLCallback cb,
    Object ctx)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.getACL);
  GetACLRequest request = new GetACLRequest();
  request.setPath(serverPath);
  GetACLResponse response = new GetACLResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

/**
 * Asynchronous sync. Flushes channel between process and leader.
 * @param path
 * @param cb a handler for the callback
 * @param ctx context to be provided to the callback
 * @throws IllegalArgumentException if an invalid path is specified
 */
public void sync(final String path, VoidCallback cb, Object ctx){
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.sync);
  SyncRequest request = new SyncRequest();
  SyncResponse response = new SyncResponse();
  request.setPath(serverPath);
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of create with ttl.
 *
 * @see #create(String, byte[], List, CreateMode, Stat, long)
 */
public void create(final String path, byte data[], List<ACL> acl,
    CreateMode createMode, Create2Callback cb, Object ctx, long ttl)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath, createMode.isSequential());
  EphemeralType.validateTTL(createMode, ttl);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  setCreateHeader(createMode, h);
  ReplyHeader r = new ReplyHeader();
  Create2Response response = new Create2Response();
  Record record = makeCreateRecord(createMode, serverPath, data, acl, ttl);
  cnxn.queuePacket(h, r, record, response, cb, clientPath,
      serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

private void removeWatches(int opCode, String path, Watcher watcher,
    WatcherType watcherType, boolean local)
    throws InterruptedException, KeeperException {
  PathUtils.validatePath(path);
  final String clientPath = path;
  final String serverPath = prependChroot(clientPath);
  WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
      watcherType, local, watchManager);
  RequestHeader h = new RequestHeader();
  h.setType(opCode);
  Record request = getRemoveWatchesRequest(opCode, watcherType,
      serverPath);
  ReplyHeader r = cnxn.submitRequest(h, request, null, null, wcb);
  if (r.getErr() != 0) {
    throw KeeperException.create(KeeperException.Code.get(r.getErr()),
        clientPath);
  }
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
    StatCallback cb, Object ctx)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.setACL);
  SetACLRequest request = new SetACLRequest();
  request.setPath(serverPath);
  request.setAcl(acl);
  request.setVersion(version);
  SetACLResponse response = new SetACLResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of setData.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
    StatCallback cb, Object ctx)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.setData);
  SetDataRequest request = new SetDataRequest();
  request.setPath(serverPath);
  request.setData(data);
  request.setVersion(version);
  SetDataResponse response = new SetDataResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * The asynchronous version of getACL.
 *
 * @see #getACL(String, Stat)
 */
public void getACL(final String path, Stat stat, ACLCallback cb,
    Object ctx)
{
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.getACL);
  GetACLRequest request = new GetACLRequest();
  request.setPath(serverPath);
  GetACLResponse response = new GetACLResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * Asynchronous sync. Flushes channel between process and leader.
 * @param path
 * @param cb a handler for the callback
 * @param ctx context to be provided to the callback
 * @throws IllegalArgumentException if an invalid path is specified
 */
public void sync(final String path, VoidCallback cb, Object ctx){
  final String clientPath = path;
  PathUtils.validatePath(clientPath);
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.sync);
  SyncRequest request = new SyncRequest();
  SyncResponse response = new SyncResponse();
  request.setPath(serverPath);
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, null);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of getChildren.
 *
 * @see #getChildren(String, Watcher)
 */
public void getChildren(final String path, Watcher watcher,
    ChildrenCallback 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 ChildWatchRegistration(watcher, clientPath);
  }
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.getChildren);
  GetChildrenRequest request = new GetChildrenRequest();
  request.setPath(serverPath);
  request.setWatch(watcher != null);
  GetChildrenResponse response = new GetChildrenResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, wcb);
}

代码示例来源:origin: apache/zookeeper

/**
 * 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);
}

代码示例来源:origin: apache/zookeeper

validateACL(acl);
final String serverPath = prependChroot(clientPath);

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
    StatCallback 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 ExistsWatchRegistration(watcher, clientPath);
  }
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.exists);
  ExistsRequest request = new ExistsRequest();
  request.setPath(serverPath);
  request.setWatch(watcher != null);
  SetDataResponse response = new SetDataResponse();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, wcb);
}

代码示例来源:origin: apache/zookeeper

/**
 * The asynchronous version of getChildren.
 *
 * @since 3.3.0
 * 
 * @see #getChildren(String, Watcher, Stat)
 */
public void getChildren(final String path, Watcher watcher,
    Children2Callback 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 ChildWatchRegistration(watcher, clientPath);
  }
  final String serverPath = prependChroot(clientPath);
  RequestHeader h = new RequestHeader();
  h.setType(ZooDefs.OpCode.getChildren2);
  GetChildren2Request request = new GetChildren2Request();
  request.setPath(serverPath);
  request.setWatch(watcher != null);
  GetChildren2Response response = new GetChildren2Response();
  cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
      clientPath, serverPath, ctx, wcb);
}

代码示例来源:origin: apache/zookeeper

/**
 * 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);
}

代码示例来源:origin: apache/zookeeper

PathUtils.validatePath(clientPath);
final String serverPath = prependChroot(clientPath);

代码示例来源:origin: apache/zookeeper

validateACL(acl);
final String serverPath = prependChroot(clientPath);

相关文章