From 2a7606d626792d3095f6fc04b16d151cac57939d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 5 Oct 2021 12:39:28 +0200 Subject: [PATCH] Track actors globally (eventually for reflection/introspection) --- syndicate/src/actor.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/syndicate/src/actor.rs b/syndicate/src/actor.rs index 5e363e0..b985010 100644 --- a/syndicate/src/actor.rs +++ b/syndicate/src/actor.rs @@ -506,8 +506,10 @@ preserves_schema::support::lazy_static! { }; #[doc(hidden)] - pub static ref ACCOUNTS: RwLock)>> = - RwLock::new(Map::new()); + pub static ref ACCOUNTS: RwLock)>> = Default::default(); + + #[doc(hidden)] + pub static ref ACTORS: RwLock> = Default::default(); } impl TryFrom<&AnyValue> for Synced { @@ -1476,13 +1478,8 @@ impl Actor { root: root.facet_id, }; st.facet_nodes.insert(root.facet_id, root); - Actor { - rx, - ac_ref: ActorRef { - actor_id, - state: Arc::new(Mutex::new(ActorState::Running(st))), - }, - } + let ac_ref = ActorRef { actor_id, state: Arc::new(Mutex::new(ActorState::Running(st))) }; + Actor { rx, ac_ref } } fn link(self, t_parent: &mut Activation) -> Self { @@ -1506,6 +1503,7 @@ impl Actor { name: tracing::Span, boot: F, ) -> ActorHandle { + ACTORS.write().insert(self.ac_ref.actor_id, (name.clone(), self.ac_ref.clone())); name.record("actor_id", &self.ac_ref.actor_id); tokio::spawn(async move { tracing::trace!("start"); @@ -1744,6 +1742,7 @@ impl Drop for Field { impl Drop for Actor { fn drop(&mut self) { self.rx.close(); + ACTORS.write().remove(&self.ac_ref.actor_id); tracing::trace!(actor_id = ?self.ac_ref.actor_id, "Actor::drop"); } }