forked from guanpengchn/java-concurrent-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyWorker.java
More file actions
40 lines (34 loc) · 1.01 KB
/
Copy pathMyWorker.java
File metadata and controls
40 lines (34 loc) · 1.01 KB
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
package ch7.s4;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class MyWorker extends UntypedActor {
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
public static enum Msg{
WORKING, DONE, CLOSE;
}
@Override
public void preStart() throws Exception {
System.out.println("MyWorker is starting");
}
@Override
public void postStop() throws Exception {
System.out.println("MyWorker is stopping");
}
@Override
public void onReceive(Object msg) throws Exception {
if(msg == Msg.WORKING){
System.out.println("I am working");
}
if(msg == Msg.DONE){
System.out.println("Stop working");
}
if(msg == Msg.CLOSE){
System.out.println("I will shutdown");
getSender().tell(Msg.CLOSE,getSelf());
getContext().stop(getSelf());
}else{
unhandled(msg);
}
}
}