예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }