Last active
August 29, 2015 14:20
-
-
Save ralfw/8b5e796f5012f549b170 to your computer and use it in GitHub Desktop.
Akka Question
This file contains hidden or 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 System.Windows.Forms; | |
using Akka.Actor; | |
namespace spike.akka | |
{ | |
static class Program | |
{ | |
[STAThread] | |
static void Main() | |
{ | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
var sys = ActorSystem.Create("MyActorSystem"); | |
var bodyActorProps = Props.Create<BodyActor>(); | |
var bodyActor = sys.ActorOf(bodyActorProps, "BodyActor"); | |
var dlg = new Form1(); | |
var headActorProps = Props.Create<HeadActor>(dlg, bodyActor) | |
.WithDispatcher("akka.actor.synchronized-dispatcher"); | |
var headActor = sys.ActorOf(headActorProps, "HeadActor"); | |
Application.Run(dlg); | |
} | |
} | |
internal class HeadActor : ReceiveActor | |
{ | |
public HeadActor(Form1 dlg, IActorRef onDataEntered) | |
{ | |
dlg.OnDataEntered += msg => { | |
Console.WriteLine("head {0}", System.Threading.Thread.CurrentThread.GetHashCode()); | |
onDataEntered.Tell(msg); | |
}; | |
// Why aren't any messages received here from BodyActor? | |
Receive<string>(msg => { | |
dlg.Display_message(msg); | |
}); | |
} | |
} | |
internal class BodyActor : ReceiveActor | |
{ | |
public BodyActor() | |
{ | |
Receive<string>(msg => | |
{ | |
Console.WriteLine("body {0}", System.Threading.Thread.CurrentThread.GetHashCode()); | |
this.Sender.Tell(msg.ToUpper()); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment