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
157
158
159
use std::any::Any;
use std::fmt::Debug;
use crate::message::BoxedDowncastErr;
use crate::State;
use super::errors::ActorProcessingErr;
pub struct BoxedState {
pub msg: Option<Box<dyn Any + Send>>,
}
impl BoxedState {
pub fn new<T>(msg: T) -> Self
where
T: State,
{
Self {
msg: Some(Box::new(msg)),
}
}
pub fn take<T>(&mut self) -> Result<T, BoxedDowncastErr>
where
T: State,
{
match self.msg.take() {
Some(m) => {
if m.is::<T>() {
Ok(*m.downcast::<T>().unwrap())
} else {
Err(BoxedDowncastErr)
}
}
None => Err(BoxedDowncastErr),
}
}
}
pub enum StopMessage {
Stop,
Reason(String),
}
impl Debug for StopMessage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Stop message: {self}")
}
}
impl std::fmt::Display for StopMessage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Stop => write!(f, "Stop"),
Self::Reason(reason) => write!(f, "Stop (reason = {reason})"),
}
}
}
pub enum SupervisionEvent {
ActorStarted(super::actor_cell::ActorCell),
ActorTerminated(
super::actor_cell::ActorCell,
Option<BoxedState>,
Option<String>,
),
ActorPanicked(super::actor_cell::ActorCell, ActorProcessingErr),
ProcessGroupChanged(crate::pg::GroupChangeMessage),
#[cfg(feature = "cluster")]
PidLifecycleEvent(crate::registry::PidLifecycleEvent),
}
impl Debug for SupervisionEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Supervision event: {self}")
}
}
impl std::fmt::Display for SupervisionEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SupervisionEvent::ActorStarted(actor) => {
write!(f, "Started actor {actor:?}")
}
SupervisionEvent::ActorTerminated(actor, _, reason) => {
if let Some(r) = reason {
write!(f, "Stopped actor {actor:?} (reason = {r})")
} else {
write!(f, "Stopped actor {actor:?}")
}
}
SupervisionEvent::ActorPanicked(actor, panic_msg) => {
write!(f, "Actor panicked {actor:?} - {panic_msg}")
}
SupervisionEvent::ProcessGroupChanged(change) => {
write!(f, "Process group {} changed", change.get_group())
}
#[cfg(feature = "cluster")]
SupervisionEvent::PidLifecycleEvent(change) => {
write!(f, "PID lifecycle event {change:?}")
}
}
}
}
#[derive(Clone)]
pub enum Signal {
Kill,
}
impl Debug for Signal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Signal: {self}")
}
}
impl std::fmt::Display for Signal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Kill => {
write!(f, "killed")
}
}
}
}