Expand description
Mailboxes are the central message-passing mechanism in Hyperactor.
Each actor owns a mailbox to which other actors can deliver messages. An actor can open one or more typed ports in the mailbox; messages are in turn delivered to specific ports.
Mailboxes are associated with an ActorId
(given by actor_id
in the following example):
let mbox = Mailbox::new_detached(actor_id);
let (port, mut receiver) = mbox.open_port::<u64>();
port.send(123).unwrap();
assert_eq!(receiver.recv().await.unwrap(), 123u64);
Mailboxes also provide a form of one-shot ports, called [OncePort
],
that permits at most one message transmission:
let mbox = Mailbox::new_detached(actor_id);
let (port, receiver) = mbox.open_once_port::<u64>();
port.send(123u64).unwrap();
assert_eq!(receiver.recv().await.unwrap(), 123u64);
[OncePort
]s are correspondingly used for RPC replies in the actor
system.
§Remote ports and serialization
Mailboxes allow delivery of serialized messages to named ports:
- Ports restrict message types to (serializable)
Message
s. - Each [
Port
] is associated with aPortId
which globally names the port. Mailbox
provides interfaces to deliver serialized messages to ports named by theirPortId
.
While this complicates the interface somewhat, it allows the implementation to avoid a serialization roundtrip when passing messages locally.
Re-exports§
pub use mailbox_admin_message::MailboxAdminMessage;
pub use mailbox_admin_message::MailboxAdminMessageHandler;
pub use durable_mailbox_sender::log;
Modules§
- durable_
mailbox_ sender - For [
DurableMailboxSender
] a sender with a write-ahead log. - mailbox_
admin_ message - For
MailboxAdminMessage
, a message type for mailbox administration.
Structs§
- Boxed
Mailbox Sender - Convenience boxing implementation for MailboxSender. Most APIs are parameterized on MailboxSender implementations, and it’s thus difficult to work with dyn values. BoxedMailboxSender bridges this gap by providing a concrete MailboxSender which dispatches using an underlying (boxed) dyn.
- Dial
Mailbox Router - A dynamic mailbox router that supports remote delivery.
- Mailbox
- A mailbox coordinates message delivery to actors through typed
[
Port
]s associated with the mailbox. - Mailbox
Client - A mailbox server client that transmits messages on a Tx channel.
- Mailbox
Error - Errors that occur during mailbox operations. Each error is associated with the mailbox’s actor id.
- Mailbox
Muxer - An in-memory mailbox muxer. This is used to route messages to different underlying senders.
- Mailbox
Router - MailboxRouter routes messages to the sender that is bound to its nearest prefix.
- Mailbox
Sender Error - Errors that that occur during mailbox sending operations. Each error is associated with the port ID of the operation.
- Mailbox
Server Handle - Represents a running
MailboxServer
. The handle composes a [‘tokio::task::JoinHandle’] and may be joined in the same manner. - Message
Envelope - An envelope that carries a message destined to a remote actor. The envelope contains a serialized message along with its destination and sender.
- Message
Metadata - Metadata about a message sent via a MessageEnvelope.
- Once
Port Handle - A one-shot port handle to which M-typed messages can be delivered.
- Once
Port Receiver - A receiver of M-typed messages from [
OncePort
]s. - Panicking
Mailbox Sender - A perpetually closed mailbox sender. Panics if any messages are posted. Useful for tests, or where there is no meaningful mailbox sender implementation available.
- Port
Handle - A port to which M-typed messages can be delivered. Ports may be
serialized to be sent to other actors. However, when a port is
deserialized, it may no longer be used to send messages directly
to a mailbox since it is no longer associated with a local mailbox
([
Mailbox::send
] will fail). However, the runtime may accept remote Ports, and arrange for these messages to be delivered indirectly through inter-node message passing. - Port
Receiver - A receiver of M-typed messages, used by actors to receive messages on open ports.
- Port
Sink - Wrapper to turn
PortRef
into aSink
. - Serialized
Sender Error - Error that that occur during SerializedSender’s send operation.
- Undeliverable
- For
Undeliverable
, a message type for delivery failures. An undeliverableM
-typed message (in practiceM
is MessageEnvelope). - Undeliverable
Mailbox Sender - A mailbox sender for undeliverable messages. This will simply record any undelivered messages.
- Unroutable
Mailbox Sender - A MailboxSender that reports any envelope as undeliverable due to routing failure.
- Weak
Mailbox Router - A version of
MailboxRouter
that holds a weak reference to the underlying state. This allows router references to be circular: an entity holding a reference to the router may also contain the router itself.
Enums§
- Delivery
Error - Delivery errors occur during message posting.
- Mailbox
Error Kind - The kinds of mailbox errors. This enum is marked non-exhaustive to allow for extensibility.
- Mailbox
Sender Error Kind - The kind of mailbox sending errors.
- Mailbox
Server Error - Errors that occur during mailbox serving.
- Port
Location - PortLocation describes the location of a port. This is used in errors to provide a uniform data type for ports that may or may not be bound.
- Undeliverable
Message Error - Errors that occur during message delivery and return.
Traits§
- Boxable
Mailbox Sender - Extension trait that creates a boxed clone of a MailboxSender.
- Into
Boxed Mailbox Sender - Extension trait that rehomes a MailboxSender into a BoxedMailboxSender.
- Mailbox
Sender - MailboxSenders can send messages through ports to mailboxes. It provides a unified interface for message delivery in the system.
- Mailbox
Server - Serve a port on the provided
channel::Rx
. This dispatches all channel messages directly to the port. - Message
- Message collects the necessary requirements for messages that are deposited into mailboxes.
- Port
Sender - PortSender extends
MailboxSender
by providing typed endpoints for sending messages over ports. - Remote
Message - RemoteMessage extends
Message
by requiring that the messages also be serializable, and can thus traverse process boundaries. RemoteMessages must also specify a globally unique type name (a URI).
Functions§
- custom_
monitored_ return_ handle - Now that monitored return handles are rare, it’s becoming helpful to get insights into where they are getting used (so that they can be eliminated and replaced with something better).
- monitored_
return_ handle - Accessor to the shared monitored undeliverable message port handle. Initialization spawns the undeliverable message port monitor that forwards incoming messages to the undeliverable mailbox sender.
- open_
once_ port - Open a one-shot port given a capability. This is a public method primarily to enable macro-generated clients.
- open_
port - Open a port given a capability.
- supervise_
undeliverable_ messages - Spawns a task that listens for undeliverable messages and posts a
corresponding
ActorSupervisionEvent
to the given supervision port.
Type Aliases§
- Data
- Type alias for bytestring data used throughout the system.