gpt4 book ai didi

org.apache.helix.manager.zk.ZkClient.getChildren()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 10:54:49 26 4
gpt4 key购买 nike

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

ZkClient.getChildren介绍

暂无

代码示例

代码示例来源:origin: org.apache.helix/helix-core

/**
 * sync getChildNames
 * @return null if parentPath doesn't exist
 */
@Override
public List<String> getChildNames(String parentPath, int options) {
 try {
  List<String> childNames = _zkClient.getChildren(parentPath);
  Collections.sort(childNames);
  return childNames;
 } catch (ZkNoNodeException e) {
  return null;
 }
}

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

public static List<String> getInstancePropertyList(ZkClient zkClient, String clusterName,
   String instanceName, PropertyType property, String key) {
  String propertyPath = PropertyPathBuilder.instanceProperty(clusterName, instanceName, property, key);
  return zkClient.getChildren(propertyPath);
 }
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<String> getClusters() {
 List<String> zkToplevelPathes = _zkClient.getChildren("/");
 List<String> result = new ArrayList<String>();
 for (String pathName : zkToplevelPathes) {
  if (ZKUtil.isClusterSetup(pathName, _zkClient)) {
   result.add(pathName);
  }
 }
 return result;
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<String> getInstancesInCluster(String clusterName) {
 String memberInstancesPath = PropertyPathBuilder.instance(clusterName);
 return _zkClient.getChildren(memberInstancesPath);
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<String> getResourcesInCluster(String clusterName) {
 return _zkClient.getChildren(PropertyPathBuilder.idealState(clusterName));
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<String> getStateModelDefs(String clusterName) {
 return _zkClient.getChildren(PropertyPathBuilder.stateModelDef(clusterName));
}

代码示例来源:origin: org.apache.helix/helix-core

public void download(String zkPath, String fsPath) throws Exception {

  List<String> children = client.getChildren(zkPath);
  if (children != null && children.size() > 0) {
   new File(fsPath).mkdirs();
   for (String child : children) {
    String childPath = zkPath.equals("/") ? "/" + child : zkPath + "/" + child;
    download(childPath, fsPath + "/" + child);
   }
  } else {
   System.out
     .println("Saving " + zkPath + " to " + new File(fsPath + suffix).getCanonicalPath());
   OutputStream out = new FileOutputStream(fsPath + suffix);
   Object readData = client.readData(zkPath);
   if (readData != null) {
    out.write((byte[]) readData);
   }
   out.close();
  }
 }
}

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

public List<String> getChildren(final String path) {
 List<String> children = super.getChildren(path);
 for (String p : _dataMap.keySet()) {
  if (p.contains(path)) {
   String[] paths = p.split("/");
   children.add(paths[paths.length-1]);
  }
 }
 return children;
}

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

public static String getInstancePropertyNameListAsString(ZkClient zkClient, String clusterName,
  String instanceName, PropertyType instanceProperty, String key, MediaType mediaType)
  throws JsonGenerationException, JsonMappingException, IOException {
 String path = PropertyPathBuilder.instanceProperty(clusterName, instanceName, instanceProperty, key);
 if (zkClient.exists(path)) {
  List<String> recordNames = zkClient.getChildren(path);
  return ObjectToJson(recordNames);
 }
 return ObjectToJson(new ArrayList<String>());
}

代码示例来源:origin: org.apache.helix/helix-core

String fromPath = concatenate(srcRootPath, path);
List<String> children = srcClient.getChildren(fromPath);
List<String> paths = new ArrayList<String>();
if (children != null && children.size() > 0) {

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

private ZNRecord readZkChild(String zkPath, ZkClient zkClient) {
 ZNRecord result = null;
 // read data and stat
 Stat stat = new Stat();
 ZNRecord data = zkClient.readDataAndStat(zkPath, stat, true);
 if (data != null) {
  result = data;
 } else {
  result = new ZNRecord("");
 }
 // read childrenList
 List<String> children = zkClient.getChildren(zkPath);
 if (children != null && children.size() > 0) {
  result.setSimpleField("numChildren", "" + children.size());
  result.setListField("childrenList", children);
 } else {
  result.setSimpleField("numChildren", "" + 0);
 }
 return result;
}

代码示例来源:origin: org.apache.helix/helix-core

public static List<ZNRecord> getChildren(ZkClient client, String path) {
 // parent watch will be set by zkClient
 List<String> children = client.getChildren(path);
 if (children == null || children.size() == 0) {
  return Collections.emptyList();
 }
 List<ZNRecord> childRecords = new ArrayList<ZNRecord>();
 for (String child : children) {
  String childPath = path + "/" + child;
  Stat newStat = new Stat();
  ZNRecord record = client.readDataAndStat(childPath, newStat, true);
  if (record != null) {
   record.setVersion(newStat.getVersion());
   record.setCreationTime(newStat.getCtime());
   record.setModifiedTime(newStat.getMtime());
   childRecords.add(record);
  }
 }
 return childRecords;
}

代码示例来源:origin: org.apache.helix/helix-core

public boolean verifyByCallback(long timeout, List<ClusterVerifyTrigger> triggers) {
 _countdown = new CountDownLatch(1);
 for (ClusterVerifyTrigger trigger : triggers) {
  String path = trigger._triggerKey.getPath();
  _zkclient.subscribeChildChanges(path, this);
  if (trigger._triggerOnChildDataChange) {
   List<String> childs = _zkclient.getChildren(path);
   for (String child : childs) {
    String childPath = String.format("%s/%s", path, child);
    _zkclient.subscribeDataChanges(childPath, this);
   }
  }
 }
 boolean success = false;
 try {
  success = verify();
  if (!success) {
   success = _countdown.await(timeout, TimeUnit.MILLISECONDS);
   if (!success) {
    // make a final try if timeout
    success = verify();
   }
  }
 } catch (Exception e) {
  LOG.error("Exception in verifier", e);
 }
 // clean up
 _zkclient.unsubscribeAll();
 return success;
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<String> getInstancesInClusterWithTag(String clusterName, String tag) {
 String memberInstancesPath = PropertyPathBuilder.instance(clusterName);
 List<String> instances = _zkClient.getChildren(memberInstancesPath);
 List<String> result = new ArrayList<String>();
 HelixDataAccessor accessor =
   new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
 Builder keyBuilder = accessor.keyBuilder();
 for (String instanceName : instances) {
  InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  if (config == null) {
   throw new IllegalStateException(String
     .format("Instance %s does not have a config, cluster might be in bad state",
       instanceName));
  }
  if (config.containsTag(tag)) {
   result.add(instanceName);
  }
 }
 return result;
}

代码示例来源:origin: org.apache.helix/helix-core

retKeys = new ArrayList<String>(record.getMapFields().keySet());
} else {
 retKeys = zkClient.getChildren(zkPath);

代码示例来源:origin: org.apache.helix/helix-core

List<String> children = _zkClient.getChildren(path);
for (String child : children) {
 String newPath = path + "/" + child;

代码示例来源:origin: org.apache.helix/helix-core

private void subscribeTrigger(ClusterVerifyTrigger trigger) {
 String path = trigger.getTriggerKey().getPath();
 if (trigger.isTriggerOnDataChange()) {
  _zkClient.subscribeDataChanges(path, this);
 }
 if (trigger.isTriggerOnChildChange()) {
  _zkClient.subscribeChildChanges(path, this);
 }
 if (trigger.isTriggerOnChildDataChange()) {
  List<String> childs = _zkClient.getChildren(path);
  for (String child : childs) {
   String childPath = String.format("%s/%s", path, child);
   _zkClient.subscribeDataChanges(childPath, this);
  }
 }
}

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

@Override
 public Representation delete() {
  String zkPath = getZKPath();
  try {
   ZkClient zkClient =
     (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);

   List<String> childNames = zkClient.getChildren(zkPath);
   if (childNames != null) {
    for (String childName : childNames) {
     String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
     zkClient.deleteRecursively(childPath);
    }
   }

   getResponse().setStatus(Status.SUCCESS_OK);
  } catch (Exception e) {
   getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
     MediaType.APPLICATION_JSON);
   getResponse().setStatus(Status.SUCCESS_OK);
   LOG.error("Error in delete zkChild: " + zkPath, e);
  }
  return null;
 }
}

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

private ZNRecord readZkDataStatAndChild(String zkPath, ZkClient zkClient) {
 ZNRecord result = null;
 // read data and stat
 Stat stat = new Stat();
 ZNRecord data = zkClient.readDataAndStat(zkPath, stat, true);
 if (data != null) {
  result = data;
 } else {
  result = new ZNRecord("");
 }
 result.setSimpleField("zkPath", zkPath);
 result.setSimpleField("stat", stat.toString());
 result.setSimpleField("numChildren", "" + stat.getNumChildren());
 result.setSimpleField("ctime", "" + new Date(stat.getCtime()));
 result.setSimpleField("mtime", "" + new Date(stat.getMtime()));
 result.setSimpleField("dataLength", "" + stat.getDataLength());
 // read childrenList
 List<String> children = zkClient.getChildren(zkPath);
 if (children != null && children.size() > 0) {
  result.setListField("children", children);
 }
 return result;
}

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

@Override
public Representation post(Representation entity) {
 String zkPath = getZKPath();
 try {
  JsonParameters jsonParameters = new JsonParameters(entity);
  String command = jsonParameters.getCommand();
  ZkClient zkClient =
    (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
  if (command.equalsIgnoreCase(JsonParameters.ZK_DELETE_CHILDREN)) {
   List<String> childNames = zkClient.getChildren(zkPath);
   if (childNames != null) {
    for (String childName : childNames) {
     String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
     zkClient.deleteRecursively(childPath);
    }
   }
  } else {
   throw new HelixException("Unsupported command: " + command + ". Should be one of ["
     + JsonParameters.ZK_DELETE_CHILDREN + "]");
  }
  getResponse().setStatus(Status.SUCCESS_OK);
 } catch (Exception e) {
  getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
    MediaType.APPLICATION_JSON);
  getResponse().setStatus(Status.SUCCESS_OK);
  LOG.error("Error in post zkPath: " + zkPath, e);
 }
 return null;
}

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