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..6a458c6 100644 --- a/01 PingPong/PingPong/PingerActor.cs +++ b/01 PingPong/PingPong/PingerActor.cs @@ -5,31 +5,42 @@ // 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 TestUntil _until; private readonly IPinger self; - public PingerActor() + public PingerActor(TestUntil until) { count = 0; + _until = until; self = SelfAs(); } public void Ping(IPonger ponger) { - if(++count >= 10) + if (++count >= 10) { self.Stop(); ponger.Stop(); - System.Console.WriteLine("Enough ping/pong. Stopped now."); } else { + Console.WriteLine($"Pinger {this.Address} - Doing Ping..."); ponger.Pong(self); } } + + 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..ef38ec1 100644 --- a/01 PingPong/PingPong/PongerActor.cs +++ b/01 PingPong/PingPong/PongerActor.cs @@ -5,20 +5,33 @@ // 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 TestUntil _until; private readonly IPonger self; - public PongerActor() + public PongerActor(TestUntil until) { + _until = until; self = SelfAs(); } public void Pong(IPinger pinger) { + Console.WriteLine($"Ponger {this.Address} - Doing Pong..."); pinger.Ping(self); + _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