Fixed Protocols

If we recall our definition of a message as an identifier followed by a set of arguments, we can break down the possible message protocols into fixed and adaptable types. In this section we’ll discuss fixed protocols, where the set of possible identifiers and the arguments for each type of message are known beforehand and don’t change during a communication session. Adaptable protocols have variable argument lists on messages, or variable sets of message types, or both.

Let’s return to the chess-player agents that we mentioned earlier and define a fixed protocol that they could use to engage in a game of chess. We’ll define a protocol that will let them pass moves back and forth, confirm each other’s moves, and concede a game. Then we’ll implement this message protocol using our BasicMessage and BasicMsgHandler classes.

Figure 6.1 shows the architecture of the chess-playing system we’ll be building in the following sections. On each player’s host computer, a ChessPlayer object keeps track of the current board layout and comes up with the player’s next move. A ChessServer object handles all of the communication with the remote opponent; it packages up moves from the local player into messages, and ships them off to the opponent’s ChessServer. (It also takes messages from the remote opponent and calls the required methods on the local ChessPlayer.)

Chess system architecture
Figure 6-1. Chess ...

Get Java Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.