-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathParserActor.cs
38 lines (31 loc) · 1.05 KB
/
ParserActor.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
using Akka.Actor;
using Akka.Event;
namespace AkkaWordCounter;
using static DocumentCommands;
using static CounterCommands; // make message handlers less verbose
public sealed class ParserActor : UntypedActor {
private readonly ILoggingAdapter _log = Context.GetLogger();
private readonly IActorRef _countingActor;
public ParserActor(IActorRef countingActor)
{
_countingActor = countingActor;
}
private const int TokenBatchSize = 10;
protected override void OnReceive(object message){
switch(message){
case ProcessDocument process:
{
// chunk tokens into buckets of 10
foreach(var tokenBatch in process.RawText.Split(" ").Chunk(TokenBatchSize)){
_countingActor.Tell(new CountTokens(tokenBatch));
}
// we are finished
_countingActor.Tell(new ExpectNoMoreTokens());
break;
}
default:
Unhandled(message);
break;
}
}
}