private void Receiving()
        {
            Receive <PublishStatsTick>(stats =>
            {
                if (!Stats.IsEmpty)
                {
                    _logger.Info("Publishing {0} to parent", Stats);

                    Commander.Tell(Stats.Copy());

                    //reset our stats after publishing
                    Stats = Stats.Reset();
                }
            });

            //Received word from a ParseWorker that we need to check for new documents
            Receive <CheckDocuments>(documents =>
            {
                //forward this onto the downloads tracker, but have it reply back to our parent router so the work might get distributed more evenly
                DownloadsTracker.Tell(documents, Context.Parent);
            });

            //Update our local stats
            Receive <DiscoveredDocuments>(discovered =>
            {
                Stats = Stats.WithDiscovered(discovered);
            });

            //Received word from the DownloadTracker that we need to process some docs
            Receive <ProcessDocuments>(process =>
            {
                foreach (var doc in process.Documents)
                {
                    SourceActor.Tell(doc);
                }
            });

            //hand the work off to the downloaders
            Receive <IDownloadDocument>(download =>
            {
                SourceActor.Tell(download.Document);
            });

            Receive <CompletedDocument>(completed =>
            {
                _logger.Info("Logging completed download {0} bytes {1}", completed.Document.DocumentUri, completed.NumBytes);
                Stats = Stats.WithCompleted(completed);
                _logger.Info("Total stats {0}", Stats);
            });

            Receive <StreamCompleteTick>(_ =>
            {
                _logger.Info("Stream has completed. No more messages to process.");
            });
        }
Example #2
0
        private void Receiving()
        {
            Receive <PublishStatsTick>(stats =>
            {
                if (!Stats.IsEmpty)
                {
                    _logger.Info("Publishing {0} to parent", Stats);

                    Commander.Tell(Stats.Copy());

                    //reset our stats after publishing
                    Stats = Stats.Reset();
                }
            });

            //Received word from a ParseWorker that we need to check for new documents
            Receive <CheckDocuments>(documents =>
            {
                //forward this onto the downloads tracker, but have it reply back to us
                DownloadsTracker.Tell(documents);
            });

            //Update our local stats
            Receive <DiscoveredDocuments>(discovered =>
            {
                Stats = Stats.WithDiscovered(discovered);
            });

            //Received word from the DownloadTracker that we need to process some docs
            Receive <ProcessDocuments>(process =>
            {
                foreach (var doc in process.Documents)
                {
                    // Context.Parent is the router between the coordinators and the Commander
                    if (doc.IsImage)
                    {
                        Context.Parent.Tell(new DownloadWorker.DownloadImage(doc));
                    }
                    else
                    {
                        Context.Parent.Tell(new DownloadWorker.DownloadHtmlDocument(doc));
                    }
                }
            });

            //hand the work off to the downloaders
            Receive <DownloadWorker.IDownloadDocument>(download =>
            {
                DownloaderRouter.Tell(download);
            });

            Receive <CompletedDocument>(completed =>
            {
                //TODO: send verbose status messages to commander here?
                Stats = Stats.WithCompleted(completed);
            });

            /* Set all of our local downloaders to message our local parsers */
            Receive <DownloadWorker.RequestParseActor>(request =>
            {
                Sender.Tell(new DownloadWorker.SetParseActor(ParserRouter));
            });

            /* Set all of our local parsers to message our local downloaders */
            Receive <ParseWorker.RequestDownloadActor>(request =>
            {
                Sender.Tell(new ParseWorker.SetDownloadActor(DownloaderRouter));
            });
        }