コード例 #1
0
  private void setCurSequence(Application application) {
    List<Node> nodes = application.getSubscribedNodeManager().getNodeList(NodeType.JOB_TRACKER);
    totalNodes = CollectionUtils.sizeOf(nodes);
    if (totalNodes == 0) {
      curSequence = 0;
    } else if (totalNodes == 1) {
      curSequence = 0;
    } else {
      List<Node> copy = new ArrayList<Node>(nodes);
      Collections.sort(
          copy,
          new Comparator<Node>() {
            @Override
            public int compare(Node left, Node right) {
              return left.getCreateTime().compareTo(right.getCreateTime());
            }
          });

      int index = 0;
      for (Node node : copy) {
        if (node.getIdentity().equals(application.getConfig().getIdentity())) {
          // 当前节点
          curSequence = index;
          break;
        }
        index++;
      }
    }
  }
コード例 #2
0
  /** 记录节点上下线日志 */
  private void addLog(NotifyEvent event, List<Node> nodes) {
    List<NodeOnOfflineLog> logs = new ArrayList<NodeOnOfflineLog>(nodes.size());

    for (Node node : nodes) {
      NodeOnOfflineLog log = new NodeOnOfflineLog();
      log.setLogTime(new Date());
      log.setEvent(event == NotifyEvent.ADD ? "ONLINE" : "OFFLINE");

      log.setClusterName(node.getClusterName());
      log.setCreateTime(node.getCreateTime());
      log.setGroup(node.getGroup());
      log.setHostName(node.getHostName());
      log.setIdentity(node.getIdentity());
      log.setIp(node.getIp());
      log.setPort(node.getPort());
      log.setThreads(node.getThreads());
      log.setNodeType(node.getNodeType());

      logs.add(log);
    }

    nodeOnOfflineLogRepo.insert(logs);
  }