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
use std::any::TypeId;
use crate::actor_proxy::ActorReport;
use crate::system_director::SystemDirector;
use crate::{Actor, Handle};
use async_std::task;
use lazy_static::lazy_static;
use std::fmt::Debug;
lazy_static! {
static ref ADDRESS_BOOK: SystemDirector = SystemDirector::new();
}
pub struct Acteur {
system_director: SystemDirector,
}
impl Default for Acteur {
fn default() -> Self {
Acteur::new()
}
}
impl Acteur {
pub fn new() -> Acteur {
Acteur {
system_director: ADDRESS_BOOK.clone(),
}
}
pub async fn send<A: Actor + Handle<M>, M: Debug + Send + 'static>(
&self,
actor_id: A::Id,
message: M,
) {
self.system_director.send::<A, M>(actor_id, message).await;
}
pub fn send_sync<A: Actor + Handle<M>, M: Debug + Send + 'static>(
&self,
actor_id: A::Id,
message: M,
) {
task::block_on(async move { self.send::<A, M>(actor_id, message).await })
}
pub fn stop(&self) {
self.system_director.stop_all();
}
pub fn wait_until_stopped(&self) {
task::block_on(async { self.system_director.wait_until_stopped().await });
}
pub fn get_statistics(&self) -> Vec<(TypeId, Vec<ActorReport>)> {
self.system_director.get_statistics()
}
}
impl Debug for Acteur {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Acteur ()")
}
}
impl Clone for Acteur {
fn clone(&self) -> Self {
Acteur {
system_director: self.system_director.clone(),
}
}
}