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