com.github.zkclient.ZkClient.exists()方法的使用及代码示例

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

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

ZkClient.exists介绍

暂无

代码示例

代码示例来源:origin: adyliu/jafka

  1. public static void makeSurePersistentPathExists(ZkClient zkClient, String path) {
  2. if (!zkClient.exists(path)) {
  3. zkClient.createPersistent(path, true);
  4. }
  5. }

代码示例来源:origin: com.github.adyliu/zkclient

  1. @Override
  2. public List<String> call() throws Exception {
  3. exists(path, true);
  4. try {
  5. return getChildren(path, true);
  6. } catch (ZkNoNodeException e) {
  7. // ignore, the "exists" watch will listen for the parent node to appear
  8. }
  9. return null;
  10. }
  11. });

代码示例来源:origin: adyliu/zkclient

  1. @Override
  2. public List<String> call() throws Exception {
  3. exists(path, true);
  4. try {
  5. return getChildren(path, true);
  6. } catch (ZkNoNodeException e) {
  7. // ignore, the "exists" watch will listen for the parent node to appear
  8. }
  9. return null;
  10. }
  11. });

代码示例来源:origin: adyliu/zkclient

  1. public boolean exists(final String path) {
  2. return exists(path, hasListeners(path));
  3. }

代码示例来源:origin: com.github.adyliu/zkclient

  1. public boolean exists(final String path) {
  2. return exists(path, hasListeners(path));
  3. }

代码示例来源:origin: com.github.adyliu/zkclient

  1. @Override
  2. public void run() throws Exception {
  3. // reinstall watch
  4. exists(path, true);
  5. try {
  6. byte[] data = readData(path, null, true);
  7. listener.handleDataChange(path, data);
  8. } catch (ZkNoNodeException e) {
  9. listener.handleDataDeleted(path);
  10. }
  11. }
  12. });

代码示例来源:origin: adyliu/zkclient

  1. @Override
  2. public void run() throws Exception {
  3. // reinstall watch
  4. exists(path, true);
  5. try {
  6. byte[] data = readData(path, null, true);
  7. listener.handleDataChange(path, data);
  8. } catch (ZkNoNodeException e) {
  9. listener.handleDataDeleted(path);
  10. }
  11. }
  12. });

代码示例来源:origin: com.github.adyliu/zkclient

  1. @Override
  2. public void run() throws Exception {
  3. try {
  4. // if the node doesn't exist we should listen for the root node to reappear
  5. exists(path);
  6. List<String> children = getChildren(path);
  7. listener.handleChildChange(path, children);
  8. } catch (ZkNoNodeException e) {
  9. listener.handleChildChange(path, null);
  10. }
  11. }
  12. });

代码示例来源:origin: com.github.adyliu/zkclient

  1. public boolean waitUntilExists(String path, TimeUnit timeUnit, long time) throws ZkInterruptedException {
  2. Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
  3. LOG.debug("Waiting until znode '" + path + "' becomes available.");
  4. if (exists(path)) {
  5. return true;
  6. }
  7. acquireEventLock();
  8. try {
  9. while (!exists(path, true)) {
  10. boolean gotSignal = getEventLock().getZNodeEventCondition().awaitUntil(timeout);
  11. if (!gotSignal) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. } catch (InterruptedException e) {
  17. throw new ZkInterruptedException(e);
  18. } finally {
  19. getEventLock().unlock();
  20. }
  21. }

代码示例来源:origin: adyliu/zkclient

  1. @Override
  2. public void run() throws Exception {
  3. try {
  4. // if the node doesn't exist we should listen for the root node to reappear
  5. exists(path);
  6. List<String> children = getChildren(path);
  7. listener.handleChildChange(path, children);
  8. } catch (ZkNoNodeException e) {
  9. listener.handleChildChange(path, null);
  10. }
  11. }
  12. });

代码示例来源:origin: adyliu/zkclient

  1. public boolean waitUntilExists(String path, TimeUnit timeUnit, long time) throws ZkInterruptedException {
  2. Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
  3. LOG.debug("Waiting until znode '" + path + "' becomes available.");
  4. if (exists(path)) {
  5. return true;
  6. }
  7. acquireEventLock();
  8. try {
  9. while (!exists(path, true)) {
  10. boolean gotSignal = getEventLock().getZNodeEventCondition().awaitUntil(timeout);
  11. if (!gotSignal) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. } catch (InterruptedException e) {
  17. throw new ZkInterruptedException(e);
  18. } finally {
  19. getEventLock().unlock();
  20. }
  21. }

相关文章