Skip to main content

atomr_core/actor/
remote.rs

1//! Remoting extension points exposed by `atomr-core`.
2//!
3//! The actual transport, endpoint manager, and remote-ref implementation
4//! live in `atomr-remote`. This module declares the *trait surface* that
5//! `atomr-remote` plugs into so that `atomr-core` does not need a build
6//! dependency on remoting.
7//!
8//! Collectively.
9
10use std::sync::Arc;
11
12use serde::{Deserialize, Serialize};
13
14use super::address::Address;
15use super::path::ActorPath;
16
17/// A serialized user message destined for a remote actor.
18///
19/// `manifest` is the type identifier (`std::any::type_name::<M>()` by default)
20/// and `serializer_id` keys into the per-system serializer registry on the
21/// receiving side.
22#[derive(Clone, Debug)]
23pub struct SerializedMessage {
24    pub serializer_id: u32,
25    pub manifest: String,
26    pub payload: Vec<u8>,
27    pub sender: Option<ActorPath>,
28}
29
30/// System-level controls that travel across the wire.
31///
32/// + the system-message serializer.
33#[derive(Clone, Debug, Serialize, Deserialize)]
34pub enum RemoteSystemMsg {
35    Stop,
36    Watch { watcher: ActorPath },
37    Unwatch { watcher: ActorPath },
38    Terminated { actor: ActorPath },
39}
40
41/// A reference to an actor on a *different* `ActorSystem`.
42///
43/// Implementations live in `atomr-remote::RemoteActorRefImpl`. The trait is
44/// object-safe so `ActorRef<M>` can carry an `Arc<dyn RemoteRef>` regardless
45/// of the user message type.
46pub trait RemoteRef: Send + Sync + std::fmt::Debug {
47    fn path(&self) -> &ActorPath;
48    fn tell_serialized(&self, msg: SerializedMessage);
49    fn tell_system(&self, msg: RemoteSystemMsg);
50}
51
52/// Pluggable resolver: given a fully-qualified `ActorPath`, return a remote
53/// handle that can deliver to it. Installed on the `ActorSystem` by
54/// `atomr-remote::RemoteActorRefProvider::install`.
55pub trait RemoteProvider: Send + Sync {
56    fn local_address(&self) -> &Address;
57    fn resolve(&self, path: &ActorPath) -> Option<Arc<dyn RemoteRef>>;
58}