Created
December 15, 2017 19:55
-
-
Save goblinfactory/1fce6afe3480d8e7a8a30ae5cc30dbf3 to your computer and use it in GitHub Desktop.
Akka.net supervision not resuming actor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Akka.Actor; | |
namespace AkkaSample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// todo find out how to inject dependancies into actors | |
using (var sys = ActorSystem.Create("games")) | |
{ | |
var counter = sys.ActorOf(Props.Create<ArrayCounter>()); | |
counter.Tell(new [] {"cat", "mouses", "four", "five", null, "humpty dumpty", "six", "seven" }); | |
Console.ReadLine(); | |
counter.Tell("stop", ActorRefs.NoSender); | |
} | |
} | |
} | |
public class ArrayCounter : UntypedActor | |
{ | |
protected override SupervisorStrategy SupervisorStrategy() | |
{ | |
return new OneForOneStrategy(d=> Directive.Resume, false); | |
} | |
protected override void PreRestart(Exception reason, object message) | |
{ | |
Console.Write(" restarting (string counter) " + reason.Message); | |
base.PreRestart(reason, message); | |
} | |
private int _total; | |
protected override void OnReceive(object message) | |
{ | |
if (message is int num) | |
{ | |
_total += num; | |
Console.Write($" {_total} "); | |
} | |
if (message is string[] messages) | |
{ | |
foreach (var msg in messages) | |
{ | |
var actor = Context.ActorOf<StringLengthCounter>(); | |
actor.Tell(msg); | |
} | |
} | |
} | |
} | |
public class StringLengthCounter : UntypedActor | |
{ | |
private static int _cnt = 0; | |
protected override void OnReceive(object message) | |
{ | |
if (message is string text) | |
{ | |
if (++_cnt > 2) | |
{ | |
if (string.IsNullOrWhiteSpace(text)) Sender.Tell(0); | |
} | |
Sender.Tell(text.Length); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok.. tried the above out in akka (JVM version)
it moans because you're trying to
tell
a null message in your loop on line 51.worth seeing if akka.net is the same.. I.e. an arg exception.. your
ArrayCounter
isn't supervised.. appart from the default..so that could be why.