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
use std::time::{Duration, Instant};

use crate::mixed::child_id::ChildID;
use crate::mixed::restart_intensity::RestartIntensity;

use super::common_decider::{CommonDecider, RestartType};
use super::RestartStrategy;

#[derive(Debug, Clone, Default)]
pub struct OneForOne {
    restart_intensity: RestartIntensity<Duration>,
}

#[derive(Debug, Clone, Default)]
pub struct AllForOne {
    restart_intensity: RestartIntensity<Duration>,
}

#[derive(Debug, Clone, Default)]
pub struct RestForOne {
    restart_intensity: RestartIntensity<Duration>,
}

impl OneForOne {
    pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
        Self { restart_intensity }
    }
}

impl AllForOne {
    pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
        Self { restart_intensity }
    }
}

impl RestForOne {
    pub fn new(restart_intensity: RestartIntensity<Duration>) -> Self {
        Self { restart_intensity }
    }
}

impl<ID> RestartStrategy<ID> for OneForOne
where
    ID: ChildID,
{
    type Decider = CommonDecider<ID, Duration, Instant>;

    fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
        CommonDecider::new(sup_id, RestartType::One, self.restart_intensity.to_owned())
    }
}

impl<ID> RestartStrategy<ID> for AllForOne
where
    ID: ChildID,
{
    type Decider = CommonDecider<ID, Duration, Instant>;

    fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
        CommonDecider::new(sup_id, RestartType::All, self.restart_intensity.to_owned())
    }
}

impl<ID> RestartStrategy<ID> for RestForOne
where
    ID: ChildID,
{
    type Decider = CommonDecider<ID, Duration, Instant>;

    fn new_decider(&self, sup_id: agner_actors::ActorID) -> Self::Decider {
        CommonDecider::new(sup_id, RestartType::Rest, self.restart_intensity.to_owned())
    }
}