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

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

本文整理了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

  1. private Op withRootPrefix(Op op) {
  2. if (null != op.getPath()) {
  3. final String serverPath = prependChroot(op.getPath());
  4. if (!op.getPath().equals(serverPath)) {
  5. return op.withChroot(serverPath);
  6. }
  7. }
  8. return op;
  9. }

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

  1. private Op withRootPrefix(Op op) {
  2. if (null != op.getPath()) {
  3. final String serverPath = prependChroot(op.getPath());
  4. if (!op.getPath().equals(serverPath)) {
  5. return op.withChroot(serverPath);
  6. }
  7. }
  8. return op;
  9. }

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

  1. private void removeWatches(int opCode, String path, Watcher watcher,
  2. WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) {
  3. PathUtils.validatePath(path);
  4. final String clientPath = path;
  5. final String serverPath = prependChroot(clientPath);
  6. WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
  7. watcherType, local, watchManager);
  8. RequestHeader h = new RequestHeader();
  9. h.setType(opCode);
  10. Record request = getRemoveWatchesRequest(opCode, watcherType,
  11. serverPath);
  12. cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
  13. serverPath, ctx, null, wcb);
  14. }

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

  1. /**
  2. * The asynchronous version of delete.
  3. *
  4. * @see #delete(String, int)
  5. */
  6. public void delete(final String path, int version, VoidCallback cb,
  7. Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath;
  12. // maintain semantics even in chroot case
  13. // specifically - root cannot be deleted
  14. // I think this makes sense even in chroot case.
  15. if (clientPath.equals("/")) {
  16. // a bit of a hack, but delete(/) will never succeed and ensures
  17. // that the same semantics are maintained
  18. serverPath = clientPath;
  19. } else {
  20. serverPath = prependChroot(clientPath);
  21. }
  22. RequestHeader h = new RequestHeader();
  23. h.setType(ZooDefs.OpCode.delete);
  24. DeleteRequest request = new DeleteRequest();
  25. request.setPath(serverPath);
  26. request.setVersion(version);
  27. cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
  28. serverPath, ctx, null);
  29. }

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

  1. /**
  2. * The asynchronous version of getACL.
  3. *
  4. * @see #getACL(String, Stat)
  5. */
  6. public void getACL(final String path, Stat stat, ACLCallback cb,
  7. Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.getACL);
  14. GetACLRequest request = new GetACLRequest();
  15. request.setPath(serverPath);
  16. GetACLResponse response = new GetACLResponse();
  17. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  18. clientPath, serverPath, ctx, null);
  19. }

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

  1. /**
  2. * Asynchronous sync. Flushes channel between process and leader.
  3. * @param path
  4. * @param cb a handler for the callback
  5. * @param ctx context to be provided to the callback
  6. * @throws IllegalArgumentException if an invalid path is specified
  7. */
  8. public void sync(final String path, VoidCallback cb, Object ctx){
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.sync);
  14. SyncRequest request = new SyncRequest();
  15. SyncResponse response = new SyncResponse();
  16. request.setPath(serverPath);
  17. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  18. clientPath, serverPath, ctx, null);
  19. }

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

  1. /**
  2. * The asynchronous version of create with ttl.
  3. *
  4. * @see #create(String, byte[], List, CreateMode, Stat, long)
  5. */
  6. public void create(final String path, byte data[], List<ACL> acl,
  7. CreateMode createMode, Create2Callback cb, Object ctx, long ttl)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath, createMode.isSequential());
  11. EphemeralType.validateTTL(createMode, ttl);
  12. final String serverPath = prependChroot(clientPath);
  13. RequestHeader h = new RequestHeader();
  14. setCreateHeader(createMode, h);
  15. ReplyHeader r = new ReplyHeader();
  16. Create2Response response = new Create2Response();
  17. Record record = makeCreateRecord(createMode, serverPath, data, acl, ttl);
  18. cnxn.queuePacket(h, r, record, response, cb, clientPath,
  19. serverPath, ctx, null);
  20. }

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

  1. private void removeWatches(int opCode, String path, Watcher watcher,
  2. WatcherType watcherType, boolean local)
  3. throws InterruptedException, KeeperException {
  4. PathUtils.validatePath(path);
  5. final String clientPath = path;
  6. final String serverPath = prependChroot(clientPath);
  7. WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
  8. watcherType, local, watchManager);
  9. RequestHeader h = new RequestHeader();
  10. h.setType(opCode);
  11. Record request = getRemoveWatchesRequest(opCode, watcherType,
  12. serverPath);
  13. ReplyHeader r = cnxn.submitRequest(h, request, null, null, wcb);
  14. if (r.getErr() != 0) {
  15. throw KeeperException.create(KeeperException.Code.get(r.getErr()),
  16. clientPath);
  17. }
  18. }

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

  1. /**
  2. * The asynchronous version of setACL.
  3. *
  4. * @see #setACL(String, List, int)
  5. */
  6. public void setACL(final String path, List<ACL> acl, int version,
  7. StatCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.setACL);
  14. SetACLRequest request = new SetACLRequest();
  15. request.setPath(serverPath);
  16. request.setAcl(acl);
  17. request.setVersion(version);
  18. SetACLResponse response = new SetACLResponse();
  19. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  20. clientPath, serverPath, ctx, null);
  21. }

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

  1. /**
  2. * The asynchronous version of setData.
  3. *
  4. * @see #setData(String, byte[], int)
  5. */
  6. public void setData(final String path, byte data[], int version,
  7. StatCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.setData);
  14. SetDataRequest request = new SetDataRequest();
  15. request.setPath(serverPath);
  16. request.setData(data);
  17. request.setVersion(version);
  18. SetDataResponse response = new SetDataResponse();
  19. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  20. clientPath, serverPath, ctx, null);
  21. }

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

  1. /**
  2. * The asynchronous version of getACL.
  3. *
  4. * @see #getACL(String, Stat)
  5. */
  6. public void getACL(final String path, Stat stat, ACLCallback cb,
  7. Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.getACL);
  14. GetACLRequest request = new GetACLRequest();
  15. request.setPath(serverPath);
  16. GetACLResponse response = new GetACLResponse();
  17. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  18. clientPath, serverPath, ctx, null);
  19. }

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

  1. /**
  2. * Asynchronous sync. Flushes channel between process and leader.
  3. * @param path
  4. * @param cb a handler for the callback
  5. * @param ctx context to be provided to the callback
  6. * @throws IllegalArgumentException if an invalid path is specified
  7. */
  8. public void sync(final String path, VoidCallback cb, Object ctx){
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. final String serverPath = prependChroot(clientPath);
  12. RequestHeader h = new RequestHeader();
  13. h.setType(ZooDefs.OpCode.sync);
  14. SyncRequest request = new SyncRequest();
  15. SyncResponse response = new SyncResponse();
  16. request.setPath(serverPath);
  17. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  18. clientPath, serverPath, ctx, null);
  19. }

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

  1. /**
  2. * The asynchronous version of getChildren.
  3. *
  4. * @see #getChildren(String, Watcher)
  5. */
  6. public void getChildren(final String path, Watcher watcher,
  7. ChildrenCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. // the watch contains the un-chroot path
  12. WatchRegistration wcb = null;
  13. if (watcher != null) {
  14. wcb = new ChildWatchRegistration(watcher, clientPath);
  15. }
  16. final String serverPath = prependChroot(clientPath);
  17. RequestHeader h = new RequestHeader();
  18. h.setType(ZooDefs.OpCode.getChildren);
  19. GetChildrenRequest request = new GetChildrenRequest();
  20. request.setPath(serverPath);
  21. request.setWatch(watcher != null);
  22. GetChildrenResponse response = new GetChildrenResponse();
  23. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  24. clientPath, serverPath, ctx, wcb);
  25. }

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

  1. /**
  2. * The asynchronous version of getData.
  3. *
  4. * @see #getData(String, Watcher, Stat)
  5. */
  6. public void getData(final String path, Watcher watcher,
  7. DataCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. // the watch contains the un-chroot path
  12. WatchRegistration wcb = null;
  13. if (watcher != null) {
  14. wcb = new DataWatchRegistration(watcher, clientPath);
  15. }
  16. final String serverPath = prependChroot(clientPath);
  17. RequestHeader h = new RequestHeader();
  18. h.setType(ZooDefs.OpCode.getData);
  19. GetDataRequest request = new GetDataRequest();
  20. request.setPath(serverPath);
  21. request.setWatch(watcher != null);
  22. GetDataResponse response = new GetDataResponse();
  23. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  24. clientPath, serverPath, ctx, wcb);
  25. }

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

  1. validateACL(acl);
  2. final String serverPath = prependChroot(clientPath);

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

  1. /**
  2. * The asynchronous version of exists.
  3. *
  4. * @see #exists(String, Watcher)
  5. */
  6. public void exists(final String path, Watcher watcher,
  7. StatCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath);
  11. // the watch contains the un-chroot path
  12. WatchRegistration wcb = null;
  13. if (watcher != null) {
  14. wcb = new ExistsWatchRegistration(watcher, clientPath);
  15. }
  16. final String serverPath = prependChroot(clientPath);
  17. RequestHeader h = new RequestHeader();
  18. h.setType(ZooDefs.OpCode.exists);
  19. ExistsRequest request = new ExistsRequest();
  20. request.setPath(serverPath);
  21. request.setWatch(watcher != null);
  22. SetDataResponse response = new SetDataResponse();
  23. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  24. clientPath, serverPath, ctx, wcb);
  25. }

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

  1. /**
  2. * The asynchronous version of getChildren.
  3. *
  4. * @since 3.3.0
  5. *
  6. * @see #getChildren(String, Watcher, Stat)
  7. */
  8. public void getChildren(final String path, Watcher watcher,
  9. Children2Callback cb, Object ctx)
  10. {
  11. final String clientPath = path;
  12. PathUtils.validatePath(clientPath);
  13. // the watch contains the un-chroot path
  14. WatchRegistration wcb = null;
  15. if (watcher != null) {
  16. wcb = new ChildWatchRegistration(watcher, clientPath);
  17. }
  18. final String serverPath = prependChroot(clientPath);
  19. RequestHeader h = new RequestHeader();
  20. h.setType(ZooDefs.OpCode.getChildren2);
  21. GetChildren2Request request = new GetChildren2Request();
  22. request.setPath(serverPath);
  23. request.setWatch(watcher != null);
  24. GetChildren2Response response = new GetChildren2Response();
  25. cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
  26. clientPath, serverPath, ctx, wcb);
  27. }

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

  1. /**
  2. * The asynchronous version of create.
  3. *
  4. * @see #create(String, byte[], List, CreateMode)
  5. */
  6. public void create(final String path, byte data[], List<ACL> acl,
  7. CreateMode createMode, StringCallback cb, Object ctx)
  8. {
  9. final String clientPath = path;
  10. PathUtils.validatePath(clientPath, createMode.isSequential());
  11. EphemeralType.validateTTL(createMode, -1);
  12. final String serverPath = prependChroot(clientPath);
  13. RequestHeader h = new RequestHeader();
  14. h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
  15. CreateRequest request = new CreateRequest();
  16. CreateResponse response = new CreateResponse();
  17. ReplyHeader r = new ReplyHeader();
  18. request.setData(data);
  19. request.setFlags(createMode.toFlag());
  20. request.setPath(serverPath);
  21. request.setAcl(acl);
  22. cnxn.queuePacket(h, r, request, response, cb, clientPath,
  23. serverPath, ctx, null);
  24. }

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

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

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

  1. validateACL(acl);
  2. final String serverPath = prependChroot(clientPath);

相关文章