use of com.couchbase.connector.cluster.consul.rpc.Broadcaster in project couchbase-elasticsearch-connector by couchbase.
the class DocumentKeys method waitForClusterToQuiesce.
private void waitForClusterToQuiesce(Duration timeout) throws TimeoutException {
final TimeoutEnforcer timeoutEnforcer = new TimeoutEnforcer(timeout);
try (Broadcaster broadcaster = new Broadcaster()) {
while (true) {
final List<RpcEndpoint> allEndpoints = listRpcEndpoints();
final Map<RpcEndpoint, RpcResult<Boolean>> results = broadcaster.broadcast("stopped?", allEndpoints, WorkerService.class, WorkerService::stopped);
boolean stopped = true;
for (Map.Entry<RpcEndpoint, RpcResult<Boolean>> e : results.entrySet()) {
if (e.getValue().isFailed()) {
LOGGER.warn("Status request failed for endpoint " + e.getKey());
stopped = false;
} else if (!e.getValue().get()) {
LOGGER.warn("Endpoint is still working: " + e.getKey());
stopped = false;
}
}
if (stopped) {
return;
}
timeoutEnforcer.throwIfExpired();
LOGGER.info("Retrying in just a moment...");
SECONDS.sleep(2);
}
} catch (Exception e) {
throwIfUnchecked(e);
propagateIfPossible(e, TimeoutException.class);
throw new RuntimeException(e);
}
}
Aggregations