/** * Operations Node removed. * * @param data the data */ protected void endpointRemoved(ChildData data) { OperationsNodeInfo nodeInfo = extractOperationServerInfo(data); String endpointAddress = constructEndpointAddress(nodeInfo); Long removeTime = nodeInfo.getTimeStarted(); Long updateTime = operationNodesStartTimes.get(endpointAddress); if (updateTime == null || removeTime >= updateTime) { operationNodesStartTimes.remove(endpointAddress); for (OperationsNodeListener listener : endpointListeners) { listener.onNodeRemoved(nodeInfo); } } else { LOG.debug("Ignoring [{}] endpoint removal, as it was before add/update", endpointAddress); } }
/** * Operations Node added. * * @param data the data */ protected void endpointAdded(ChildData data) { OperationsNodeInfo nodeInfo = extractOperationServerInfo(data); String endpointAddress = constructEndpointAddress(nodeInfo); operationNodesStartTimes.put(endpointAddress, nodeInfo.getTimeStarted()); for (OperationsNodeListener listener : endpointListeners) { listener.onNodeAdded(nodeInfo); } }
/** * Operations Node updated. * * @param data the data */ protected void endpointUpdated(ChildData data) { OperationsNodeInfo nodeInfo = extractOperationServerInfo(data); String endpointAddress = constructEndpointAddress(nodeInfo); operationNodesStartTimes.put(endpointAddress, nodeInfo.getTimeStarted()); for (OperationsNodeListener listener : endpointListeners) { listener.onNodeUpdated(nodeInfo); } }
/** * Gets the current endpoint nodes. * * @return the current endpoint nodes */ public List<OperationsNodeInfo> getCurrentOperationServerNodes() { List<ChildData> nodesData = endpointCache != null ? endpointCache .getCurrentData() : new ArrayList<ChildData>(); Map<ConnectionInfoKey, OperationsNodeInfo> uniqueMap = new HashMap<>(); for (ChildData data : nodesData) { OperationsNodeInfo newNodeInfo = extractOperationServerInfo(data); ConnectionInfoKey key = new ConnectionInfoKey(newNodeInfo.getConnectionInfo()); OperationsNodeInfo oldNodeInfo = uniqueMap.get(key); if (oldNodeInfo != null) { if (newNodeInfo.getTimeStarted() >= oldNodeInfo.getTimeStarted()) { uniqueMap.put(key, newNodeInfo); } } else { uniqueMap.put(key, newNodeInfo); } } return new ArrayList<>(uniqueMap.values()); }