Message Processing

When you’re developing an agent that will be exchanging messages, it’s important to think about how message processing will integrate with the rest of the objects making up the agent. Ideally, you’d like to:

Isolate communications details from application details

This leaves you free to design the bulk of the classes making up the application around application issues, not issues related to the communication scheme you happen to be using. Likewise, the communications subsystem can be designed and updated independently, based on the communication needs of the overall system.

Provide a structured way to link messages to method calls on application objects

You need a well-defined way for incoming messages to trigger method calls on application objects, and for object methods to generate messages to remote agents to service requests.

These may seem like conflicting requirements, but we’ll see that they can both be satisfied to one degree or another by a single message-processing method.

Asychronous vs. Synchronous Message Handling

A crucial question in designing a message-processing system is whether it needs to be asynchronous or not. In our chess example, the player agents can process messages synchronously, since they’ll be handshaking throughout the entire game. That is, one player sends a move (in a message) to the other player; the second player applies the move to its copy of the “playing board,” weighs its options, and sends its countermove to the first ...

Get Java Distributed Computing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.