private void ProcessStopMovieMessage(IContext context, StopMovieMessage msg)
        {
            CreateChildUserIfNotExists(context, msg.UserId);
            var childActorRef = _users[msg.UserId];

            context.Send(childActorRef, msg);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        private void _(StopMovieMessage message)
        {
            Console.WriteLine("Stopping movie " + currentlyWatching);
            currentlyWatching = null;

            Become(Playing);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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();
        }
Пример #7
0
        private void HandleStopMovieMessage(StopMovieMessage message)
        {
            if (currentlyWatching == null)
            {
                ColorConsole.WriteLineRed("Error: cannot stop if nothing is playing");
                return;
            }

            StopPlayingCurrentMovie();
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
 private void _(StopMovieMessage message)
 {
     if (currentlyWatching == null)
     {
         Console.WriteLine("!!! Nothing to stop");
     }
     else
     {
         Console.WriteLine("Stopping movie " + currentlyWatching);
         currentlyWatching = null;
     }
 }
Пример #10
0
 private void _(StopMovieMessage message)
 {
     if (currentlyWatching == null)
     {
         logger.Warn("Nothing to stop");
     }
     else
     {
         logger.Info("Stopping movie " + currentlyWatching);
         currentlyWatching = null;
     }
 }
Пример #11
0
        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);
        }
Пример #12
0
        private void HandleStopMovieMessage(StopMovieMessage message)
        {
            if (_currentlyWatching == null)
            {
                Console.WriteLine("Cannot stop if nothing is playing");
            }
            else
            {
                Console.WriteLine("Stopping" + _currentlyWatching);

                _currentlyWatching = null;
            }
        }
Пример #13
0
        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;
                }
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        private static void Main(string[] args)
        {
            _movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
            Console.WriteLine(string.Format("{0} started...", _movieStreamingActorSystem.Name));

            var playbackActorProps = Props.Create<PlaybackActor>();
            var playbackActorRef = _movieStreamingActorSystem.ActorOf(playbackActorProps, "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"))
                {
                    var userId = int.Parse(command.Split(',')[1]);
                    var movieTitle = command.Split(',')[2];

                    var message = new PlayMovieMessage(movieTitle, userId);
                    _movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

                if (command.StartsWith("stop"))
                {
                    var userId = int.Parse(command.Split(',')[1]);

                    var message = new StopMovieMessage(userId);
                    _movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

                if (command == "exit")
                {
                    _movieStreamingActorSystem.Shutdown();
                    _movieStreamingActorSystem.AwaitTermination();
                    ColorConsole.WriteLineGray("Actor system shutdown");
                    Console.ReadKey();
                    Environment.Exit(1);
                }

            } 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);
        }
Пример #19
0
        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);
        }
Пример #20
0
        static void Main(string[] args)
        {
            ColorConsole.WriteLineGray("Creating MovieStreamingActorSystem");
            MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
            Console.WriteLine("Actor system created.");

            ColorConsole.WriteLineGray("Creating actor supervisory hierarchy");
            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);
                }

                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.StartsWith("exit"))
                {
                    MovieStreamingActorSystem.Shutdown();
                    MovieStreamingActorSystem.AwaitTermination();
                    ColorConsole.WriteLineGray("Actor system shutdown");
                    Console.ReadKey();
                    Environment.Exit(1);
                }

            } while (true);
        }
Пример #21
0
        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;
                }
            }
        }
Пример #22
0
        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);
        }
Пример #23
0
        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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }
Пример #26
0
        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);
        }
Пример #27
0
        static void Main(string[] args)
        {
            ColorConsole.WriteLine("Creating MovieStreamingActorSystem", ConsoleColor.Gray);
            using (ActorSystem movieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem"))
            {
                ColorConsole.WriteLine("Creating actor supervisory hierarchy", ConsoleColor.Gray);
                movieStreamingActorSystem.ActorOf(Props.Create(() => new PlaybackActor()), "Playback");
                do
                {
                    Task.Delay(100).Wait();
                    ColorConsole.WriteLine("enter a command and hit enter", ConsoleColor.Gray);
                    var command = Console.ReadLine();

                    if (command.StartsWith("play"))
                    {
                        int               userId     = int.Parse(command.Split(',')[1]);
                        string            movieTitle = command.Split(',')[2];
                        StartMovieMessage message    = new StartMovieMessage(movieTitle, userId);
                        movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                    }

                    if (command.StartsWith("stop"))
                    {
                        int userId = int.Parse(command.Split(',')[1]);
                        StopMovieMessage message = new StopMovieMessage(userId);
                        movieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                    }

                    if (command == "exit")
                    {
                        break;
                    }
                } while (true);
            }
            Console.ReadKey();
        }
Пример #28
0
 private void StopPlayingMovie(StopMovieMessage message)
 {
     _currentlyPlaying = null;
     Become(StoppedBehavior);
 }
        private void _(StopMovieMessage message)
        {
            var actor = CreateIfNotExists(message.UserId);

            actor.Tell(message);
        }
Пример #30
0
        static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddXmlFile("hocon.xml");

            var configuration = builder.Build();

            var hoconConfig = configuration.GetSection("hocon");

            var config = ConfigurationFactory.ParseString(hoconConfig.Value);

            Console.WriteLine("Creating MovieStreamingActorSystem");
            MovieStreamingActorSystem = ActorSystem.Create(nameof(MovieStreamingActorSystem), config);

            Console.WriteLine("Creating actor supervisory hierarchy");
            MovieStreamingActorSystem.ActorOf(Props.Create <PlaybackActor>(), "Playback");

            do
            {
                ShortPause();

                Console.WriteLine("Enter command and hit enter");

                var command = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(command))
                {
                    Console.WriteLine("Bad command. Please reenter.");
                    continue;
                }

                var commandArgs = command.Split(',');

                if (commandArgs[0] == "play")
                {
                    if (commandArgs.Length != 3)
                    {
                        Console.WriteLine("Bad play command parameters. Please reenter command.");
                        continue;
                    }

                    int    userId     = int.Parse(commandArgs[1]);
                    string movieTitle = commandArgs[2];

                    var message = new PlayMovieMessage(userId, movieTitle);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

                if (commandArgs[0] == "stop")
                {
                    if (commandArgs.Length != 2)
                    {
                        Console.WriteLine("Bad stop command parameters. Please reenter command.");
                        continue;
                    }

                    int userId = int.Parse(commandArgs[1]);

                    var message = new StopMovieMessage(userId);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(message);
                }

                if (commandArgs[0] == "exit")
                {
                    await MovieStreamingActorSystem.Terminate();

                    await MovieStreamingActorSystem.WhenTerminated;

                    Console.WriteLine("Actor system shutdown");
                    Console.ReadKey();
                    break;
                }
            } while (true);
        }
Пример #31
0
 public static int StopPlayingMovie(StopMovieMessage message)
 {
     ActorSystemHelper.SendAsynchronousMessage(GetUserCoordinatorActorRef(), message);
     return(0);
 }
Пример #32
0
        static void Main(string[] args)
        {
            // we don't want to use the new keyword, we want to use factories to create things for us.
            // MovieStreaming = new ActorSystemImpl();
            // when we use these factories we ensure that everything is set up correctly.

            MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
            Console.WriteLine("Actor system created");
            // The name of the actor system is important because it actually forms part of the address. If we are
            // referencing remote actors.


            //We need to defin some props to create an instance of our playback actor.
            // Also we don't want to create our props using the new keyword instead we want to use a
            // one of the Akkka.Net factory methods.
            Props playbackActorProps = Props.Create <PlaybackActor>();



            // Here we create our PlaybackActor. inside the MovieStreamingActory system.
            // We also got the reference to the actor in our playbackActorRef.
            IActorRef playbackActorRef = MovieStreamingActorSystem.ActorOf(playbackActorProps, "playbackActor");



            // We have already have the reference to our actor in this playbackActorRef variable. So we can use this
            // actor reference to tell the actor do something.


            do
            {
                Thread.Sleep(2000);
                Console.WriteLine("Enter a command: ");

                var command = Console.ReadLine();

                if (command.StartsWith("play"))
                {
                    var userId     = int.Parse(command.Split(",")[1]);
                    var movieTitle = command.Split(",")[2];

                    var message = new PlayMovieMessage(userId, movieTitle);
                    playbackActorRef.Tell(message);
                }

                if (command.StartsWith("stop"))
                {
                    var userId  = int.Parse(command.Split(",")[1]);
                    var message = new StopMovieMessage(userId);
                    playbackActorRef.Tell(message);
                }


                if (command == "exit")
                {
                    Console.ReadLine();
                    Environment.Exit(1);
                }
            } while (true);



            Console.ReadLine();

            //// tell actor system (and all child actors) to shutdown
            MovieStreamingActorSystem.Terminate();

            //// wait for the actor system to finish shutting down.
            MovieStreamingActorSystem.Terminate().Wait();

            Console.WriteLine("actor system shutdown");
            Console.ReadLine();
            //// shutdown method was deprecated and then removed, and has been replaced with terminate.
        }
Пример #33
0
        static void Main(string[] args)
        {
            MovieStreamingActorSystem = ActorSystem.Create("MovieStreamingActorSystem");
            Console.WriteLine("Actor system created");

            var       playbackActorProps = Props.Create <PlaybackActor>();
            IActorRef playbackActorRef   = MovieStreamingActorSystem.ActorOf(playbackActorProps, "Playback");

            //IActorRef playbackActorRef = MovieStreamingActorSystem
            //    .ActorSelection("akka.tcp://[email protected]:8092/user/Playback")
            //       .ResolveOne(TimeSpan.FromSeconds(3))
            //    .Result;

            IActorRef userActorRef = MovieStreamingActorSystem.ActorOf <UserActor>("UserActor");

            do
            {
                Thread.Sleep(500);
                Console.WriteLine();
                var cmd = Console.ReadLine();
                if (cmd.StartsWith("play"))
                {
                    var userId = int.Parse(cmd.Split(',')[1]);
                    var title  = cmd.Split(',')[2];
                    var msg    = new PlayMovieMessage(title, userId);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(msg);
                }
                if (cmd.StartsWith("stop"))
                {
                    var userId = int.Parse(cmd.Split(',')[1]);
                    var title  = cmd.Split(',')[2];
                    var msg    = new StopMovieMessage(userId);
                    MovieStreamingActorSystem.ActorSelection("/user/Playback/UserCoordinator").Tell(msg);
                }
                if (cmd == "exit")
                {
                    MovieStreamingActorSystem.Terminate();
                    Console.ReadKey();
                    Environment.Exit(1);
                }
            } while (true);



            //userActorRef.Tell(new PlayMovieMessage("Akka The Movie", 9));
            //Console.ReadLine();
            //userActorRef.Tell(new StopMovieMessage());
            //Console.ReadLine();
            //userActorRef.Tell(new PlayMovieMessage("test1", 9));
            //Console.ReadLine();
            //userActorRef.Tell(new StopMovieMessage());
            //Console.ReadLine();
            //userActorRef.Tell(new PlayMovieMessage("test2", 9));
            //Console.ReadLine();
            //userActorRef.Tell(new StopMovieMessage());
            //Console.ReadLine();
            //userActorRef.Tell(new PlayMovieMessage("test3", 9));
            //Console.ReadLine();
            //userActorRef.Tell(new StopMovieMessage());
            //Console.ReadLine();
            //userActorRef.Tell(new StopMovieMessage());
            //Console.ReadLine();
            MovieStreamingActorSystem.Terminate();
        }