Overriding behavior of actor on receipt of PoisonPill

自古美人都是妖i 提交于 2019-12-24 22:29:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!