Created
June 12, 2015 06:22
-
-
Save pawelpabich/651d729a2a6ce2b1a909 to your computer and use it in GitHub Desktop.
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 System.Threading; | |
using Akka.Actor; | |
namespace Actors | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var system = ActorSystem.Create("MySystem"); | |
var parent = system.ActorOf<Parent>("parent"); | |
parent.Tell(new Greet(DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString())); | |
Console.ReadLine(); | |
} | |
} | |
public class Greet | |
{ | |
public Greet(string who) | |
{ | |
Who = who; | |
} | |
public string Who { get; private set; } | |
} | |
public class Parent : ReceiveActor | |
{ | |
public Parent() | |
{ | |
var child = Context.ActorOf<ChildActor>(); | |
// Tell the actor to respond | |
// to the Greet message | |
Receive<Greet>(greet => | |
{ | |
Console.WriteLine("Parent"); | |
child.Tell(greet); | |
}); | |
Receive<Terminated>(t => | |
{ | |
Console.WriteLine("Terminated"); | |
}); | |
} | |
protected override bool AroundReceive(Receive receive, object message) | |
{ | |
return base.AroundReceive(receive, message); | |
} | |
} | |
public class ChildActor :ReceiveActor | |
{ | |
public ChildActor() | |
{ | |
Receive<Greet>(greet => | |
{ | |
Console.WriteLine("Child"); | |
Thread.Sleep(5000); | |
if (DateTime.Now.Day == 12) throw new Exception("Throwing exception for the child actor."); | |
}); | |
} | |
protected override void PreRestart(Exception reason, object message) | |
{ | |
base.PreRestart(reason, message); | |
} | |
protected override void PostRestart(Exception reason) | |
{ | |
base.PostRestart(reason); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment