gpt4 book ai didi

me.hao0.antares.common.zk.ZkClient.gets()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 21:59:31 30 4
gpt4 key购买 nike

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

ZkClient.gets介绍

[英]Get the children of the path
[中]带孩子们走这条路

代码示例

代码示例来源:origin: ihaolin/antares

private void getServersOnce() {
  List<String> servers = zk.gets(ZkPaths.SERVERS);
  if (servers.isEmpty()){
    log.warn("there are no available servers, please check the environment.");
    return;
  }
  for (String server: servers){
    client.addHttpServer(server);
  }
}

代码示例来源:origin: ihaolin/antares

/**
 * Find the job instance ids of the job
 * @param appName the app name
 * @param jobClass the job class
 * @return the job instance ids
 */
public List<String> findJobInstances(String appName, String jobClass){
  String jobInstancesNode = ZkPaths.pathOfJobInstances(appName, jobClass);
  return zk.client().gets(jobInstancesNode);
}

代码示例来源:origin: ihaolin/antares

/**
 * Check the job has one running job instance
 * @param appName the app name
 * @param jobClass the job class
 * @return return true if has one running job instance, or false
 */
public boolean hasJobInstance(String appName, String jobClass) {
  String jobInstanceNodePath = ZkPaths.pathOfJobInstances(appName, jobClass);
  List<String> instances = zk.client().gets(jobInstanceNodePath);
  return !CollectionUtil.isNullOrEmpty(instances);
}

代码示例来源:origin: ihaolin/antares

public AppClientCluster(AntaresZkClient zk, String appName){
  this.appName = appName;
  this.zk = zk;
  // get alive clients once
  String appClientsPath = ZkPaths.pathOfAppClients(appName);
  zk.client().mkdirs(appClientsPath);
  List<String> clients = zk.client().gets(appClientsPath);
  if (!CollectionUtil.isNullOrEmpty(clients)){
    alives.addAll(clients);
  }
}

代码示例来源:origin: ihaolin/antares

@Override
  public Response<List<String>> listSimpleServers() {
    try {
      List<String> servers = zk.client().gets(ZkPaths.SERVERS);
      if (CollectionUtil.isNullOrEmpty(servers)){
        return Response.ok(Collections.<String>emptyList());
      }
      return Response.ok(servers);
    } catch (Exception e){
      Logs.error("failed to list simple servers, cause: {}", Throwables.getStackTraceAsString(e));
      return Response.notOk("server.list.failed");
    }
  }
}

代码示例来源:origin: ihaolin/antares

@Override
public Response<List<ServerInfo>> listServers() {
  try {
    List<String> servers = zk.client().gets(ZkPaths.SERVERS);
    if (CollectionUtil.isNullOrEmpty(servers)){
      return Response.ok(Collections.<ServerInfo>emptyList());
    }
    String leader = zk.client().getString(ZkPaths.LEADER);
    List<ServerInfo> serverInfos = Lists.newArrayListWithExpectedSize(servers.size());
    ServerInfo serverInfo;
    for (String server: servers){
      serverInfo = new ServerInfo();
      if (Objects.equal(server, leader)){
        serverInfo.setLeader(true);
      }
      serverInfo.setServer(server);
      serverInfo.setJobCount(jobServerDao.countJobsByServer(server).intValue());
      serverInfos.add(serverInfo);
    }
    return Response.ok(serverInfos);
  } catch (Exception e){
    Logs.error("failed to list servers, cause: {}", Throwables.getStackTraceAsString(e));
    return Response.notOk("server.list.failed");
  }
}

代码示例来源:origin: ihaolin/antares

@Override
public Response<List<ClientInfo>> listClients(Long appId) {
  try {
    App app = appDao.findById(appId);
    if (app == null){
      Logs.warn("The app(id={}) doesn't exist when list clients", appId);
      return Response.ok(Collections.<ClientInfo>emptyList());
    }
    String appClientsPath = ZkPaths.pathOfAppClients(app.getAppName());
    zk.client().mkdirs(appClientsPath);
    List<String> clients = zk.client().gets(appClientsPath);
    if(CollectionUtil.isNullOrEmpty(clients)){
      return Response.ok(Collections.<ClientInfo>emptyList());
    }
    List<ClientInfo> clientInfos = Lists.newArrayListWithExpectedSize(clients.size());
    ClientInfo clientInfo;
    for (String client : clients){
      clientInfo = new ClientInfo();
      clientInfo.setAddr(client);
      clientInfos.add(clientInfo);
    }
    return Response.ok(clientInfos);
  } catch (Exception e){
    Logs.error("failed to list clients, cause: {}", Throwables.getStackTraceAsString(e));
    return Response.notOk("client.list.failed");
  }
}

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