forked from petabridge/akka-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTailCoordinatorActor.cs
73 lines (60 loc) · 2.14 KB
/
TailCoordinatorActor.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
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using Akka.Actor;
namespace WinTail
{
public class TailCoordinatorActor : UntypedActor
{
#region Message types
/// <summary>
/// Start tailing the file at user-specified path.
/// </summary>
public class StartTail
{
public StartTail(string filePath, IActorRef reporterActor)
{
FilePath = filePath;
ReporterActor = reporterActor;
}
public string FilePath { get; private set; }
public IActorRef ReporterActor { get; private set; }
}
/// <summary>
/// Stop tailing the file at user-specified path.
/// </summary>
public class StopTail
{
public StopTail(string filePath)
{
FilePath = filePath;
}
public string FilePath { get; private set; }
}
#endregion
protected override void OnReceive(object message)
{
if (message is StartTail)
{
var msg = message as StartTail;
Context.ActorOf(Props.Create(() => new TailActor(msg.ReporterActor, msg.FilePath)));
}
}
// here we are overriding the default SupervisorStrategy
// which is a One-For-One strategy w/ a Restart directive
protected override SupervisorStrategy SupervisorStrategy()
{
return new OneForOneStrategy (
10, // maxNumberOfRetries
TimeSpan.FromSeconds(30), // duration
x =>
{
//Maybe we consider ArithmeticException to not be application critical
//so we just ignore the error and keep going.
if (x is ArithmeticException) return Directive.Resume;
//Error that we cannot recover from, stop the failing actor
else if (x is NotSupportedException) return Directive.Stop;
//In all other cases, just restart the failing actor
else return Directive.Restart;
});
}
}
}