private void getMostRecentState() throws InterruptedException { boolean successful = false; while (!successful && !aborted.get()) { ClientState bestClient = getBestClient(clientStates); if (bestClient == null) { successful = true; continue; } Services.Client client = connections.getClient0(bestClient.getLocation()); if (client == null) { clients.remove(bestClient.getLocation()); continue; } Rpc rpc = rpcf.create(); FullStateCallback done = new FullStateCallback(); client.getFullState(rpc, Empty.getDefaultInstance(), done); rpc.await(); successful = rpc.isOk(); if (!successful) { clients.remove(bestClient.getLocation()); } } }
@Override public void joinNetworkRequest( RpcController controller, ClientState request, RpcCallback<Empty> done) { sendInitialMasterTakeover(request.getLocation()); addParticipant(request.getLocation()); done.run(Empty.getDefaultInstance()); }
private ClientState getBestClient(List<ClientState> clients) { if (clients.isEmpty()) { return null; } ClientState best = clients.get(0); for (ClientState client : clients) { if (client.getRevision() > best.getRevision()) { best = client; } } return best; }