コード例 #1
0
        //----HANDLERS----//

        // Sentence cleanup
        private void CleanUpSentence(string content)
        {
            // Trim by typical sentence symbols
            char[] symbolsToTrim = new char[] { '.', ',', ';', '?', '!' };

            // Initialize a new list where words will be cleaned up
            List <string> cleanSentence = new List <string>();

            // Clean up each word in provided sentence
            Array.ForEach(content.Split(' '), (c) => {
                cleanSentence.Add(c.Trim(symbolsToTrim));
            });

            // Send the newly cleaned sentence back
            TrimmedSentence trimmed = new TrimmedSentence(
                String.Join(" ", cleanSentence), cleanSentence.Count);

            Sender.Tell(trimmed);
        }
コード例 #2
0
        // PickerActor handler
        // TODO - have the chunks returned in order
        private void OnReceiveTrimmedSentence(TrimmedSentence t)
        {
            // Initialize PickerActors with a RoundRobin router
            _pickers = Context.ActorOf(Props.Create <PickerActor>()
                                       .WithRouter(new RoundRobinPool(t.WordCount)), "picker");

            // Split the trimmed sentence and assign each word to one worker
            var splitTrimmed = t.Content.Split(' ');

            splitTrimmed.ForEach(word =>
            {
                // For each word in array, send it to a picker actor to process (with index)
                _pickers.Tell(new Word(word, word.Length, splitTrimmed.ToList().IndexOf(word)));
            });

            // After all workers have finished, kill them
            _pickers.Tell(new Broadcast(PoisonPill.Instance));

            // Watch router and workers
            Context.Watch(_pickers);
        }