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
#[macro_use]
extern crate log;
extern crate riker;
use riker::actors::*;
use riker::actor::All;
use riker::system::DeadLetterProps;
pub struct DeadLettersActor<Msg: Message> {
dl: ActorRef<Msg>,
}
impl<Msg: Message> DeadLettersActor<Msg> {
fn new(dl: ActorRef<Msg>) -> BoxActor<Msg> {
let actor = DeadLettersActor {
dl,
};
Box::new(actor)
}
}
impl<Msg: Message> Actor for DeadLettersActor<Msg> {
type Msg = Msg;
fn pre_start(&mut self, ctx: &Context<Self::Msg>) {
let msg = ActorMsg::Channel(ChannelMsg::Subscribe(All.into(), ctx.myself()));
self.dl.tell(msg, None);
}
fn other_receive(&mut self, _: &Context<Msg>, msg: ActorMsg<Msg>, _: Option<ActorRef<Msg>>) {
if let ActorMsg::DeadLetter(dl) = msg {
info!("DeadLetter: {} => {} ({:?})", dl.sender, dl.recipient, dl.msg)
}
}
fn receive(&mut self, _: &Context<Msg>, _: Msg, _: Option<ActorRef<Msg>>) {}
}
impl<Msg: Message> DeadLetterProps for DeadLettersActor<Msg> {
type Msg = Msg;
fn props(dl: ActorRef<Msg>) -> BoxActorProd<Msg> {
Props::new_args(Box::new(DeadLettersActor::new), dl)
}
}