agner_sup/mixed/restart_strategy/
strategies.rs1use std::time::{Duration, Instant};
2
3use crate::mixed::child_id::ChildID;
4use crate::mixed::restart_intensity::RestartIntensity;
5
6use super::common_decider::{CommonDecider, RestartType};
7use super::RestartStrategy;
8
9#[derive(Debug, Clone, Default)]
10pub struct OneForOne {
11 restart_intensity: RestartIntensity<Duration>,
12}
13
14#[derive(Debug, Clone, Default)]
15pub struct AllForOne {
16 restart_intensity: RestartIntensity<Duration>,
17}
18
19#[derive(Debug, Clone, Default)]
20pub struct RestForOne {
21 restart_intensity: RestartIntensity<Duration>,
22}
23
24impl OneForOne {
25 pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
26 Self { restart_intensity }
27 }
28}
29
30impl AllForOne {
31 pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
32 Self { restart_intensity }
33 }
34}
35
36impl RestForOne {
37 pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
38 Self { restart_intensity }
39 }
40}
41
42impl<ID> RestartStrategy<ID> for OneForOne
43where
44 ID: ChildID,
45{
46 type Decider = CommonDecider<ID, Duration, Instant>;
47
48 fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
49 CommonDecider::new(sup_id, RestartType::One, self.restart_intensity.to_owned())
50 }
51}
52
53impl<ID> RestartStrategy<ID> for AllForOne
54where
55 ID: ChildID,
56{
57 type Decider = CommonDecider<ID, Duration, Instant>;
58
59 fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
60 CommonDecider::new(sup_id, RestartType::All, self.restart_intensity.to_owned())
61 }
62}
63
64impl<ID> RestartStrategy<ID> for RestForOne
65where
66 ID: ChildID,
67{
68 type Decider = CommonDecider<ID, Duration, Instant>;
69
70 fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
71 CommonDecider::new(sup_id, RestartType::Rest, self.restart_intensity.to_owned())
72 }
73}