Exemplo n.º 1
0
        public static void TerminateActorSystem()
        {
            ColoredConsole.WriteTitle("  Quitting...");

            // Terminate an ActorSystem
            ActorSystemHelper.TerminateActorSystem();
        }
Exemplo n.º 2
0
        public MoviePlaybackActor()
            : base()
        {
            ColoredConsole.WriteCreationEvent($"  [{this.ActorName}] '{ActorName}' actor constructor.");

            UserCoordinatorActorRef    = ActorSystemHelper.CreateActorHelper(Context, UserCoordinatorActor.Props(), ActorPaths.UserCoordinatorActor.Name);
            PlaybackStatisticsActorRef = ActorSystemHelper.CreateActorHelper(Context, PlaybackStatisticsActor.Props(), ActorPaths.PlaybackStatisticsActor.Name);
        }
Exemplo n.º 3
0
        private static IActorRef GetUserCoordinatorActorRef()
        {
            if (_userCoordinatorActorRef == null)
            {
                // Get reference to UserCoordinatorActor for sending PlayMovieMessage and StopMovieMessage
                _userCoordinatorActorRef = ActorSystemHelper.GetActorRefUsingResolveOne(ActorPaths.UserCoordinatorActor.Path);
            }

            return(_userCoordinatorActorRef);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public static void StartActorSystem(bool createRootActor = false)
        {
            ActorSystemName = Constants.ActorSystemName;

            // Create an ActionSystem
            ColoredConsole.WriteTitle($"Creating '{ActorSystemName}' ActorSystem...");

            // Create an Akka ActorSystem
            ActorSystemHelper.CreateActorSystem(ActorSystemName);

            if (createRootActor == true)
            {
                // Create first 'user' actor 'MoviePlaybackActor' in Akka ActorSystem
                _moviePlaybackActorRef = ActorSystemHelper.CreateActor(MoviePlaybackActor.Props(), ActorPaths.MoviePlaybackActor.Name);
            }
        }
Exemplo n.º 6
0
        private IActorRef CreateOrGetChildActor(int userId)
        {
            IActorRef actorRef;

            var childActorMetaData = ActorPaths.GetUserActorMetaData(userId.ToString());

            // ColoredConsole.WriteTemporaryDebugMessage($"User Actor Path: '{userActorMetaData.Path}'");

            // Use ResolveOne or Identity message to get the Actor Reference
            // actorRef = _actorSystemHelper.GetActorRefUsingIdentity(userActorMetaData.Path);
            actorRef = ActorSystemHelper.GetActorRefUsingResolveOne(childActorMetaData.Path);
            if (actorRef == null)
            {
                actorRef = ActorSystemHelper.CreateActor(Context, UserActor.Props(userId), childActorMetaData.Name);
                ColoredConsole.WriteCreationEvent($"    [{this.ActorName}] '{this.ActorName}' has created new child '{childActorMetaData.Name}' actor for UserId {userId}.");
            }

            return(actorRef);
        }
Exemplo n.º 7
0
        override protected void OnReceive(object message)
        {
            IActorRef actorRef;

            switch (message)
            {
            case PlayMovieMessage pmm:
                actorRef = CreateOrGetChildActor(pmm.UserId);
                ActorSystemHelper.SendAsynchronousMessage(actorRef, message);
                break;

            case StopMovieMessage smm:
                actorRef = CreateOrGetChildActor(smm.UserId);
                ActorSystemHelper.SendAsynchronousMessage(actorRef, message);
                break;

            default:
                ColoredConsole.WriteReceivedMessage($"    [{this.ActorName}] OnReceive(): ERROR: Unknown '{message.GetType().ToString()}' type received!");
                Unhandled(message);
                break;
            }
        }
Exemplo n.º 8
0
 public static int StopPlayingMovie(StopMovieMessage message)
 {
     ActorSystemHelper.SendAsynchronousMessage(GetUserCoordinatorActorRef(), message);
     return(0);
 }
Exemplo n.º 9
0
 public static Akka.Actor.IActorRef Create()
 {
     return(ActorSystemHelper.CreateActor(MoviePlaybackActor.Props(), ActorPaths.MoviePlaybackActor.Name));
 }