gpt4 book ai didi

com.ke.kob.basic.constant.ZkPathConstant类的使用及代码示例

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

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

ZkPathConstant介绍

暂无

代码示例

代码示例来源:origin: LianjiaTech/kob

@Override
public Map<String, ClientInfo> getClientNodes(String projectCode) {
  String clientNodePath = ZkPathConstant.clientNodePath(cluster, projectCode);
  if (!zkClient.exists(clientNodePath)) {
    return new HashMap<>(0);
  }
  List<String> nodeClientStrList = zkClient.getChildren(clientNodePath);
  Map<String, ClientInfo> projectClientNode = new HashMap<>(10);
  if (!KobUtils.isEmpty(nodeClientStrList)) {
    for (String child : nodeClientStrList) {
      ClientPath clientPath = JSONObject.parseObject(child, ClientPath.class);
      String path = ZkPathConstant.clientNodePath(cluster, projectCode) + ZkPathConstant.BACKSLASH + child;
      String dataStr = zkClient.readData(path, true);
      if (!KobUtils.isEmpty(dataStr)) {
        ClientData clientData = JSONObject.parseObject(dataStr, ClientData.class);
        projectClientNode.put(clientPath.getIdentification(), new ClientInfo(path, clientPath, clientData));
      }
    }
  }
  return projectClientNode;
}

代码示例来源:origin: LianjiaTech/kob

/**
 * 待回收积压任务
 * 根据一定权重进入回收方法,判断是否超过积压阈值,并回收已过期任务只可剩余任务数量
 *
 * @param projectCode 项目名称
 */
private void recoveryOverstockTask(String projectCode) {
  int random100 = new Random().nextInt(AdminConstant.ONE_HUNDRED);
  if (random100 < processorProperties.getTaskOverstockRecoveryWeight()) {
    List<String> taskPathList = zkClient.getChildren(ZkPathConstant.clientTaskPath(serverContext.getCluster(), projectCode));
    if (!KobUtils.isEmpty(taskPathList) && taskPathList.size() > processorProperties.getTaskOverstockRecoveryThreshold()) {
      List<TaskBaseContext> tasks = new ArrayList<>();
      for (String s : taskPathList) {
        TaskBaseContext task = JSONObject.parseObject(s, TaskBaseContext.class);
        task.setPath(ZkPathConstant.clientTaskPath(serverContext.getCluster(), projectCode) + ZkPathConstant.BACKSLASH + s);
        tasks.add(task);
      }
      Collections.sort(tasks);
      List<TaskBaseContext> overstockTask = tasks.subList(0, tasks.size() - processorProperties.getTaskOverstockRecoveryRetainCount());
      scheduleService.fireOverstockTask(zkClient, overstockTask, serverContext.getCluster());
    }
  }
}

代码示例来源:origin: LianjiaTech/kob

@Override
  public void afterPropertiesSet() throws Exception {
    this.masterElector = new MasterElector(cluster, now.getTime());
    this.masterPath = ZkPathConstant.serverNodePath(cluster);
  }
}

代码示例来源:origin: LianjiaTech/kob

/**
 * 保存项目接入信息
 *
 * @return ResponseData
 */
@RequestMapping(value = "/save_project_access.json")
@ResponseBody
public ResponseData saveProjectAccess() {
  HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  User user = (User) request.getSession().getAttribute(Attribute.SESSION_USER);
  String projectCode = request.getParameter("project_code");
  String regex = "([A-Z]|[a-z]|_){6,60}";
  if (KobUtils.isEmpty(projectCode) || !projectCode.matches(regex)) {
    return ResponseData.error("项目标识有误");
  }
  String projectName = request.getParameter("project_name");
  if (KobUtils.isEmpty(projectName) || projectName.length() > 60) {
    return ResponseData.error("项目名称有误");
  }
  boolean zkExist = zkClient.exists(ZkPathConstant.clientNodePath(cluster, projectCode));
  boolean dbExist = indexService.existProject(projectCode);
  if (zkExist || dbExist) {
    return ResponseData.error("项目已存在");
  }
  indexService.initProject(user.getCode(), user.getName(), user.getConfiguration(), projectCode, projectName);
  zkClient.createPersistent(ZkPathConstant.clientNodePath(cluster, projectCode), true);
  zkClient.createPersistent(ZkPathConstant.clientTaskPath(cluster, projectCode), true);
  return ResponseData.success();
}

代码示例来源:origin: LianjiaTech/kob

return;
List<String> currentChilds = zkClient.getChildren(ZkPathConstant.serverNodePath(serverContext.getCluster()));
NodeServer currentNodeServerMaster = MasterElector.getNodeMaster(currentChilds);
if (!currentNodeServerMaster.getIdentification().equals(serverContext.getMasterElector().getMaster().getIdentification())) {
  for (final String currentProjectCode : currentProjectCodeSet) {
    if (localProjectCodeSet.add(currentProjectCode)) {
      zkClient.subscribeChildChanges(ZkPathConstant.clientNodePath(serverContext.getCluster(), currentProjectCode), new IZkChildListener() {
        @Override
        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {

代码示例来源:origin: LianjiaTech/kob

clientTaskPath = ZkPathConstant.clientTaskPath(prop.getCluster(), prop.getProjectCode());
clientNodePath = ZkPathConstant.clientNodePath(prop.getCluster(), prop.getProjectCode());
buildKobRunner(beans);
buildClientInfo(prop);

代码示例来源:origin: LianjiaTech/kob

@Override
  public Map<String, ClientPath> getClientPaths(String projectCode) {
    String clientNodePath = ZkPathConstant.clientNodePath(cluster, projectCode);
    if (!zkClient.exists(clientNodePath)) {
      return null;
    }
    List<String> nodePathStrList = zkClient.getChildren(clientNodePath);
    Map<String, ClientPath> projectClientPath = new HashMap<>(10);
    if (!KobUtils.isEmpty(nodePathStrList)) {
      for (String child : nodePathStrList) {
        ClientPath clientPath = JSONObject.parseObject(child, ClientPath.class);
        projectClientPath.put(clientPath.getIdentification(), clientPath);
      }
    }
    return projectClientPath;
  }
}

代码示例来源:origin: LianjiaTech/kob

@Override
public void pushTask(ZkClient zkClient, TaskWaiting tw, String cluster) {
  TaskBaseContext context = new TaskBaseContext();
  context.setProjectCode(tw.getProjectCode());
  context.setJobUuid(tw.getJobUuid());
  context.setJobCn(tw.getJobCn());
  context.setTaskUuid(tw.getTaskUuid());
  context.setTaskKey(tw.getTaskKey());
  context.setTriggerTime(tw.getTriggerTime());
  context.setDesignatedNode(tw.getInnerParamsBean().getDesignatedNode());
  context.setRecommendNode(tw.getInnerParamsBean().getRecommendNode());
  context.setTryToExclusionNode(tw.getInnerParamsBean().getTryToExclusionNode());
  context.setUserParam(JSONObject.parseObject(tw.getUserParams()));
  String projectTaskPath = ZkPathConstant.clientTaskPath(cluster, context.getProjectCode());
  int state = TaskRecordStateConstant.PUSH_SUCCESS;
  Map<String, Object> param = new HashMap<>(10);
  try {
    zkClient.createPersistent(projectTaskPath + ZkPathConstant.BACKSLASH + JSONObject.toJSONString(context));
  } catch (Exception e) {
    log.error("pushTask_error 推送zk事件异常", e);
    state = TaskRecordStateConstant.PUSH_FAIL;
    param.put("complete", true);
  }
  param.put("state", state);
  taskRecordMapper.updateByTaskUuid(param, tw.getTaskUuid(), cluster);
}

代码示例来源:origin: LianjiaTech/kob

public String getLocalNodePath() {
  return ZkPathConstant.serverNodePath(cluster) + ZkPathConstant.BACKSLASH + JSONObject.toJSONString(masterElector.getLocal());
}

代码示例来源:origin: LianjiaTech/kob

private void refreshClientNode(List<String> currentChilds, String project) {
  Map<String, ClientInfo> projectClientNode = new ConcurrentHashMap<>();
  if (!KobUtils.isEmpty(currentChilds)) {
    for (String child : currentChilds) {
      ClientPath clientPath = JSONObject.parseObject(child, ClientPath.class);
      String path = ZkPathConstant.clientNodePath(serverContext.getCluster(), project) + ZkPathConstant.BACKSLASH + child;
      String dataStr = zkClient.readData(path, true);
      if (!KobUtils.isEmpty(dataStr)) {
        ClientData clientData = JSONObject.parseObject(dataStr, ClientData.class);
        projectClientNode.put(clientPath.getIdentification(), new ClientInfo(path, clientPath, clientData));
      }
    }
  }
  serverContext.getClientNodeMap().put(project, projectClientNode);
}

代码示例来源:origin: LianjiaTech/kob

context.setTryToExclusionNode(retryTask.getInnerParamsBean().getTryToExclusionNode());
context.setUserParam(JSONObject.parseObject(retryTask.getUserParams()));
String projectTaskPath = ZkPathConstant.clientTaskPath(cluster, context.getProjectCode());
int state = TaskRecordStateConstant.PUSH_SUCCESS;
Map<String, Object> param = new HashMap<>(10);

代码示例来源:origin: LianjiaTech/kob

@Override
public List<NodeServer> getNodeServerList() {
  String serverNodePath = ZkPathConstant.serverNodePath(cluster);
  if (!zkClient.exists(serverNodePath)) {
    return new ArrayList<>();
  }
  List<String> nodeServerStrList = zkClient.getChildren(serverNodePath);
  List<NodeServer> nodeServerList = new ArrayList<>();
  if (!KobUtils.isEmpty(nodeServerStrList)) {
    for (String nodeServerStr : nodeServerStrList) {
      NodeServer nodeServer = JSONObject.parseObject(nodeServerStr, NodeServer.class);
      nodeServerList.add(nodeServer);
    }
  }
  return nodeServerList;
}

代码示例来源:origin: LianjiaTech/kob

innerParams.setTaskPushNode(serverIdentification);
if (LoadBalanceType.NODE_HASH.name().equals(tw.getLoadBalance())) {
  List<String> clientNodePathList = zkClient.getChildren(ZkPathConstant.clientNodePath(cluster, tw.getProjectCode()));
  List<String> nodeList = new ArrayList<>();
  if (!KobUtils.isEmpty(clientNodePathList)) {

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