Created
June 17, 2015 06:30
-
-
Save AndrewEgorov/53bbbcbd891bea6b4c3e to your computer and use it in GitHub Desktop.
Sample code which reproduce problem with killing remote child 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 RemoteDeploy.Shared | |
{ | |
public class KillMe | |
{ | |
public static KillMe Instance = new KillMe(); | |
} | |
public class EchoActor : ReceiveActor | |
{ | |
public EchoActor() | |
{ | |
Become(Idle); | |
} | |
public void Idle() | |
{ | |
Receive<Hello>(msg => | |
{ | |
Console.WriteLine("Received msg from {0}: {1}", Sender.Path, msg.Message); | |
Sender.Tell(KillMe.Instance); | |
}); | |
} | |
} | |
} |
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; | |
using Akka.Configuration; | |
using RemoteDeploy.Shared; | |
namespace RemoteDeploy.Deployer | |
{ | |
class Program | |
{ | |
public class DeployActor | |
{ | |
public Address Address { get; private set; } | |
public string ActorName { get; private set; } | |
public DeployActor(Address address, string actorName) | |
{ | |
Address = address; | |
ActorName = actorName; | |
} | |
} | |
public class Server : ReceiveActor | |
{ | |
public Server() | |
{ | |
Become(Idle); | |
} | |
public void Idle() | |
{ | |
Receive<DeployActor>(msg => | |
{ | |
Props actorProp = | |
Props.Create(() => new EchoActor()).WithDeploy(Deploy.None.WithScope(new RemoteScope(msg.Address))); | |
//Second time you'll get exception here because in KillMe msg actor wasn't removed from context; | |
var actor = Context.ActorOf(actorProp, msg.ActorName); | |
actor.Tell(new Hello("Hello from server")); | |
}); | |
Receive<KillMe>(msg => | |
{ | |
//Here i need correctly handle deleting of remote child actor, so after receiving | |
//DeployActor msg again this child has been removed from current context | |
Console.WriteLine("Killing {0}", Sender.Path); | |
Context.Stop(Sender); | |
}); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var system = ActorSystem.Create("TestSystem", ConfigurationFactory.ParseString(@" | |
akka { | |
actor{ | |
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" | |
} | |
remote { | |
helios.tcp { | |
port = 0 | |
hostname = localhost | |
} | |
} | |
}")); | |
var server = system.ActorOf(Props.Create(() => new Server()), "Server"); | |
var remoteAddress = Address.Parse("akka.tcp://DeployTarget@localhost:8090"); | |
server.Tell(new DeployActor(remoteAddress, "TestActorName")); | |
Console.ReadLine(); | |
//Just for sample, wait a little while we kill remote child actor first time adn then press any key again | |
//to send DeployActor msg to Server | |
while (Console.ReadLine() != "exit") | |
{ | |
server.Tell(new DeployActor(remoteAddress, "TestActorName")); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment