Why do I get a DeathWatchNotification of an undelivered message on shutdown?

强颜欢笑 提交于 2019-12-25 11:57:53

问题


Why do a get a DeathWatchNotification when running this console app:

class Program
{
    private static ActorSystem TestSystem; 

    static void Main(string[] args)
    {
        TestSystem = ActorSystem.Create("TestSystem");
        TestSystem.ActorOf<TestActor>("Test");

        Console.WriteLine("Press a key to shutdown actor system");

        Console.ReadKey();
        TestSystem.Shutdown();
        TestSystem.AwaitTermination();

        Console.WriteLine("Press a key to quit");

        Console.ReadKey(); 
    }
}

public class TestActor : ReceiveActor
{
    public TestActor()
    {

    }
    protected override void Unhandled(object message)
    {
        Console.WriteLine("unhandled message");
        //Do something with the message.
    }

}

public class TestMessage
{

}

Obviously I haven't sent any messages and the actor doesn't do anything. It's not a huge deal but I'm concerned I'll miss a real problem if I ignore this message.


回答1:


As I understand, DeathWatchNotification is a special type of message, that actor sends to its watcher(s) when it's getting terminated. For example, consider this piece of code, that I got from the source of Akka.NET-1.0.4 (ActorCell.DeatWatch.cs file):

    private void SendTerminated(bool ifLocal, IActorRef watcher)
    {
        if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
        {
            watcher.Tell(new DeathWatchNotification(Self, true, false));
        }
    }


来源:https://stackoverflow.com/questions/32386573/why-do-i-get-a-deathwatchnotification-of-an-undelivered-message-on-shutdown

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