public class PingPong {

	Agent<String> whoseTurn;

	public PingPong(Agent<String> player) {
		whoseTurn = player;
	}

	public boolean hit(final String opponent) {
		final String x = Thread.currentThread().getName();

		//wait till all the messages are processed to make 
		//you get the correct value, as updated to Agents are
		//async
		String result = whoseTurn.await(new Timeout(5, SECONDS));

		if (x.compareTo(result) == 0) {
			System.out.println("PING! (" + x + ")");
			whoseTurn.send(opponent);
		} else {
			try {
				wait(2500);

			} catch (Exception e) {
			}
		}
		return true; // keep playing.
	}
}