Waiting for clients to complete an action

When using CT with multiple clients and consecutive games, it becomes necessary to ensure proper synchronization. The server needs to be able to know when all clients have completed an action, so that it doesn't begin a new game or start some new process while some of the clients aren't ready.

A "ClientWaiter" system has been implemented in the groupRobust branch, and will hopefully soon be merged into the trunk.

  1. Add class: edu.harvard.eecs.airg.coloredtrails.server.ClientWaiter
  2. In edu.harvard.eecs.airg.coloredtrails.server.ServerGameStatus  
    1. Add methods
      • public boolean waitForClients(String category, long interval, long timeoutIntervals)
      • public void setWaitStatus(String category, int perGameId, boolean status)
      • public boolean getWaitStatus(String category, int perGameId)
    2. Add to the end of setEnded()
              if (!waitForClients("ReadyForNextGame", 2000, 10))
              {
              	throw new RuntimeException("Clients failed to end game after 20 seconds!");
              }
  3. In edu.harvard.eecs.airg.coloredtrails.server.ColoredTrailsServer, add this declaration:
    public static final String CATEGORYFINISHED = "FINISHEDCATEGORY:";
  4. In edu.harvard.eecs.airg.coloredtrails.server.ClientCommands.onMessage(Message), add the following condition branch.
    			else if (req.startsWith(ColoredTrailsServer.CATEGORYFINISHED))
    			{
    				String category = req.substring(ColoredTrailsServer.CATEGORYFINISHED.length());
    				log.debug("Received a FINISHEDCATEGORY message [" + category + "] from " + clientid);
    				
    				ServerGameStatus gs = ServerData.getInstance().getGameStatusById(gameid);
    				gs.setWaitStatus(category, perGameId, true);
    			}
  5. In edu.harvard.eecs.airg.coloredtrails.ColoredTrailsClientImpl
    1. Add method public void sendCategoryFinishedMessage(String category)
    2. Add to the top of gameEnded():
      		sendCategoryFinishedMessage("ReadyForNextGame");