/** * 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); }