Skip to main content

atomr_core/actor/
observer.rs

1//! Lifecycle observer hooks. Enables external crates (e.g.
2//! `atomr-telemetry`) to observe actor spawn/stop/dead-letter events
3//! without taking a dependency on `atomr-core`'s internals.
4
5use super::path::ActorPath;
6
7/// Implementors are notified whenever actors are spawned or stopped.
8/// Methods are called on the actor's task, so they should be cheap and
9/// non-blocking.
10pub trait SpawnObserver: Send + Sync + 'static {
11    fn on_spawn(&self, path: &ActorPath, parent: Option<&ActorPath>, actor_type: &'static str);
12    fn on_stop(&self, path: &ActorPath);
13
14    /// Called whenever the mailbox depth is sampled (optional).
15    fn on_mailbox_depth(&self, _path: &ActorPath, _depth: u64) {}
16}
17
18/// Implementors are notified whenever a `tell` fails because the target
19/// actor has stopped. Called on the caller's thread, so implementers
20/// should be cheap.
21pub trait DeadLetterObserver: Send + Sync + 'static {
22    fn on_dead_letter(&self, recipient: &ActorPath, sender: Option<&ActorPath>, message_type: &'static str);
23}