Actor that validates user input and signals result to others.
상속: Akka.Actor.UntypedActor
예제 #1
0
        protected override void OnReceive(object message)
        {
            var msg = message as string;

            if (string.IsNullOrEmpty(msg))
            {
                // signal that the user needs to supply an input
                this.consoleWriterActor.Tell(new Messages.NullInputError("Input was blank. Please try again.\n"));

                // tell sender to continue doing its thing (whatever that may be,
                // this actor doesn't care)
                this.Sender.Tell(new Messages.ContinueProcessing());
            }
            else
            {
                var valid = FileValidatorActor.IsFileUri(msg);
                if (valid)
                {
                    // signal successful input
                    this.consoleWriterActor.Tell(new Messages.InputSuccess($"Starting processing for {msg}"));

                    // start coordinator
                    Context.ActorSelection("akka://MyActorSystem/user/tailCoordinatorActor").Tell(new TailCoordinatorActor.StartTail(msg, this.consoleWriterActor));
                }
                else
                {
                    // signal that input was bad
                    this.consoleWriterActor.Tell(new Messages.ValidationError($"{msg} is not an existing URI on disk."));

                    // tell sender to continue doing its thing (whatever that
                    // may be, this actor doesn't care)
                    this.Sender.Tell(new Messages.ContinueProcessing());
                }
            }
        }
예제 #2
0
        private static async Task Main()
        {
            MyActorSystem = ActorSystem.Create("MyActorSystem");

            var consoleWriterActor   = MyActorSystem.ActorOf(ConsoleWriterActor.Props(), "consoleWriterActor");
            var tailCoordinatorActor = MyActorSystem.ActorOf(TailCoordinatorActor.Props(), "tailCoordinatorActor");
            var fileValidatorActor   = MyActorSystem.ActorOf(FileValidatorActor.Props(consoleWriterActor), "validationActor");
            var consoleReaderActor   = MyActorSystem.ActorOf(ConsoleReaderActor.Props(), "consoleReaderActor");

            consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);

            await MyActorSystem.WhenTerminated.ConfigureAwait(false);
        }