Example #1
0
        private void StopPlayingCurrentMovie()
        {
            ColorConsole.WriteLineYellow(string.Format("User has stopped watching: {0}", _currentlyWatching));
            _currentlyWatching = null;

            Become(Stopped);
        }
Example #2
0
        private void Waiting()
        {
            _logger.Debug("Cordinator {0}'s current state is Waiting", Self.Path.Name);
            ColorConsole.WriteLineYellow("Coordinator {0} state is - Waiting.", Self.Path.Name);

            // Received CanAcceptJobMessage from coordinator
            Receive <CanAcceptJobMessage>(job =>
            {
                _logger.Debug("Cordinator {0} received CanAcceptJobMessage while in waiting state from {1} for Task ID: {2}",
                              Self.Path.Name, Sender.Path.Name, job.ID);

                Sender.Tell(new AbleToAcceptJobMessage(job.Description, job.ID));
            });

            // Received BeginJobMessage from coordinator
            Receive <JobStartedMessage>(job =>
            {
                _logger.Debug("Cordinator {0} received BeginJobMessage from {1} for Task ID: {2}",
                              Self.Path.Name, Sender.Path.Name, job.ID);

                ColorConsole.WriteLineGreen("Task {0} is processing by coordinator {1}.", job.ID, Self.Path.Name);
                // move to next state first
                BecomeWorking();

                // ask the worker for job
                _taskWorker.Tell(job);
            });
        }
        private void Playing()
        {
            Receive <PlayMovieMessage>(message => ColorConsole.WriteLineRed("Error: cannot start playing another movie before stopping existing one."));
            Receive <StopMovieMessage>(message => StopPlayingCurrentMovie());

            ColorConsole.WriteLineYellow("UserActor {0} has now become Playing", _userId);
        }
        private void Stopped()
        {
            Receive <PlayMovieMessage>(message => StartPlayingMovie(message.MovieTitle));
            Receive <StopMovieMessage>(message => ColorConsole.WriteLineRed("Error: cannot stop if nothing is playing"));

            ColorConsole.WriteLineYellow("UserActor has now become Stopped", _userId);
        }
Example #5
0
        private void StopPlayingCurrentMovie()
        {
            ColorConsole.WriteLineYellow("UserActor {0} has stopped watching '{1}'", _userId, _currentlyWatching);
            _currentlyWatching = null;

            Become(Stopped);
        }
Example #6
0
 private void HandleCalcMessage(CalcMessage msg)
 {
     ColorConsole.WriteLineYellow($"Calc V2 for {msg.LeftOperand} and {msg.RightOperand}");
     Thread.Sleep(5000);
     Sender.Tell(CalcVersionTwo(msg));
     ColorConsole.WriteLineCyan($"Result completed.");
 }
Example #7
0
 private void HandlePlayMovieMessage(PlayMovieMessage message)
 {
     ColorConsole.WriteLineYellow(
         string.Format("PlayMovieMessage '{0}' for user {1}",
                       message.MovieTitle,
                       message.UserId));
 }
Example #8
0
        private void StopPlayingCurrentMovie()
        {
            ColorConsole.WriteLineYellow($"Actor {_userId} is watching {_currentWatching}");

            _currentWatching = null;

            Become(Stopped);
        }
Example #9
0
        private void Stopped()
        {
            Receive <PlayMovieMessage>(message => StartPlayingMovie(message.MovieTitle));
            Receive <StopMovieMessage>(
                message => ColorConsole.WriteLineRed("cannot stop if nothing is playing"));

            ColorConsole.WriteLineYellow($"useractor {_userId} has become stopped");
        }
Example #10
0
        private void Stopped()
        {
            Receive <PlayMovieMessage>(message => StartPlayingMovie(message.MovieTitle));
            string messageText = $"UserActor {_userId} Error: cannot stop if nothing is playing";

            Receive <StopMovieMessage>(message => ColorConsole.WriteLineRed(messageText));
            ColorConsole.WriteLineYellow($"UserActor {_userId} has now become Stopped");
        }
Example #11
0
        private void Playing()
        {
            string messageText = $"UserActor {_userId} Error: cannot start playing another movie before stopping existing one";

            Receive <PlayMovieMessage>(message => ColorConsole.WriteLineRed(messageText));
            Receive <StopMovieMessage>(message => StopPlayingCurrentMovie());
            ColorConsole.WriteLineYellow($"UserActor {_userId} has now become Playing");
        }
Example #12
0
        private void StartPlayingMovie(string title)
        {
            _currentlyWatching = title;

            ColorConsole.WriteLineYellow("UserActor {0} is currently watching '{1}'", _userId, _currentlyWatching);

            Become(Playing);
        }
Example #13
0
        private void StartPlayingMovie(string title)
        {
            _currentlyWatching = title;

            ColorConsole.WriteLineYellow("UserActor {0} is currently watching '{1}'", _userId, _currentlyWatching);
            Context.ActorSelection("/user/Playback/PlayBackStatistics/MoviePlayCounter").Tell(new IncrementPlayCountMessage(title));
            Become(Playing);
        }
        private void StartPlayingMovie(string title)
        {
            _currentlyWatching = title;

            ColorConsole.WriteLineYellow(string.Format("User is currently watching '{0}'", _currentlyWatching));

            Become(Playing);
        }
Example #15
0
        private void StopPlayingCurrentMovie()
        {
            ColorConsole.WriteLineYellow("User {0} has stoppped watching {1}", UserID, currentlyWatching);
            currentlyWatching = null;

            // Switch Actor behavior from 'Playing' to 'Stopped'
            Become(Stopped);
        }
Example #16
0
        private void StopPlayingMusic()
        {
            ColorConsole.WriteLineYellow($"Stopped playing '{_currentlyPlaying}'");

            _currentlyPlaying = "";

            Become(Stopped);
        }
Example #17
0
        //private void HandleStopMovieMessage()
        //{
        //    if (string.IsNullOrEmpty(currentlyWatching))
        //    {
        //        ColorConsole.WriteLineRed(
        //            "Error: cannot stop if nothing is playing");
        //    }
        //    else
        //    {
        //        this.StopPlayingCurrentMovie();
        //    }
        //}

        private void StopPlayingCurrentMovie()
        {
            ColorConsole.WriteLineYellow(string.Format("UserActor {0} has stopped watching '{1}'", this.userId, this.currentlyWatching));

            this.currentlyWatching = null;

            this.Become(this.Stopped);
        }
Example #18
0
        private void StartPlayingMusic(string trackName)
        {
            _currentlyPlaying = trackName;

            ColorConsole.WriteLineYellow($"Currently playing '{_currentlyPlaying}'");

            Become(Playing);
        }
Example #19
0
        private void Playing()
        {
            Receive <PlayMovieMessage>(message =>
                                       ColorConsole.WriteLineRed("Error: A movie is already playing"));
            Receive <StopMovieMessage>
                (message => StopPlayingCurrentMovie());

            ColorConsole.WriteLineYellow("UserActor has now become playing");
        }
Example #20
0
        private void Stopped()
        {
            ColorConsole.WriteLineYellow(string.Format("UserActor {0} has now become Stopped", this.userId));

            this.Receive <PlayMovieMessage>(message => StartPlayingMovie(message.MovieTitle));
            this.Receive <StopMovieMessage>(
                message => ColorConsole.WriteLineRed(
                    string.Format("UserActor {0} Error: cannot stop if nothing is playing", this.userId)));
        }
Example #21
0
        private void Playing()
        {
            ColorConsole.WriteLineYellow(string.Format("UserActor {0} has now become Playing", this.userId));

            this.Receive <StopMovieMessage>(message => StopPlayingCurrentMovie());
            this.Receive <PlayMovieMessage>(
                message => ColorConsole.WriteLineRed(
                    string.Format("UserActor {0} Error: cannot start playing another movie before stopping existing one", this.userId)));
        }
Example #22
0
        private void HandleReportMessage(ReportMessage rpt)
        {
            var delay = Rnd.Next(5, 10);

            ColorConsole.WriteLineYellow($"Generating Report for Job #{rpt.JobId}. Should take { delay }s to finish.it");
            Thread.Sleep(delay * 1000);
            ColorConsole.WriteLineCyan($"{ ActorClassName } { _actorId }: Report '{rpt.ReportTitle}' for Job #{rpt.JobId} completed.");
            Sender.Tell($"Report #{rpt.JobId} completed.");
        }
Example #23
0
        private void StartPlayingMovie(string movieTitle)
        {
            _currentlyWatching = movieTitle;
            ColorConsole.WriteLineYellow(string.Format("User currently playing movie: {0}", movieTitle));

            Context.ActorSelection("/user/Playback/PlaybackStatistics/MoviePlayCounter")
            .Tell(new IncrementPlayCountMessage(movieTitle));

            Become(Playing);
        }
Example #24
0
        private void StartPlayingMovie(string movieTitle)
        {
            currentlyWatching = movieTitle;
            ColorConsole.WriteLineYellow("User {0} is currently watching {1}", UserID, currentlyWatching);

            Context.ActorSelection(Constants.ActorsSelectionPaths.MoviePlayCounter).Tell(new IncrementPlayCountMessage(movieTitle));

            // Switch Actor behavior from 'Stopped' to 'Playing'
            Become(Playing);
        }
Example #25
0
        private void Playing()
        {
            // Defines what happens when we receive a PlayMovieMessage while we are in a Playing state.
            Receive <PlayMovieMessage>(message => ColorConsole.WriteLineRed("Error: cannot start playing another movie before stopping existing one"));

            // Defines what happens when we receive a StopMovieMessage while we are in a Playing state.
            Receive <StopMovieMessage>(message => StopPlayingCurrentMovie());

            ColorConsole.WriteLineYellow("UserActor {0} has now become Playing", UserID.ToString());
        }
Example #26
0
        private void Playing()
        {
            Receive <PlayMovieMessage>(message => ColorConsole.WriteLineRed(
                                           "cannot start playing another movie"));

            Receive <StopMovieMessage>(
                message => StopPlayingCurrentMovie());

            ColorConsole.WriteLineYellow($"useractor {_userId} has become playing");
        }
        private void StartPlayingMovie(string movieTitle)
        {
            _currentlyWatching = movieTitle;
            ColorConsole.WriteLineYellow($"UserActor {_id} is currently watching '{_currentlyWatching}'");

            Context.ActorSelection("/user/Playback/PlaybackStatistics/MoviePlayCounter")
            .Tell(new IncrementPlayCountMessage(movieTitle));

            Become(Playing);
        }
Example #28
0
        private void Stopped()
        {
            // Defines what happens when we receive a PlayMovieMessage while we are in a Stopped state.
            Receive <PlayMovieMessage>(message => StartPlayingMovie(message.MovieTitle));

            // Defines what happens when we receive a StopMovieMessage while we are in a Stopped state.
            Receive <StopMovieMessage>(message =>
                                       ColorConsole.WriteLineRed("Error: cannot stop if nothing is playing")
                                       );

            ColorConsole.WriteLineYellow("UserActor {0} has now become Stopped", UserID);
        }
Example #29
0
 private void HandleProcessJob()
 {
     if (_jobsToProcessed.Count > 0)
     {
         _currentJobMsg = _jobsToProcessed[0];
         Context.ActorSelection(ActorPaths.ValidatorActor.Path).Ask(_currentJobMsg.Description).PipeTo(Self);
         _jobsToProcessed.RemoveAt(0);
     }
     else
     {
         ColorConsole.WriteLineYellow("All jobs are processed from job pool queue..");
         _jobScheduler.Cancel();
     }
 }
        public JobPoolControllerActor(IActorRef commanderActor)
        {
            _commander = commanderActor;
            Receive <ProcessFileMessage>(msg => InitializeJobs(msg.FileName));
            Receive <UnableToAcceptJobMessage>(job =>
            {
                ColorConsole.WriteLineRed($"Commander {Sender.Path} is unable to perform Task : {job.Description}");
                if (!_jobsToProcessed.ContainsKey(job.ID))
                {
                    if (_taskList[job.ID].Status == JobStatus.NotStarted)
                    {
                        _jobsToProcessed.Add(job.ID, new ProcessJobMessage(job.Description, job.ID, Self));
                    }
                }
            });

            Receive <JobStartedMessage>(job =>
            {
                ColorConsole.WriteLineGreen($"Task {job.ID}. {job.Description} has started by {Sender.Path} at {job.ProcessedTime}");
                var task       = _taskList[job.ID];
                task.StartTime = job.ProcessedTime;
                task.Status    = JobStatus.Started;
                if (null == _stopWatch)
                {
                    _stopWatch = new Stopwatch();
                    _stopWatch.Start();
                }
                // update UI
            });

            Receive <JobCompletedMessage>(job =>
            {
                ColorConsole.WriteLineYellow($"Task {job.ID}. {job.Description} has completed succesfully at {job.ProcessedTime} by {Sender.Path} in {job.Duration} ms.");
                var task      = _taskList[job.ID];
                task.EndTime  = job.ProcessedTime;
                task.Duration = job.Duration;
                task.Status   = JobStatus.Completed;
                // update UI
            });

            Receive <JobFailedMessage>(job =>
            {
                ColorConsole.WriteLineRed($"Commander {Sender.Path} is unable to perform Task : {job.Description} because {job.Status.ToString()}");
                _taskList[job.ID].Status = job.Status;
                // update UI
            });

            Receive <ProcessUnfinishedJobs>(msg => HandleProcessUnFinishedJobs(msg));
        }