gpt4 book ai didi

me.hao0.antares.common.util.ZkPaths.pathOfAppClients()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 20:09:31 29 4
gpt4 key购买 nike

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

ZkPaths.pathOfAppClients介绍

[英]Get the dir of the alive client
[中]获取活动客户端的目录

代码示例

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

@Override
public void doStart() {
  // listen app's clients change
  watcher = zk.client().newChildWatcher(ZkPaths.pathOfAppClients(appName), new ChildListener() {
    @Override
    protected void onAdd(String path, byte[] data) {
      // not started, or has shutdown
      // prevent multiple redundant notifies before started
      if (!started || shutdowned) {
        return;
      }
      String client = ZkPaths.lastNode(path);
      if (alives.contains(client)){
        return;
      }
      alives.add(client);
      onClientChanged(appName, client, true);
      Logs.info("The app({})'s client({}) joined.", appName, client);
    }
    @Override
    protected void onDelete(String path) {
      String client = ZkPaths.lastNode(path);
      alives.remove(client);
      onClientChanged(appName, client, false);
      Logs.info("The app({})'s client({}) left.", appName, client);
    }
  });
}

代码示例来源: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 void doStart(){
  // mk app clients path
  zk.mkdirs(ZkPaths.pathOfAppClients(client.getAppName()));
  // register client self
  clientRegister = new ClientRegister(client);
  clientRegister.start();
  // get servers once
  getServersOnce();
  // listen servers
  listenOnServerChanged();
}

代码示例来源: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");
  }
}

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