|
Outgoing messages can have assigned a priority, which influences the ordering of message frames in the outgoing message queue.
Each communication channel has its own outgoing queue where already serialized messages are stored for transmission. When the channel is freshly created, its outgoing queue is empty.
When the user code asks the agent to send a message, it is serialized and fragmented into a sequence of frames, which are then put into the outgoing queue of the relevant channel. Assuming that the first message ``A'', which was send with the default priority 0, was big enough to span three frames, the state of the outgoing queue can be represented as on the following diagram:
This arrangement of frames means that the first one to be physically transmitted is frame 1, then frame 2 and the last one will be frame 3 - after all three frames are transmitted, the queue will be empty again.
If the user code asks to send another message with default priority 0, its frames will be placed after the existing frames, which indicates that the FIFO ordering is guaranteed for the transmission of messages within the same priority. Similarly, new frames will be appended at the end of the queue if the new message has lower priority than the priorities of existing frames.
The message priorities disrupt this scheme when the newly created message has priority that is higher than the priority of the last frame - in this case the frames belonging to the newly created message will be inserted before all frames of lower priority, except for the first frame in the queue, which is considered to be implicitly ``pinned'' for transmission. For example, if the state of the outgoing queue is as described above and the new message ``B'' that is big enough to span two frames is created with some higher priority (for example 5), then the frames belonging to message ``B'' will be inserted between frames 1 and 2 of message ``A'':
Thanks to this rearrangement the frames will be transmitted in this order:
In other words, high-priority message ``B'' will preempt the delivery of low-priority message ``A''. This scheme can be of course scaled up to handle more complex combinations of priorities with any number of messages.
At the receiving end all frames will be collected and assembled into complete messages - in the above example the message ``B'' will be assembled before message ``A'', even though it was posted after ``A''.
The following points should be noted with regard to the above example:
Priorities are also taken into account when the channel is explicitly closed by the user. The closing operation can have its own priority and respects the priorities of frames that are possibly still in the outgoing queue of the given channel. By extending the above example, if the close request is posted with priority 3 and the outgoing queue has exactly the state as on the above diagram, then message ``B'' will be allowed to be fully transmitted (as it has a higher priority than the close request), whereas message ``A'' will be interrupted and abandoned. Close requests respect FIFO ordering with regard to messages of the same priority.
Priority information is provided as an additional parameter to the sending and closing operation and by default is equal to 0
.