问题
I have an actor that is mysteriously dying, and I think the cause may be that someone is sending the actor a PoisonPill.
Is there a way for me to override the behavior of an actor when it receives a PoisonPill so that it logs the sender and the fact that it just received a PoisonPill? That is, of course, in addition to stopping the actor.
I am using 2.4.16, and in this version, PoisonPill behavior appears to be defined in a class called ActorCell. The problem is that this class is private and I have no way of accessing it.
I have also tried defining a case statement in the body of my actor's receive function, but testing this in a sandbox, it appears to do nothing.
So something like
def receive: Receive = {
case PoisonPill => println("I got poisoned.")
}
doesn't work.
I know that it is possible to put a logging message in the postStop method, but this does not allow me to determine the sender of the PoisonPill.
Is there some way to do what I have described?
来源:https://stackoverflow.com/questions/58810757/overriding-behavior-of-actor-on-receipt-of-poisonpill