Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated demo with 0.4.5 actors libraray with TestUntil. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 01 PingPong/PingPong/PingPong.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Vlingo.Actors" Version="0.3.5" />
<PackageReference Include="Vlingo.Actors" Version="0.4.5" />
</ItemGroup>

<ItemGroup>
<None Update="vlingo-actors.properties">
<None Update="vlingo-actors.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
17 changes: 14 additions & 3 deletions 01 PingPong/PingPong/PingerActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPinger>();
}

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();
}
}
}
15 changes: 14 additions & 1 deletion 01 PingPong/PingPong/PongerActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPonger>();
}

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();
}
}
}
12 changes: 8 additions & 4 deletions 01 PingPong/PingPong/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// one at https://mozilla.org/MPL/2.0/.

using System;
using Vlingo.Actors.TestKit;

namespace Vlingo.Actors.Examples.PingPong
{
Expand All @@ -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<IPinger>(
Definition.Has<PingerActor>(
Definition.NoParameters));
Definition.Parameters(until)));

var ponger = world.ActorFor<IPonger>(
Definition.Has<PongerActor>(
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();
}
}
}
19 changes: 19 additions & 0 deletions 01 PingPong/PingPong/vlingo-actors.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
9 changes: 0 additions & 9 deletions 01 PingPong/PingPong/vlingo-actors.properties

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down