-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlutoActor.cs
59 lines (49 loc) · 1.84 KB
/
PlutoActor.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
53
54
55
56
57
58
59
using System;
using System.Diagnostics;
using Akka.Actor;
using Akka.Dispatch.SysMsg;
using Akka.Event;
namespace Akka.Monitoring.NewRelic.Demo
{
public class PlutoActor : ReceiveActor
{
private Stopwatch _stopwatch;
public class YoureMyMoon { }
public PlutoActor()
{
Context.IncrementActorCreated();
var random = new Random();
Receive<CharonActor.ImYourMoon>(_ =>
{
Context.IncrementMessagesReceived();
Sender.Tell(new YoureMyMoon());
});
Receive<CharonActor.WeGoRoundAndRound>(_ =>
{
Context.IncrementMessagesReceived();
_stopwatch = Stopwatch.StartNew();
Context.GetLogger().Info("Start \"revolving\"");
var cancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.Zero, TimeSpan.FromSeconds(1), Self, "revolve", Self);
Context.GetLogger().Info("Stop \"revolving\"");
Context.System.Scheduler.ScheduleTellOnce(TimeSpan.FromSeconds(5), Self, cancelable, Self);
});
Receive<string>(_ =>
{
Context.IncrementCounter("revolutions");
Context.GetLogger().Debug("Whee!");
Context.Gauge("revolutions.enjoyment", random.Next(1, 11));
});
Receive<ICancelable>(cancelable =>
{
cancelable.Cancel();
Context.Timing("revolutions.elapsed", _stopwatch.ElapsedMilliseconds);
Context.GetLogger().Warning("... the rest of the world seems so small");
Self.Tell(PoisonPill.Instance);
});
Receive<Stop>(_ =>
{
Context.IncrementActorStopped();
});
}
}
}