1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) Sean Lawlor
//
// This source code is licensed under both the MIT license found in the
// LICENSE-MIT file in the root directory of this source tree.
//! Represents an actor registry.
//!
//! It allows unique naming of actors via `String`
//! so it works more or less like an Erlang `atom()`
//!
//! Actors are automatically registered into the global registry, if they
//! provide a name, upon construction. Actors are also
//! automatically unenrolled from the registry upon being dropped, therefore freeing
//! the name for subsequent registration.
//!
//! You can then retrieve actors by name with [where_is]. Note: this
//! function only returns the [ActorCell] reference to the actor, it
//! additionally requires knowledge of the [crate::Actor] in order
//! to send messages to it (since you need to know the message type)
//! or agents will runtime panic on message reception, and supervision
//! processes would need to restart the actors.
//!
//! ## Examples
//!
//! **Basic actor retrieval**
//! ```rust
//! async fn test() {
//! let maybe_actor = ractor::registry::where_is("my_actor".to_string());
//! if let Some(actor) = maybe_actor {
//! // send a message, or interact with the actor
//! // but you'll need to know the actor's strong type
//! }
//! }
//! ```
//!
//! **Full example**
//!
//! ```rust
//! use ractor::registry;
//! use ractor::Actor;
//! use ractor::ActorProcessingErr;
//! use ractor::ActorRef;
//!
//! struct ExampleActor;
//!
//! #[cfg_attr(feature = "async-trait", ractor::async_trait)]
//! impl Actor for ExampleActor {
//! type Msg = ();
//! type State = ();
//! type Arguments = ();
//!
//! async fn pre_start(
//! &self,
//! _myself: ActorRef<Self::Msg>,
//! _args: Self::Arguments,
//! ) -> Result<Self::State, ActorProcessingErr> {
//! println!("Starting");
//! Ok(())
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! let (actor, handle) = Actor::spawn(Some("my_actor".to_string()), ExampleActor, ())
//! .await
//! .expect("Failed to startup dummy actor");
//!
//! // Retrieve the actor by name from the registry
//! let who: ActorRef<()> = registry::where_is("my_actor".to_string())
//! .expect("Failed to find actor")
//! .into();
//! who.cast(()).expect("Failed to send message");
//!
//! // wait for actor exit
//! actor.stop(None);
//! handle.await.unwrap();
//!
//! // Automatically removed from the registry upon shutdown
//! assert!(registry::where_is("my_actor".to_string()).is_none());
//! }
//! ```
use Arc;
use Occupied;
use Vacant;
use DashMap;
use OnceCell;
use crateActorCell;
use crateActorName;
pub use get_all_pids;
pub use where_is_pid;
pub use PidLifecycleEvent;
/// Errors involving the [crate::registry]'s actor registry
/// The name'd actor registry
static ACTOR_REGISTRY: = new;
/// Retrieve the named actor registry handle
/// Put an actor into the registry
pub
/// Remove an actor from the registry given it's actor name
pub
/// Try and retrieve an actor from the registry
///
/// * `name` - The name of the [ActorCell] to try and retrieve
///
/// Returns: Some(actor) on successful identification of an actor, None if
/// actor not registered
/// Returns a list of names that have been registered
///
/// Returns: A [`Vec<String>`] of actor names which are registered
/// currently