-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitoring.java
59 lines (46 loc) · 1.69 KB
/
Monitoring.java
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
import akka.actor.*;
import akka.japi.pf.ReceiveBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Monitoring {
private static final Logger LOGGER = LoggerFactory.getLogger(Monitoring.class);
private static class Ares extends AbstractActor {
private final ActorRef athena;
public Ares(ActorRef athena) {
this.athena = athena;
receive(ReceiveBuilder
.match(Terminated.class, msg -> {
LOGGER.info("Ares received Terminated");
context().stop(self());
})
.build());
}
@Override
public void preStart() throws Exception {
context().watch(athena);
}
@Override
public void postStop() throws Exception {
LOGGER.info("Ares postStop");
}
}
private static class Athena extends AbstractActor {
public Athena() {
receive(ReceiveBuilder
.match(Object.class, msg -> {
LOGGER.info(String.format("Athena received %s", msg));
context().stop(self());
})
.build());
}
}
public static void main(String[] args) throws InterruptedException {
// Create the 'monitoring' actor system
ActorSystem system = ActorSystem.create("monitoring");
ActorRef athena = system.actorOf(Props.create(Athena.class), "athena");
ActorRef ares = system.actorOf(Props.create(Ares.class, athena), "ares");
athena.tell("Hi", ActorRef.noSender());
Thread.sleep(500);
system.terminate();
}
}