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
<configuration> | |
<configSections> | |
<section name="akka" | |
type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" /> | |
</configSections> | |
<startup> | |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | |
</startup> |
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
public class Message | |
{ | |
public string Text { get; private set; } | |
public Message(string text) | |
{ | |
Text = text; | |
} | |
} |
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
public class MessageProcessor : ReceiveActor | |
{ | |
public MessageProcessor() | |
{ | |
Receive<Message>(message => Console.WriteLine("Received a message with text: {0}", message.Text)); | |
} | |
} |
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
public class Program | |
{ | |
static void Main(string[] arg) | |
{ | |
var system = ActorSystem.Create("ActorSystem"); | |
var actor = system.ActorOf<MessageProcessor>("actor"); | |
actor.Tell(new Message("This is first message!")); | |
Console.ReadLine(); |
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
public abstract class Message | |
{ | |
public string User { get; private set; } | |
public string Article { get; private set; } | |
public Message(string user, string article) | |
{ | |
User = user; | |
Article = article; | |
} |
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
public class StartedReadingMessage : Message | |
{ | |
public StartedReadingMessage(string user, string article) | |
: base(user, article) {} | |
} | |
class StopedReadingMessage : Message | |
{ | |
public StopedReadingMessage(string user, string article) | |
: base (user, article) {} |
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
static void Main(string[] args) | |
{ | |
ActorSystem system = ActorSystem.Create("rubikscode"); | |
IActorRef blogActor = system.ActorOf(Props.Create(typeof(BlogActor)), "blog"); | |
blogActor.Tell(new StartedReadingMessage("NapoleonHill", "Tuples in .NET world and C# 7.0 improvements")); | |
// Used for simulation. | |
Thread.Sleep(1000); |
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
public class BlogActor : ReceiveActor | |
{ | |
private IActorRef _users; | |
private IActorRef _reporting; | |
public BlogActor() | |
{ | |
_users = Context.ActorOf(Props.Create(typeof(UsersActor)), "users"); | |
_reporting = Context.ActorOf(Props.Create(typeof(ReportActor)), "reporting"); |
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
public class UsersActor : ReceiveActor | |
{ | |
private Dictionary<string, IActorRef> _users; | |
public UsersActor() | |
{ | |
_users = new Dictionary<string, IActorRef>(); | |
Receive<StartedReadingMessage>(message => ReceivedStartMessage(message)); | |
Receive<StopedReadingMessage>(message => ReceivedStopMessage(message)); |
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
public class UserActor : ReceiveActor | |
{ | |
private Stopwatch _stopwatch; | |
private bool _isAlreadyReading; | |
public UserActor() | |
{ | |
_stopwatch = new Stopwatch(); | |
Receive<StartedReadingMessage>(message => ReceivedStartMessage(message)); | |
Receive<StopedReadingMessage>(message => ReceivedStopMessage(message)); |