public CompletableFuture<Long> ping(long index) {
CompletableFuture<Long> future = new CompletableFuture<>();
// Set up a read quorum. Once the required number of replicas have been
// contacted the quorum will succeed.
final Quorum quorum = new Quorum(readQuorum, succeeded -> {
if (succeeded) {
future.complete(index);
} else {
future.completeExceptionally(new CopycatException("Failed to obtain quorum"));
}
}).countSelf();
// Iterate through replicas and ping each replica. Internally, this
// should cause the replica to send any remaining entries if necessary.
for (NodeReplicator replica : replicaMap.values()) {
replica.ping(index).whenComplete((resultIndex, error) -> {
if (error == null) {
quorum.succeed();
} else {
quorum.fail();
}
});
}
return future;
}