Juvix imports
module arch.node.types.messages;
import prelude open public;
import arch.node.types.basics open;
import arch.node.types.identities open;
import arch.node.types.anoma_message open;
Messages and mailboxes¶
Types¶
A message is a piece of data dispatched from one engine, termed the sender, to another engine, referred to as the target. When a message is sent, it is enveloped with additional metadata such as the target address and potentially the sender address, in case the sender wants to be identified. Upon arrival at the target engine, the message is stored in the target engine's mailboxes. These mailboxes are indexed by an identifier that are only unique to their engine. If the target engine has only one mailbox, the mailbox identifier is redundant.
The following types are used to represent these messages and mailboxes.
MailboxID¶
A mailbox identifier is a natural number used to index mailboxes.
Where do mailbox identifiers come from?
The concept of mailbox identifier is taken from the paper 1 (see also Mailbox Cluster and 2).
syntax alias MailboxID := Nat;
EngineMsg¶
A message between engines. Consists of a sender, a target, an optional mailbox identifier, and the message itself.
type EngineMsg :=
mkEngineMsg@{
sender : EngineID;
target : EngineID;
mailbox : Option MailboxID;
msg : Msg;
};
MessageID¶
Message identifier. Cryptographic hash of an EngineMsg
.
syntax alias MessageID := Hash;
Mailbox S¶
A mailbox is a container for messages and optionally a mailbox state. The mailbox state could be used to store additional information about the mailbox, such as the priority of the messages in the mailbox.
Where does mailbox state come from?
The mailbox state is related to the capabilities of mailboxes of the paper 1. In particular, at any given point in time, a mailbox will have a capability for receiving messages (in later versions of the specs). As mailbox state can be useful in general, we already have it now.
type Mailbox M :=
mkMailbox@{
messages : List EngineMsg;
mailboxState : Option M;
};
Timer H¶
type Timer H :=
mkTimer@{
time : Time;
handle : H;
};
Trigger H¶
type Trigger H :=
| MessageArrived@{msg : EngineMsg}
| Elapsed@{timers : List (Timer H)};
- Extract the actual message from a trigger in case it has one:
getMessageFromTrigger {H} (tr : Trigger H) : Option Msg :=
case tr of
| MessageArrived@{msg} := some (EngineMsg.msg msg)
| Elapsed@{} := none;
- Get the message sender from a trigger:
getSenderFromTrigger {H} (tr : Trigger H) : Option EngineID :=
case tr of
| MessageArrived@{msg} := some (EngineMsg.sender msg)
| Elapsed@{} := none;
- Get the target destination from a trigger:
getTargetFromTrigger {H} (tr : Trigger H) : Option EngineID :=
case tr of
| MessageArrived@{msg} := some (EngineMsg.target msg)
| Elapsed@{} := none;
TimestampedTrigger H¶
type TimestampedTrigger H :=
mkTimestampedTrigger@{
time : Time;
trigger : Trigger H;
};
- Get the actual message from a
TimestampedTrigger
:getMessageFromTimestampedTrigger {H} (tr : TimestampedTrigger H) : Option Msg :=
getMessageFromTrigger (TimestampedTrigger.trigger tr);
- Get the sender from a
TimestampedTrigger
:getSenderFromTimestampedTrigger
{H} (tr : TimestampedTrigger H) : Option EngineID :=
getSenderFromTrigger (TimestampedTrigger.trigger tr);
- Get the target from a
TImestampedTrigger
:getTargetFromTimestampedTrigger
{H} (tr : TimestampedTrigger H) : Option EngineID :=
getTargetFromTrigger (TimestampedTrigger.trigger tr);
-
Simon Fowler, Duncan Paul Attard, Franciszek Sowul, Simon J. Gay, and Phil Trinder. Special delivery: programming with mailbox types. Proceedings of the ACM on Programming Languages, 7(ICFP):78–107, August 2023. URL: http://dx.doi.org/10.1145/3607832, doi:10.1145/3607832. ↩↩
-
Shams M. Imam and Vivek Sarkar. Selectors: actors with multiple guarded mailboxes. AGERE! '14: Proceedings of the 4th International Workshop on Programming based on Actors Agents and Decentralized Control, October 2014. URL: http://dx.doi.org/10.1145/2687357.2687360, doi:10.1145/2687357.2687360. ↩