Example #1
0
        public CommandReceptionistActor()
        {
            commandHandler = Context.ActorSelection(ActorSystemValues.COMMAND_HANDLER_ROUTER_PATH);

            Receive <TCommand>(command => {
                originalSender = Sender;
                commandHandler.Tell(command);

                SetReceiveTimeout(TimeSpan.FromSeconds(3));

                Become(() => {
                    Receive <CommandHandled <TCommand, TCommandResult> >(x => {
                        originalSender.Tell(x);
                        Self.Tell(PoisonPill.Instance);
                    });
                    Receive <ReceiveTimeout>(x => {
                        originalSender.Tell(CommandHandled <TCommand, TCommandResult> .CreateUnsuccessfulResult(command, CommandResultStatus.GENERAL_ERROR));
                    });
                });
            });
        }
Example #2
0
        private void WaitForAnswer()
        {
            Receive <ReceiveTimeout>(x => {
                commandSender.Tell(CommandHandled <TCommand, TCommandResult> .CreateUnsuccessfulResult(command));
                Self.Tell(PoisonPill.Instance);
            });

            Receive <CommandNotSuccessfulResult>(x => {
                commandSender.Tell(CommandHandled <TCommand, TCommandResult> .CreateUnsuccessfulResult(command, x.CommandStatus));
                Self.Tell(PoisonPill.Instance);
            });

            Receive <CommandHandled <TCommand, TCommandResult> >(x => {
                commandSender.Tell(x);
                Self.Tell(PoisonPill.Instance);
            });

            Receive <TCommandResult>(x => {
                commandSender.Tell(CommandHandled <TCommand, TCommandResult> .CreateSuccessfulResult(command, x));
                Self.Tell(PoisonPill.Instance);
            });
        }