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