gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-17 12:24:40 28 4
gpt4 key购买 nike

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

ZkClient.exists介绍

暂无

代码示例

代码示例来源:origin: ltsopensource/light-task-scheduler

public boolean exists(String path) {
  try {
    return zkClient.exists(path);
  } catch (ZkNoNodeException ignored) {
  }
  return false;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public boolean exists(String path) {
  try {
    return zkClient.exists(path);
  } catch (ZkNoNodeException ignored) {
  }
  return false;
}

代码示例来源:origin: killme2008/Metamorphosis

/**
 * Check if the given path exists
 */
public static boolean pathExists(final ZkClient client, final String path) {
  return client.exists(path);
}

代码示例来源:origin: networknt/light-4j

@Override
public boolean exists(String path) {
  return zkClient.exists(path);
}

代码示例来源:origin: apache/incubator-dubbo

public boolean exists(String path) {
  Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
  return client.exists(path);
}

代码示例来源:origin: apache/incubator-dubbo

public boolean exists(String path) {
  Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
  return client.exists(path);
}

代码示例来源:origin: weibocom/motan

private List<String> getChildren(String path) {
  List<String> children = new ArrayList<String>();
  if (zkClient.exists(path)) {
    children = zkClient.getChildren(path);
  }
  return children;
}

代码示例来源:origin: weibocom/motan

private List<String> getChildren(String path) {
    List<String> children = new ArrayList<String>();
    if (zkClient.exists(path)) {
      children = zkClient.getChildren(path);
    }
    return children;
  }
}

代码示例来源:origin: killme2008/Metamorphosis

/**
 * make sure a persiste.nt path exists in ZK. Create the path if not exist.
 */
public static void makeSurePersistentPathExists(final ZkClient client, final String path) throws Exception {
  if (!client.exists(path)) {
    try {
      client.createPersistent(path, true);
    }
    catch (final ZkNodeExistsException e) {
    }
    catch (final Exception e) {
      throw e;
    }
  }
}

代码示例来源:origin: weibocom/motan

private void removeNode(URL url, ZkNodeType nodeType) {
  String nodePath = ZkUtils.toNodePath(url, nodeType);
  if (zkClient.exists(nodePath)) {
    zkClient.delete(nodePath);
  }
}

代码示例来源:origin: weibocom/motan

@Override
protected String discoverCommand(URL url) {
  try {
    String commandPath = ZkUtils.toCommandPath(url);
    String command = "";
    if (zkClient.exists(commandPath)) {
      command = zkClient.readData(commandPath);
    }
    return command;
  } catch (Throwable e) {
    throw new MotanFrameworkException(String.format("Failed to discover command %s from zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()));
  }
}

代码示例来源:origin: weibocom/motan

@Override
protected List<URL> discoverService(URL url) {
  try {
    String parentPath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
    List<String> currentChilds = new ArrayList<>();
    if (zkClient.exists(parentPath)) {
      currentChilds = zkClient.getChildren(parentPath);
    }
    return nodeChildsToUrls(url, parentPath, currentChilds);
  } catch (Throwable e) {
    throw new MotanFrameworkException(String.format("Failed to discover service %s from zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
  }
}

代码示例来源:origin: crossoverJie/cim

/**
 * 创建父级节点
 */
public void createRootNode(){
  boolean exists = zkClient.exists(appConfiguration.getZkRoot());
  if (exists){
    return;
  }
  //创建 root
  zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}

代码示例来源:origin: crossoverJie/cim

/**
 * 创建父级节点
 */
public void createRootNode(){
  boolean exists = zkClient.exists(appConfiguration.getZkRoot());
  if (exists){
    return;
  }
  //创建 root
  zkClient.createPersistent(appConfiguration.getZkRoot()) ;
}

代码示例来源:origin: weibocom/motan

private void createNode(URL url, ZkNodeType nodeType) {
  String nodeTypePath = ZkUtils.toNodeTypePath(url, nodeType);
  if (!zkClient.exists(nodeTypePath)) {
    zkClient.createPersistent(nodeTypePath, true);
  }
  zkClient.createEphemeral(ZkUtils.toNodePath(url, nodeType), url.toFullStr());
}

代码示例来源:origin: weibocom/motan

/**
   * 更新指定group的指令列表
   *
   * @param command
   * @param group
   * @return
   */
  @Override
  public boolean setCommand(String group, RpcCommand command) {
    String path = getCommandPath(group);
    if (!zkClient.exists(path)) {
      zkClient.createPersistent(path, true);
    }
    try {
      zkClient.writeData(path, RpcCommandUtil.commandToString(command));
    } catch (Exception e) {
      return false;
    }
    return true;
  }
}

代码示例来源:origin: apache/incubator-pinot

private void addAndRemoveNewInstanceConfig(ZkClient zkClient)
  throws Exception {
 int biggerRandomNumber = NUM_INSTANCES + new Random().nextInt(NUM_INSTANCES);
 String instanceName = "Server_localhost_" + String.valueOf(biggerRandomNumber);
 String instanceConfigPath = PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
 Assert.assertFalse(zkClient.exists(instanceConfigPath));
 List<String> instances = _helixResourceManager.getAllInstances();
 Assert.assertFalse(instances.contains(instanceName));
 // Add new ZNode.
 ZNRecord znRecord = new ZNRecord(instanceName);
 zkClient.createPersistent(instanceConfigPath, znRecord);
 List<String> latestAllInstances = _helixResourceManager.getAllInstances();
 long maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
 while (!latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
  Thread.sleep(100L);
  latestAllInstances = _helixResourceManager.getAllInstances();
 }
 Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for adding instance config");
 // Remove new ZNode.
 zkClient.delete(instanceConfigPath);
 latestAllInstances = _helixResourceManager.getAllInstances();
 maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
 while (latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) {
  Thread.sleep(100L);
  latestAllInstances = _helixResourceManager.getAllInstances();
 }
 Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for removing instance config");
}

代码示例来源:origin: apache/incubator-pinot

private void modifyExistingInstanceConfig(ZkClient zkClient)
  throws InterruptedException {
 String instanceName = "Server_localhost_" + new Random().nextInt(NUM_INSTANCES);
 String instanceConfigPath = PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
 Assert.assertTrue(zkClient.exists(instanceConfigPath));
 ZNRecord znRecord = zkClient.readData(instanceConfigPath, null);
 InstanceConfig cachedInstanceConfig = _helixResourceManager.getHelixInstanceConfig(instanceName);
 String originalPort = cachedInstanceConfig.getPort();
 Assert.assertNotNull(originalPort);
 String newPort = Long.toString(System.currentTimeMillis());
 Assert.assertTrue(!newPort.equals(originalPort));
 // Set new port to this instance config.
 znRecord.setSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_PORT.toString(), newPort);
 zkClient.writeData(instanceConfigPath, znRecord);
 long maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND;
 InstanceConfig latestCachedInstanceConfig = _helixResourceManager.getHelixInstanceConfig(instanceName);
 String latestPort = latestCachedInstanceConfig.getPort();
 while (!newPort.equals(latestPort) && System.currentTimeMillis() < maxTime) {
  Thread.sleep(100L);
  latestCachedInstanceConfig = _helixResourceManager.getHelixInstanceConfig(instanceName);
  latestPort = latestCachedInstanceConfig.getPort();
 }
 Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for adding instance config");
 // Set original port back to this instance config.
 znRecord.setSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_PORT.toString(), originalPort);
 zkClient.writeData(instanceConfigPath, znRecord);
}

代码示例来源:origin: apache/incubator-pinot

_zkClient = new ZkClient(ZK_SERVER);
final String zkPath = "/" + HELIX_CLUSTER_NAME;
if (_zkClient.exists(zkPath)) {
 _zkClient.deleteRecursive(zkPath);

代码示例来源:origin: javahongxi/whatsmars

public boolean exists(String path) {
  Assert.notNull(client, new IllegalStateException("Zookeeper is not connected yet!"));
  return client.exists(path);
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com