-
Notifications
You must be signed in to change notification settings - Fork 77
/
App.cs
52 lines (42 loc) · 1.46 KB
/
App.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using Orleankka;
namespace Demo
{
public class App
{
readonly IActorSystem system;
readonly IClientObservable observable;
public App(IActorSystem system, IClientObservable observable)
{
this.system = system;
this.observable = observable;
}
public async void Run()
{
var facebook = system.ActorOf<IApi>("facebook");
var twitter = system.ActorOf<IApi>("twitter");
await facebook.Tell(new Subscribe(observable.Ref));
await twitter.Tell(new Subscribe(observable.Ref));
observable.Subscribe(LogToConsole);
foreach (var i in Enumerable.Range(1, 25))
{
var topic = system.ActorOf<ITopic>(i.ToString());
await topic.Tell(new CreateTopic("[" + i + "]", new Dictionary<ActorRef, TimeSpan>
{
{facebook, TimeSpan.FromMinutes(1)},
{twitter, TimeSpan.FromMinutes(1)},
}));
}
}
static void LogToConsole(object message)
{
var e = (AvailabilityChanged) message;
Log.Message(
!e.Available ? ConsoleColor.Red : ConsoleColor.Green,
!e.Available ? "*{0}* gone wild. Unavailable!" : "*{0}* is back available again!",
e.Api.Path.Id);
}
}
}