/** * Filter the given nodes to only include nodes with the service on it, and sort all those nodes by node number. * * @param clusterNodes Set of all cluster nodes. * @return Sorted list of nodes with the service on it. */ protected List<Node> sortServiceNodes(Set<Node> clusterNodes) { List<Node> filteredNodes = nodesForService(clusterNodes); Collections.sort(filteredNodes, NODE_NUM_COMPARATOR); return filteredNodes; }
/** * Get the n'th node from the given cluster nodes that have the service. * * @param clusterNodes Nodes in the cluster. * @param n number of the node with the service on it. * @return N'th node on the cluster with the given service. * @throws IncompleteClusterException if there are not fewer than n + 1 nodes with the service */ protected Node getNthServiceNode(Set<Node> clusterNodes, int n) throws IncompleteClusterException { List<Node> sortedNodes = sortServiceNodes(clusterNodes); if (n >= sortedNodes.size()) { throw new IncompleteClusterException("There are fewer than " + (n + 1) + " nodes with " + serviceName + " on the cluster"); } return sortedNodes.get(n); }