Concepts
Communications
In order to communicate with each other, separate processes only need to open a single connection with a bus. They never directly exchange data. They only send messages to the bus and they only receive messages from the bus. Different programming languages can use a simplified common interface.
Opening a connection with a bus returns an identifier - actually a socket handle - which is used to designate the bus when sending or receiving messages.
NOTE: This connector is also often used to automatically redirect the control flow in the main loop of the program, typically after a select
.
All communicating processes are generally registered on the same bus on the same host machine. For architectural, organizational, performance or security reasons, certain programs can very well open connections with several dedicated buses.
Addressing
To receive data, a process registers itself on a bus under a public name, called a domain name. To exchange data, a process sends a message with a domain name to a bus which will transmit the data to the destination process.
Characteristics
The Ping-Pong exercise in Practice has demonstrated all the characteristics of the magic bus:
- processes can enter and leave the bus whenever they want to,
- a process can register itself and change its name on the bus at any time,
- only one connection channel is needed to communicate with several other processes,
- the same uniform interface can be used to exchange data between different programs,
- communications with the bus are asynchronous,
- a process can be a server and a client at the same time,
- a message can be a notification and no reply is expected,
- a message can be a request in which case a reply is expected,
- if a reply isn’t received before a given fixed time, an error is automatically reported,
- a message can be broadcast to several processes registered under the same name,
- when a given process fails, messages are automatically redirected to a process with the same domain,
- there is no limitation to the number of communicating processes,
- there is no limitation to the size of the messages processes can exchange,
- addressing or transmission errors are always reported.
Message flow
Communications through the bus are asynchronous.
After a process has sent a message, it immediately regains control. If no process is currently registered in the specified destination domain, or if a transmission error occurs, the bus sends an error message to the sender called a nobody message. After the message is transmitted, if the sender didn’t ask for a reply, the bus immediately sends it an empty reply message. If the sender requested a reply, the bus waits for a reply message from the receiver and forwards it to the sender when it receives it. If the receiver doesn’t reply in a given fixed time, the bus sends an error message to the sender called a time-out message.
In order to keep track of messages, a message identifier is passed by the sender along with the data. This identification number is returned by the bus in the reply.
One-way messages
One-way messages don’t expect a reply from the receiver. The bus returns an empty reply message to the sender after all the data could be read by the receiving process. If no process is currently registered in the specified destination domain, or if a transmission error occurs, the bus returns a nobody message.
Two-way messages
Two-way messages expect a reply message from the receiver. Like for one-way messages, if no process is currently registered in the specified destination domain, or if a transmission error occurs, the bus returns a nobody message to the sender. As soon as the receiver sends back a reply, the bus forwards it to the sender in a reply message. If the receiver doesn’t reply in a given fixed time, the bus automatically sends a time-out message to the sender.
Multi-way messages
Multi-way messages are like one-way messages except that they are sent to all the processes which have registered themselves in the specified domain. The bus returns an empty reply to the sender if one destination process could be found and all the data could be transferred. If no process is currently registered in the specified domain, a nobody message is returned.
Comments