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()); } } }
private void sendComponent(String clientLocation, Component component) { Services.Client client = connections.getClient0(clientLocation); if (client == null) { removeParticipant(clientLocation); } Services.Component componentProto = ServicesPbConversion.componentToPb(component); Rpc rpc = rpcf.create(); RpcCallback<Empty> done = new RemoveParticipantIfFailsCallback<Empty>(clientLocation, rpc); client.setState(rpc, componentProto, done); }
private void sendTakeovers() throws InterruptedException { RpcList rpcs = new RpcList(); for (String location : clients) { Services.Client client = connections.getClient0(location); if (client == null) { clients.remove(location); } else { Rpc rpc = rpcf.create(); client.masterTakeover(rpc, newMaster, new TakeoverCallback(location)); rpcs.add(rpc); } } rpcs.awaitAll(); }
private void finishTakeover() throws InterruptedException { RpcList rpcs = new RpcList(); for (String location : clients) { Services.Client client = connections.getClient0(location); if (client == null) { clients.remove(client); continue; } RemoveClientCallback<Empty> done = new RemoveClientCallback<Empty>(location); Rpc rpc = rpcf.create(); client.masterTakeoverFinished(rpc, newMaster, done); rpcs.add(rpc); } rpcs.awaitAll(); }
private synchronized void sendInitialMasterTakeover(String clientLocation) { Services.Client client = connections.getClient0(clientLocation); // Step 1: Send takeover. Rpc rpc1 = rpcf.create(); RpcCallback<MasterTakeoverResponse> done1 = new RemoveParticipantIfFailsCallback<MasterTakeoverResponse>(clientLocation, rpc1); client.masterTakeover(rpc1, getMasterInfo(), done1); // Step 2: Send all state. sendFullState(clientLocation); // Step 3: Finish takeover. Rpc rpc2 = rpcf.create(); RpcCallback<Empty> done2 = new RemoveParticipantIfFailsCallback<Empty>(clientLocation, rpc2); client.masterTakeoverFinished(rpc2, getMasterInfo(), done2); }
private void sendFullState() throws InterruptedException { RpcList rpcs = new RpcList(); for (String location : clients) { Services.Client client = connections.getClient0(location); if (client == null) { clients.remove(client); continue; } RemoveClientCallback<Empty> done = new RemoveClientCallback<Empty>(location); for (Component component : state.getComponents()) { Services.Component componentPb = ServicesPbConversion.componentToPb(component); Rpc rpc = rpcf.create(); client.setState(rpc, componentPb, done); rpcs.add(rpc); } } rpcs.awaitAll(); }