From 10102c557f66365d213ed0d5963ff69ca3bd9bc6 Mon Sep 17 00:00:00 2001 From: Miha Jakovac Date: Mon, 14 Oct 2019 21:00:12 +0200 Subject: [PATCH 1/2] updated demo with 0.4.5 actors libraray with TestUntil. --- 01 PingPong/PingPong/PingPong.csproj | 4 ++-- 01 PingPong/PingPong/PingerActor.cs | 23 +++++++++++++------ 01 PingPong/PingPong/PongerActor.cs | 19 +++++++++++---- 01 PingPong/PingPong/Program.cs | 12 ++++++---- 01 PingPong/PingPong/vlingo-actors.json | 19 +++++++++++++++ 01 PingPong/PingPong/vlingo-actors.properties | 9 -------- README.md | 4 ++-- 7 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 01 PingPong/PingPong/vlingo-actors.json delete mode 100644 01 PingPong/PingPong/vlingo-actors.properties diff --git a/01 PingPong/PingPong/PingPong.csproj b/01 PingPong/PingPong/PingPong.csproj index 91aad8c..414ce84 100644 --- a/01 PingPong/PingPong/PingPong.csproj +++ b/01 PingPong/PingPong/PingPong.csproj @@ -7,11 +7,11 @@ - + - + Always diff --git a/01 PingPong/PingPong/PingerActor.cs b/01 PingPong/PingPong/PingerActor.cs index dcc50aa..a4f8c55 100644 --- a/01 PingPong/PingPong/PingerActor.cs +++ b/01 PingPong/PingPong/PingerActor.cs @@ -5,31 +5,40 @@ // was not distributed with this file, You can obtain // one at https://mozilla.org/MPL/2.0/. +using System; +using Vlingo.Actors.TestKit; + namespace Vlingo.Actors.Examples.PingPong { public class PingerActor : Actor, IPinger { private int count; - private readonly IPinger self; + private readonly TestUntil _until; - public PingerActor() + public PingerActor(TestUntil until) { count = 0; - self = SelfAs(); + _until = until; } public void Ping(IPonger ponger) { - if(++count >= 10) + if (++count >= 10) { - self.Stop(); + this.Stop(); ponger.Stop(); - System.Console.WriteLine("Enough ping/pong. Stopped now."); } else { - ponger.Pong(self); + Console.WriteLine($"Pinger {this.Address} - Doing Ping..."); + ponger.Pong(this); } } + + protected override void AfterStop() + { + Console.WriteLine("Pinger " + this.Address + " just stopped!"); + _until.Happened(); + } } } diff --git a/01 PingPong/PingPong/PongerActor.cs b/01 PingPong/PingPong/PongerActor.cs index f3a9a2e..e3be14d 100644 --- a/01 PingPong/PingPong/PongerActor.cs +++ b/01 PingPong/PingPong/PongerActor.cs @@ -5,20 +5,31 @@ // was not distributed with this file, You can obtain // one at https://mozilla.org/MPL/2.0/. +using System; +using Vlingo.Actors.TestKit; + namespace Vlingo.Actors.Examples.PingPong { public class PongerActor : Actor, IPonger { - private readonly IPonger self; + private readonly TestUntil _until; - public PongerActor() + public PongerActor(TestUntil until) { - self = SelfAs(); + _until = until; } public void Pong(IPinger pinger) { - pinger.Ping(self); + Console.WriteLine($"Ponger {this.Address} - Doing Pong..."); + pinger.Ping(this); + _until.Happened(); + } + + protected override void AfterStop() + { + Console.WriteLine("Ponger " + this.Address + " just stopped!"); + _until.Happened(); } } } diff --git a/01 PingPong/PingPong/Program.cs b/01 PingPong/PingPong/Program.cs index 92da140..c619718 100644 --- a/01 PingPong/PingPong/Program.cs +++ b/01 PingPong/PingPong/Program.cs @@ -6,6 +6,7 @@ // one at https://mozilla.org/MPL/2.0/. using System; +using Vlingo.Actors.TestKit; namespace Vlingo.Actors.Examples.PingPong { @@ -14,21 +15,24 @@ class Program static void Main(string[] args) { var world = World.Start("playground"); + var until = TestUntil.Happenings(1); var pinger = world.ActorFor( Definition.Has( - Definition.NoParameters)); + Definition.Parameters(until))); var ponger = world.ActorFor( Definition.Has( - Definition.NoParameters)); + Definition.Parameters(until))); pinger.Ping(ponger); - Console.WriteLine("Press any key to end the world..."); - Console.ReadKey(); + until.Completes(); world.Terminate(); + + Console.WriteLine("Press any key to end the world..."); + Console.ReadKey(); } } } diff --git a/01 PingPong/PingPong/vlingo-actors.json b/01 PingPong/PingPong/vlingo-actors.json new file mode 100644 index 0000000..28c3b5e --- /dev/null +++ b/01 PingPong/PingPong/vlingo-actors.json @@ -0,0 +1,19 @@ +{ + "plugin": { + "name": { + "queueMailbox": true, + "consoleLogger": true + }, + "queueMailbox": { + "classname": "Vlingo.Actors.Plugin.Mailbox.ConcurrentQueue.ConcurrentQueueMailboxPlugin", + "defaultMailbox": true, + "numberOfDispatchersFactor": 1, + "dispatcherThrottlingCount": 10 + }, + "consoleLogger": { + "classname": "Vlingo.Actors.Plugin.Logging.Console.ConsoleLoggerPlugin", + "name": "vlingo-net/actors", + "defaultLogger": true + } + } +} \ No newline at end of file diff --git a/01 PingPong/PingPong/vlingo-actors.properties b/01 PingPong/PingPong/vlingo-actors.properties deleted file mode 100644 index 8d1311a..0000000 --- a/01 PingPong/PingPong/vlingo-actors.properties +++ /dev/null @@ -1,9 +0,0 @@ -plugin.name.queueMailbox = true -plugin.queueMailbox.classname = Vlingo.Actors.Plugin.Mailbox.ConcurrentQueue.ConcurrentQueueMailboxPlugin -plugin.queueMailbox.defaultMailbox = true -plugin.queueMailbox.numberOfDispatchersFactor = 1 -plugin.queueMailbox.dispatcherThrottlingCount = 10 - -plugin.name.consoleLogger = true -plugin.consoleLogger.classname = Vlingo.Actors.Plugin.Logging.Console.ConsoleLoggerPlugin -plugin.consoleLogger.defaultLogger = true \ No newline at end of file diff --git a/README.md b/README.md index 87a1540..f9658b7 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ Various examples using [Vlingo .NET Actors](https://github.com/vlingo-net/vlingo-net-actors) library ## Examples -1. [PingPong](https://github.com/vlingo-net/vlingo-net-actors-examples/tree/master/01%20PingPong) (using Vlingo.Actors v0.3.5) +1. [PingPong](https://github.com/vlingo-net/vlingo-net-actors-examples/tree/master/01%20PingPong) (using Vlingo.Actors v0.4.5) License (See LICENSE file for full license) ------------------------------------------- -Copyright © 2012-2018 Vaughn Vernon. All rights reserved. +Copyright © 2012-2019 Vaughn Vernon. All rights reserved. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL From 7ebaf9ab631dc036d80ca4ddc437dc25eb53f4d1 Mon Sep 17 00:00:00 2001 From: Miha Jakovac Date: Mon, 14 Oct 2019 21:12:33 +0200 Subject: [PATCH 2/2] SelfAs added back --- 01 PingPong/PingPong/PingerActor.cs | 8 +++++--- 01 PingPong/PingPong/PongerActor.cs | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/01 PingPong/PingPong/PingerActor.cs b/01 PingPong/PingPong/PingerActor.cs index a4f8c55..6a458c6 100644 --- a/01 PingPong/PingPong/PingerActor.cs +++ b/01 PingPong/PingPong/PingerActor.cs @@ -14,30 +14,32 @@ public class PingerActor : Actor, IPinger { private int count; private readonly TestUntil _until; + private readonly IPinger self; public PingerActor(TestUntil until) { count = 0; _until = until; + self = SelfAs(); } public void Ping(IPonger ponger) { if (++count >= 10) { - this.Stop(); + self.Stop(); ponger.Stop(); } else { Console.WriteLine($"Pinger {this.Address} - Doing Ping..."); - ponger.Pong(this); + ponger.Pong(self); } } protected override void AfterStop() { - Console.WriteLine("Pinger " + this.Address + " just stopped!"); + Console.WriteLine($"Pinger {this.Address} just stopped!"); _until.Happened(); } } diff --git a/01 PingPong/PingPong/PongerActor.cs b/01 PingPong/PingPong/PongerActor.cs index e3be14d..ef38ec1 100644 --- a/01 PingPong/PingPong/PongerActor.cs +++ b/01 PingPong/PingPong/PongerActor.cs @@ -13,22 +13,24 @@ namespace Vlingo.Actors.Examples.PingPong public class PongerActor : Actor, IPonger { private readonly TestUntil _until; + private readonly IPonger self; public PongerActor(TestUntil until) { _until = until; + self = SelfAs(); } public void Pong(IPinger pinger) { Console.WriteLine($"Ponger {this.Address} - Doing Pong..."); - pinger.Ping(this); + pinger.Ping(self); _until.Happened(); } protected override void AfterStop() { - Console.WriteLine("Ponger " + this.Address + " just stopped!"); + Console.WriteLine($"Ponger {this.Address} just stopped!"); _until.Happened(); } }