Java/Akka here. I have the following actor:
public class MyActor extends AbstractActor {
private Logger log = LoggerFactory.getLogger(this.getClass());
public MyActor() {
super();
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Init.class, init -> {
log.info("Sending myself a Poison Pill...");
self().tell(PoisonPill.getInstance(), self());
}).match(PoisonPill.class, poisonPill -> {
log.info("Got the Poison Pill...");
context().system().terminate();
}).build();
}
}
当接收到一个
Init
消息时,我看到以下日志记录:Sending myself a Poison Pill...
但我从未看到:
Got the Poison Pill...
此外,该应用程序只是停留在那里,无法按预期关闭。我在使用
self().tell(PoisonPill.getInstance(), self())
时是否有什么问题,阻止它接收消息并关闭?