private void ProcessPlayMovieMessage(IContext context, PlayMovieMessage msg) { CreateChildUserIfNotExists(context, msg.UserId); var childActorRef = _users[msg.UserId]; context.Send(childActorRef, msg); }
private void HandlePlayMovieMessage(PlayMovieMessage message) { ColorConsole.WriteLineYellow( string.Format("PlayMovieMessage '{0}' for user {1}", message.MovieTitle, message.UserId)); }
private void _(PlayMovieMessage message) { currentlyWatching = message.Name; Console.WriteLine("Starting movie " + currentlyWatching); Become(Stopped); }
private static void Main(string[] args) { MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.WriteLine("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } } while (true); }
private static void ManageHieararchy() { ColorConsole.WriteLineGray("Creating actor supervisor hierarchy"); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), Constants.ActorsNames.Playback); do { //ShortPause(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; ColorConsole.WriteLineGray("Enter a command (play/stop/exit) and hit Enter"); var command = Console.ReadLine(); if (command.StartsWith(Constants.Commands.Play, StringComparison.InvariantCultureIgnoreCase)) { var userId = int.Parse(command.Split(',')[1]); var movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection(Constants.ActorsSelectionPaths.UserCoordinator).Tell(message); } if (command.StartsWith(Constants.Commands.Stop, StringComparison.InvariantCultureIgnoreCase)) { var userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection(Constants.ActorsSelectionPaths.UserCoordinator).Tell(message); } if (command.StartsWith(Constants.Commands.Exit, StringComparison.InvariantCultureIgnoreCase)) { TerminateActorSystem(); Console.ReadKey(); Environment.Exit(1); } } while (true); }
static async Task MainAsync() { // [INITIALIZING] MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); Console.WriteLine("Actor system created"); Props userActorProps = Props.Create <UserActor>(); IActorRef userActorRef = MovieStreamingActorSystem.ActorOf(userActorProps, "UserActor"); //Props playbackActorProps = Props.Create<PlaybackActor>(); //IActorRef playbackActorRef = MovieStreamingActorSystem.ActorOf(playbackActorProps, "PlaybackActor"); //------------------------------ // [SENDING] Console.ReadKey(); var codenanDestroyer = new PlayMovieMessage("Codenan the Destroyer", 42); Console.WriteLine(string.Format("Sending a PlayMovieMessage ({0})", codenanDestroyer.MovieTitle)); userActorRef.Tell(codenanDestroyer); Console.ReadKey(); var booleanLies = new PlayMovieMessage("Boolean Lies", 42); Console.WriteLine(string.Format("Sending another PlayMovieMessage ({0})", booleanLies.MovieTitle)); userActorRef.Tell(booleanLies); Console.ReadKey(); Console.WriteLine("Sending a StopMovieMessage"); userActorRef.Tell(new StopMovieMessage()); Console.ReadKey(); Console.WriteLine("Sending another StopMovieMessage"); userActorRef.Tell(new StopMovieMessage()); //playbackActorRef.Tell(new PlayMovieMessage("Akka.NET: The Movie", 42)); //playbackActorRef.Tell(new PlayMovieMessage("Partial Recall", 99)); //playbackActorRef.Tell(new PlayMovieMessage("Boolean Lies", 77)); //playbackActorRef.Tell(new PlayMovieMessage("Codenan the Destroyer", 1)); //playbackActorRef.Tell(PoisonPill.Instance); // the actor will process the previous messages and then take this poison pill //------------------------------ // [TERMINATING] //press any key to start shutdown of system Console.ReadKey(); // terminating the actor system will terminate all actors await MovieStreamingActorSystem.Terminate(); //Shutdown() is obsolete await MovieStreamingActorSystem.WhenTerminated; //AwaitTermination() is obsolete Console.WriteLine("Actor system shutdown"); //press any key to stop console application Console.ReadKey(); }
private void _(PlayMovieMessage message) { log.Info("Started playing " + message.MovieTitle); CurrentlyPlaying = message.MovieTitle; log.Info("Replying to sender"); Sender.Tell(new NowPlayingMessage(CurrentlyPlaying)); stat?.Tell(message.MovieTitle); }
public UserActor(int userId) { ColoredConsole.WriteCreationEvent($" [{this.ActorName}] '{ActorName}' actor constructor."); _userId = userId; _currentlyPlaying = null; // Initial behavior Become(StoppedBehavior); }
static void Main(string[] args) { ConfigureAutofac(); ResolveLogger(); using (var system = ActorSystem.Create(SystemName)) { Logger.WriteVerbose("Actor system created"); var resolver = new AutoFacDependencyResolver(Container, system); system.ActorOf(resolver.Create <PlaybackActor>(), PlaybackActorName); bool running = true; do { Console.WriteLine("Enter a command and hit Enter"); Console.WriteLine("eg 'play <user id> <movie title>'"); Console.WriteLine("eg 'stop <user id>'"); Console.WriteLine("(enter 'exit' to quit)"); var command = Console.ReadLine(); if (command.StartsWith("play", StringComparison.InvariantCultureIgnoreCase)) { var parts = command.Split(new[] { ' ' }, 3); var userId = int.Parse(parts[1]); var movieTitle = parts[2]; var message = new PlayMovieMessage(movieTitle, userId); system.ActorSelection($"/user/{PlaybackActorName}/{UserCoordinatorActorName}").Tell(message); } if (command.StartsWith("stop", StringComparison.InvariantCultureIgnoreCase)) { var parts = command.Split(new[] { ' ' }, 2); var userId = int.Parse(parts[1]); var message = new StopMovieMessage(userId); system.ActorSelection($"/user/{PlaybackActorName}/{UserCoordinatorActorName}").Tell(message); } if (command.StartsWith("exit", StringComparison.InvariantCultureIgnoreCase)) { running = false; } } while (running); system.Terminate().GetAwaiter().GetResult(); Logger.WriteDebug("Actor system terminated"); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
private void HandlePlayMovieMessage(PlayMovieMessage message) { if (currentlyWatching != null) { ColorConsole.WriteLineRed("Error: cannot start playing another movie before stopping existing one"); return; } StartPlayingMovie(message.MovieTitle); }
static void Main(string[] args) { Console.WriteLine("Creating MovieStreamingActorSystem", Color.Gray); var config = ConfigurationFactory.ParseString(File.ReadAllText("settings.hocon")); using (MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorLocalSystem", config)) { Console.WriteLine("Actor System created"); Console.WriteLine("Creating actor supervisory hierarchy", Color.Gray); Props playbackActorProps = Props.Create <PlaybackActor>(); MovieStreamingActorSystem.ActorOf(playbackActorProps, "PlaybackActor"); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); // so that the messages from the system come before the user prompt is displayed do { Console.WriteLine(); Console.WriteLine("Enter a command and hit enter", Color.DarkGray); var command = Console.ReadLine(); if (command.StartsWith("play")) { var userId = int.Parse(command.Split(',')[1]); var movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/PlaybackActor/UserCoordinatorActor").Tell(message); } if (command.StartsWith("stop")) { var userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/PlaybackActor/UserCoordinatorActor").Tell(message); } if (command.StartsWith("exit")) { MovieStreamingActorSystem.Terminate(); Console.WriteLine("Actor System terminating", Color.Gray); MovieStreamingActorSystem.WhenTerminated.Wait(); Console.WriteLine("Actor System terminated", Color.Gray); Console.ReadLine(); Environment.Exit(0); } } while (true); } }
private void HandlePlayMovieMessage(PlayMovieMessage message) { if (_currentlyWatching != null) { Console.WriteLine("Need to Stop Previous Message"); } else { _currentlyWatching = message.MovieName; Console.WriteLine("User is currently watching"); } }
private void _(PlayMovieMessage message) { if (currentlyWatching != null) { logger.Warn("User {0} already watching movie", message.UserId); } else { currentlyWatching = message.MovieName; logger.Info("Starting movie " + currentlyWatching); } }
private void _(PlayMovieMessage message) { if (currentlyWatching != null) { Console.WriteLine("!!! user already watching movie"); } else { currentlyWatching = message.Name; Console.WriteLine("Starting movie " + currentlyWatching); } }
private void HandlePlayMovieMessage(PlayMovieMessage message) { if (_currentlyWatching != null) { WriteLineRed( "Error: cannot start playing another movie before stopping existing one"); } else { StartPlayingMovie(message.MovieTitle); } }
static async Task HierarchyMainAsync() { ColorConsole.WriteLineGray("Creating MovieStreamingActorSystem"); MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); ColorConsole.WriteLineGray("Creating actor supervisory hierarchy"); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { await ShortPause(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; ColorConsole.WriteLineGray("enter a command and hit enter"); var command = Console.ReadLine(); object message = null; if (command.StartsWith("play")) { var commandParts = command.Split(','); var userId = int.Parse(commandParts[1]); var movieTitle = commandParts[2]; message = new PlayMovieMessage(movieTitle, userId); } if (command.StartsWith("stop")) { var userId = int.Parse(command.Split(',')[1]); message = new StopMovieMessage(userId); } if (message != null) { MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command == "exit") { await MovieStreamingActorSystem.Terminate(); await MovieStreamingActorSystem.WhenTerminated; ColorConsole.WriteLineGray("Actor system shutdown"); Console.ReadKey(); Environment.Exit(1); } }while (true); }
private void StartPlayingMovie(PlayMovieMessage message) { _currentlyPlaying = message; // Context.ActorSelection(ActorPaths.MoviePlayCounterActor.Path).Tell(new IncrementMoviePlayCountMessage(message.MovieTitle, 1)); var actorRef = ActorSystemHelper.GetActorRefUsingResolveOne(ActorPaths.MoviePlayCounterActor.Path); if (actorRef != null) { ActorSystemHelper.SendAsynchronousMessage(actorRef, new IncrementMoviePlayCountMessage(message.MovieTitle, 1)); } Become(PlayingMovieBehavior); }
public void Start() { ColorConsole.WriteLineGray("Creating MovieStreamingActorSystem"); _movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); ColorConsole.WriteLineGray("Creating actor supervisory hierarchy"); _movieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); while (true) { Thread.Sleep(500); Console.WriteLine(); ColorConsole.WriteGray("Enter command > "); string command = Console.ReadLine(); if (command == null) { continue; } command = command.ToLower(); string[] commandArray = command.Split(','); if (command.StartsWith("play")) { int userId = int.Parse(commandArray[1]); string movieTitle = commandArray[2]; PlayMovieMessage message = new PlayMovieMessage(movieTitle, userId); const string selector = "/user/Playback/UserCoordinator"; _movieStreamingActorSystem.ActorSelection(selector).Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(commandArray[1]); StopMovieMessage message = new StopMovieMessage(userId); const string selector = "/user/Playback/UserCoordinator"; _movieStreamingActorSystem.ActorSelection(selector).Tell(message); } if (command == "exit") { _movieStreamingActorSystem.Terminate(); ColorConsole.WriteLineGray("Actor system shutdown"); break; } } }
private static void ManageUntypeActor() { var playbackActorProps = Props.Create <UntypePlaybackActor>(); var playbackActorReference = MovieStreamingActorSystem.ActorOf(playbackActorProps, "PlaybackActor"); playbackActorReference.Tell("Akka.NET: The Movie"); playbackActorReference.Tell(42); playbackActorReference.Tell('c'); var playMovieMessage = new PlayMovieMessage("My Movie", 56); playbackActorReference.Tell(playMovieMessage); }
static void Main(string[] args) { ColorConsole.WriteLineGray("Creating MovieStreamingActorSystem"); MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); ColorConsole.WriteLineGray("Creating actor supervisor hierarchy"); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); ColorConsole.WriteLineDarkGray("Input a command and hit Enter"); string command = Console.ReadLine(); string[] split = command.Split(","); string action = split[0]; ActorSelection userCoordinatorActor = MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator"); ActorSelection playbackStatisticsActor = MovieStreamingActorSystem.ActorSelection("/user/Playback/PlaybackStatistics"); if (action.Equals("play")) { int userId = int.Parse(split[1]); string movieTitle = split[2]; var message = new PlayMovieMessage(movieTitle, userId); userCoordinatorActor.Tell(message); playbackStatisticsActor.Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(split[1]); var message = new StopMovieMessage(userId); userCoordinatorActor.Tell(message); } if (command.StartsWith("exit")) { MovieStreamingActorSystem.Terminate(); ColorConsole.WriteLineGray("Actor system shutdown"); Console.ReadKey(); Environment.Exit(1); } } while (true); }
private static void Main(string[] args) { Console.WriteLine("Creating MovieStreamingActorSystem"); _movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); Console.WriteLine("Creating actor supervisory hierarchy"); _movieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); _movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); _movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command == "exit") { _movieStreamingActorSystem.Terminate().Wait(); Console.WriteLine("Actor system shutdown"); Console.ReadKey(); Environment.Exit(1); return; } } while (true); }
private static void Main(string[] args) { var builder = new ContainerBuilder(); builder.RegisterType <SimpleTrendingMovieAnalyzer>().As <ITrendingMovieAnalyzer>(); builder.RegisterType <TrendingMoviesActor>(); var container = builder.Build(); var logger = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); Serilog.Log.Logger = logger; MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); var resolver = new AutoFacDependencyResolver(container, MovieStreamingActorSystem); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.WriteLine("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } } while (true); }
static void Main(string[] args) { var builder = new ContainerBuilder(); builder.RegisterType <SimpleTrendingMovieAnalyzer>().As <ITrendingMovieAnalyzer>(); builder.RegisterType <TrendingMoviesActor>(); var container = builder.Build(); MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); IDependencyResolver resolver = new AutoFacDependencyResolver(container, MovieStreamingActorSystem); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; ColorConsole.WriteLineGray("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } else if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } else if (command == "exit") { Terminate(); } } while (true); }
static void Main(string[] args) { _movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); var playbackActorRef = _movieStreamingActorSystem.ActorOf <PlaybackActor>("Playback"); while (true) { Thread.Sleep(200); Console.WriteLine("Enter a command:"); var input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { continue; } if (input.StartsWith("play")) { var userId = int.Parse(input.Split(',')[1]); var movieTitle = input.Split(',')[2]; var playMovieMessage = new PlayMovieMessage(userId, movieTitle); var userCoordinator = _movieStreamingActorSystem.ActorSelection ("/user/Playback/UserCoordinator"); userCoordinator.Tell(playMovieMessage); } else if (input.StartsWith("stop")) { var userId = int.Parse(input.Split(',')[1]); var stopMovieMessage = new StopMovieMessage(userId); var userCoordinator = _movieStreamingActorSystem.ActorSelection ("/user/Playback/UserCoordinator"); userCoordinator.Tell(stopMovieMessage); } else if (input.StartsWith("exit")) { break; } } }
private static void Main(string[] args) { var container = new WindsorContainer(); container.Register(Component.For <ITrendingMovieAnalyzer>().ImplementedBy <SimpleTrendingMovieAnalyzer>()); container.Register(Component.For <TrendingMoviesActor>()); MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); IDependencyResolver resolver = new WindsorDependencyResolver(container, MovieStreamingActorSystem); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.WriteLine("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } } while (true); }
private static void Main(string[] args) { var logger = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .MinimumLevel.Information() .CreateLogger(); Serilog.Log.Logger = logger; MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"); MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); Console.WriteLine(); Console.WriteLine("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } } while (true); }
static void Main(string[] args) { var config = ConfigurationFactory.ParseString(@"akka { loglevel = DEBUG loggers = [""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""] }"); _movieStreamActorSystem = ActorSystem.Create("MovieStreamingActorSystem", config); _movieStreamActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback"); do { ShortPause(); WriteLine(); WriteLine("enter a command and hit enter"); var command = ReadLine(); if (command.StartsWith("play")) { int userId = int.Parse(command.Split(',')[1]); string movieTitle = command.Split(',')[2]; var message = new PlayMovieMessage(movieTitle, userId); _movieStreamActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } if (command.StartsWith("stop")) { int userId = int.Parse(command.Split(',')[1]); var message = new StopMovieMessage(userId); _movieStreamActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message); } } while (true); }
private void _(PlayMovieMessage message) { var actor = CreateIfNotExists(message.UserId); actor.Tell(message); }
private void HandredCount(PlayMovieMessage message) { _watched = _watched + 1; ColorConsole.WriteLineYellow(string.Format("The Movie {0} was watching {1} times", message.MovieTitle, _watched)); }
private void HandlePlayMovieMessage(PlayMovieMessage message) { Console.WriteLine("Improved Message : " + message.MovieTitle); Console.WriteLine("Improved Message : " + message.UserId); }