private void Playing() { Receive <PlayMovieMessage>( message => Colorconsole.WriteLineRed( "Error: cannont start playing another movie before stopping existing one")); Receive <StopMovieMessage>(message => StopPlayingCurrentMovie()); }
private void StopPlayingCurrentMovie() { Colorconsole.WriteLineYellow($"user has stoped watching {_currentlyWatching}"); _currentlyWatching = null; Become(Stopped); Colorconsole.WriteLineYellow("UserActore has become Stopped"); }
private void StartPlayingMovie(string movieTitle) { _currentlyWatching = movieTitle; Colorconsole.WriteLineYellow($"UserActor {_userId } is currently watching {_currentlyWatching}"); Context.ActorSelection("/user/Playback/PlaybackStatistics/MoviePlayCounter").Tell(new IncrementPlayCountMessage(movieTitle)); Become(Playing); Colorconsole.WriteLineCyan("UserActor has now become Playing"); }
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"); }
private void CreateChildUserIfNotExist(int userId) { if (!_users.ContainsKey(userId)) { IActorRef newChildActorRef = Context.ActorOf(Props.Create(() => new UserActor(userId)), "User" + userId); _users.Add(userId, newChildActorRef); Colorconsole.WriteLineCyan($"UserCoordinatorActor created new child UserActor for {userId} (Total User: {_users.Count})"); } }
private void HandleIncrementMessage(IncrementPlayCountMessage message) { if (_moviePlayCounts.ContainsKey(message.MovieTitle)) { _moviePlayCounts[message.MovieTitle] += 1; } else { _moviePlayCounts.Add(message.MovieTitle, 1); } // Simulated Bugs if (_moviePlayCounts[message.MovieTitle] > 3) { throw new SimulatedCorruptStateException(); } if (message.MovieTitle == "Partial Recoil") { throw new SimulatedTerribleMovieException(); } Colorconsole.WriteLineMagenta($"MoviePlayCounterActor {message.MovieTitle} has been watched {_moviePlayCounts[message.MovieTitle]} times"); }
protected override void PostRestart(Exception reason) { Colorconsole.WriteLineGreen($"PlaybackActor PreReStart because: {reason}"); base.PostRestart(reason); }
protected override void PostStop() { Colorconsole.WriteLineGreen("PlaybackActor PostStop"); }
protected override void PreStart() { Colorconsole.WriteLineGreen("PlaybackActor PreStart"); }
protected override void PostRestart(Exception reason) { Colorconsole.WriteLineYellow($"UserActor PreReStart because: {reason}"); base.PostRestart(reason); }
protected override void PreStart() { Colorconsole.WriteLineCyan("UserCoordinatorActor PreStart"); }
protected override void PostRestart(Exception reason) { Colorconsole.WriteLineMagenta($"PlaybackStatisticsActor PostRestart because: {reason}"); base.PostRestart(reason); }
protected override void PostStop() { Colorconsole.WriteLineMagenta("PlaybackStatisticsActor PostStop"); }
protected override void PostRestart(Exception reason) { Colorconsole.WriteLineCyan($"UserCoordinatorActor PostRestart because: {reason}"); base.PostRestart(reason); }
protected override void PostStop() { Colorconsole.WriteLineCyan("UserCoordinatorActor PostStop"); }
protected override void PreStart() { Colorconsole.WriteLineMagenta("PlaybackStatisticsActor PreStart"); }
protected override void PreStart() { Colorconsole.WriteLineYellow("UserActor PreStart"); }
protected override void PreRestart(Exception reason, object message) { Colorconsole.WriteLineMagenta($"PlaybackStatisticsActor PreRestart because: {reason}"); base.PreRestart(reason, message); }
protected override void PostStop() { Colorconsole.WriteLineYellow("UserActor PostStop"); }
static void Main(string[] args) { Colorconsole.WriteLineGray("Creating MovieStreamingActorSystem"); _movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); _movieStreamingActorSystem.AwaitTermination(); }
protected override void PreRestart(Exception reason, object message) { Colorconsole.WriteLineYellow($"UserActor PreRestart because: {reason}"); base.PreRestart(reason, message); }