Inspirel banner

Programming Distributed Systems with YAMI4

4.2 Agents

The agent encapsulates system resources (network connections, threads, etc.) that are needed for communication.

The name ``agent'' is used to reflect the terminology used in previous versions of the project. Another popular term for the entity that manages communication is a broker (the name mostly associated with ORB, from Object Request Broker), but it is useful to distinguish these terms in the context of previous chapter, where ``broker'' clearly referred to external central service that was used to relay messages between other remote participants - in contrast, ``agent'' is meant to be a local manager object that handles everything that is related to communication with other programs.

In many programs - in particular in all YAMI4 examples - the agent is created in a single instance and is kept alive for the lifetime of the program. In fact, server-like programs that are reactive in nature will have most or even all of their activity driven by the agent, which will orchestrate the work in response to the arriving messages. This is a very clean approach from the design perspective, but certainly not the only one possible with YAMI4.

Agent is a relatively cheap object that can be created in many instances if that makes sense in a give project - such an approach can be useful when different parts of the same program take part in remote communication for completely different purposes. It is also possible to create agents for a short period of time that corresponds to a single communication scenario.

The agent object provides services for both sending and receiving messages, which means that in a client-server system there will be at least one agent on both client and server side.

A single agent manages the following internal entities:

Each of these internal entities is described in detail in the following chapters.

A single agent is always associated with at least one background thread (at least the I/O worker thread). All threads managed by the agent are stopped when the agent itself is finalized in Ada, destroyed in C++ or when its close() operation is called in Java or .NET.

Distinct agents do not share any state with the exception of global system space for network port numbers.

Agents can be safely used from multiple threads.