AMX Message Exchange Manager
K
A
DAK
111
8. AMX Message Exchange Mana ger8.1 Introduction
The AMX Message Exchange Manager provides a very flexible, general purpose
mechanism for inter process communication and synchronization using prioritized
messages. In particular, it offers an instant solution to a common problem frequently
encountered in real-time applications: one or more processes (producers) having to
asynchronously deliver requests of varying priorities for service to one or more servers
(consumers) whose identity is unknown to the producer.
For example, assume that two printers are available to print reports and that requests for
specific reports originate from a periodic Timer Procedure, from a data acquisition task
and from a data base update task. The producers do not know which printer, if any, is
free for use at the instant they must initiate their requests. Furthermore, if no printer is
free, the data acquisition task and Timer Procedure are unable to wait for a printer to
become available. The data acquisition task must be able to inject high priority print
requests when errors are detected. How then to solve the problem?
The Message Exchange Manager readily provides the solution. A message exchange is
created to act as a prioritized print request queue. The data acquisition task, Timer
Procedure and data base task send their print requests to the message exchange. Two
print server tasks, one for each printer, wait on the message exchange for the next print
request. Each print server completes the generation of one report on its printer and then
goes back to the exchange for the next request.
As just illustrated, the AMX Message Exchange Manager provides an extension to the
inherent message passing services offered by AMX. The AMX kernel only allows a
message to be sent to the particular task identified by the sender. The Message Exchange
Manager extends the message delivery system to permit any task, ISP or Timer Procedure
to receive a message. In so doing, it also removes the restriction requiring the message
sender to identify the message receiver.
The Message Exchange Manager uses a message exchange to deliver messages. A
message exchange consists of four message queues into which messages can be
deposited. The message queues are ordered according to priority (0, 1, 2 or 3), message
queue 0 being of highest priority.
Messages are delivered to the message queues in a message exchange in message
envelopes. These are the same envelopes that are used by AMX to deliver messages to
task mailboxes (see Chapter 3.9).
Any task, ISP, Timer Procedure or Restart Procedure can send a message to a message
exchange. The sender indicates the priority of its message (0 to 3) thereby identifying the
message queue into which it will be delivered.
Any task, ISP or Timer Procedure can request a message from a message exchange.
Only tasks are allowed to wait for the arrival of a message if none is present in the
message exchange when the task makes its request. A task can specify the priority at
which it is willing to wait and the maximum time interval which it will wait for a
message to arrive.