Example #1
0
 private void SendTerminated(bool ifLocal, IInternalActorRef watcher)
 {
     if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
     {
         watcher.SendSystemMessage(new DeathWatchNotification(Self, true, false));
     }
 }
Example #2
0
        /// <summary>
        ///     Handles the daemon MSG create.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleDaemonMsgCreate(DaemonMsgCreate message)
        {
            var       supervisor = (IInternalActorRef)message.Supervisor;
            var       parent     = supervisor;
            Props     props      = message.Props;
            ActorPath childPath;

            if (ActorPath.TryParse(message.Path, out childPath))
            {
                IEnumerable <string> subPath = childPath.ElementsWithUid.Drop(1); //drop the /remote
                ActorPath            p       = Path / subPath;
                var s          = subPath.Join("/");
                var i          = s.IndexOf("#", StringComparison.Ordinal);
                var childName  = i < 0 ? s : s.Substring(0, i); // extract the name without the UID
                var localProps = props;                         //.WithDeploy(new Deploy(Scope.Local));

                bool isTerminating = !_terminating.WhileOff(() =>
                {
                    IInternalActorRef actor = _system.Provider.ActorOf(_system, localProps, supervisor, p, false,
                                                                       message.Deploy, true, false);

                    AddChild(childName, actor);
                    actor.SendSystemMessage(new Watch(actor, this));
                    actor.Start();
                    if (AddChildParentNeedsWatch(parent, actor))
                    {
                        //TODO: figure out why current transport is not set when this message is sent
                        parent.SendSystemMessage(new Watch(parent, this));
                    }
                });
                if (isTerminating)
                {
                    Log.Error("Skipping [{0}] to RemoteSystemDaemon on [{1}] while terminating", message, p.Address);
                }
            }
            else
            {
                Log.Debug("remote path does not match path from message [{0}]", message);
            }
        }
Example #3
0
        /// <summary>
        /// Initialize: make a dummy cell which holds just a mailbox, then tell our
        /// supervisor that we exist so that he can create the real Cell in
        /// handleSupervise().
        /// </summary>
        /// <param name="async">TBD</param>
        /// <exception cref="IllegalStateException">This exception is thrown if this function is called more than once.</exception>
        /// <returns>TBD</returns>
        public RepointableActorRef Initialize(bool async)
        {
            var underlying = Underlying;

            if (underlying == null)
            {
                var newCell = new UnstartedCell(System, this, Props, Supervisor);
                SwapUnderlying(newCell);
                SwapLookup(newCell);
                Supervisor.SendSystemMessage(new Supervise(this, async));
                if (!async)
                {
                    Point();
                }

                return(this);
            }
            else
            {
                throw new IllegalStateException("initialize called more than once!");
            }
        }
 public SystemGuardianTests()
 {
     _userGuardian   = Sys.ActorOf(Props.Create <GuardianActor>()).AsInstanceOf <IInternalActorRef>();
     _systemGuardian = Sys.ActorOf(Props.Create(() => new SystemGuardianActor(_userGuardian))).AsInstanceOf <IInternalActorRef>();
     _systemGuardian.SendSystemMessage(new Watch(_userGuardian, _systemGuardian));
 }
 private void SendTerminated(bool ifLocal, IInternalActorRef watcher)
 {
     if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
     {
         watcher.SendSystemMessage(new DeathWatchNotification(Self, true, false));
     }
 }
Example #6
0
        public void Dispatch(IInternalActorRef recipient, Address recipientAddress, SerializedMessage message,
            IActorRef senderOption = null)
        {
            var payload = MessageSerializer.Deserialize(system, message);
            Type payloadClass = payload == null ? null : payload.GetType();
            var sender = senderOption ?? system.DeadLetters;
            var originalReceiver = recipient.Path;

            // message is intended for the RemoteDaemon, usually a command to create a remote actor
            if (recipient.Equals(remoteDaemon))
            {
                if (settings.UntrustedMode) log.Debug("dropping daemon message in untrusted mode");
                else
                {
                    if (settings.LogReceive)
                    {
                        var msgLog = string.Format("RemoteMessage: {0} to {1}<+{2} from {3}", payload, recipient, originalReceiver,sender);
                        log.Debug("received daemon message [{0}]", msgLog);
                    }
                    remoteDaemon.Tell(payload);
                }
            }

            //message is intended for a local recipient
            else if ((recipient is ILocalRef || recipient is RepointableActorRef) && recipient.IsLocal)
            {
                if (settings.LogReceive)
                {
                    var msgLog = string.Format("RemoteMessage: {0} to {1}<+{2} from {3}", payload, recipient, originalReceiver,sender);
                    log.Debug("received local message [{0}]", msgLog);
                }
                if (payload is ActorSelectionMessage)
                {
                    var sel = (ActorSelectionMessage) payload;

                    var actorPath = "/" + string.Join("/", sel.Elements.Select(x => x.ToString()));
                    if (settings.UntrustedMode
                        && (!settings.TrustedSelectionPaths.Contains(actorPath)
                            || sel.Message is IPossiblyHarmful
                            || !recipient.Equals(provider.RootGuardian)))
                    {
                        log.Debug(
                            "operating in UntrustedMode, dropping inbound actor selection to [{0}], allow it" +
                            "by adding the path to 'akka.remote.trusted-selection-paths' in configuration",
                            actorPath);
                    }
                    else
                    {
                        //run the receive logic for ActorSelectionMessage here to make sure it is not stuck on busy user actor
                        ActorSelection.DeliverSelection(recipient, sender, sel);
                    }
                }
                else if (payload is IPossiblyHarmful && settings.UntrustedMode)
                {
                    log.Debug("operating in UntrustedMode, dropping inbound IPossiblyHarmful message of type {0}",
                        payload.GetType());
                }
                else if (payload is ISystemMessage)
                {
                    recipient.SendSystemMessage((ISystemMessage)payload);
                }
                else
                {
                    recipient.Tell(payload, sender);
                }

            }

            // message is intended for a remote-deployed recipient
            else if ((recipient is IRemoteRef || recipient is RepointableActorRef) && !recipient.IsLocal &&
                     !settings.UntrustedMode)
            {
                if (settings.LogReceive)
                {
                    var msgLog = string.Format("RemoteMessage: {0} to {1}<+{2} from {3}", payload, recipient, originalReceiver, sender);
                    log.Debug("received remote-destined message {0}", msgLog);
                }
                if (provider.Transport.Addresses.Contains(recipientAddress))
                {
                    //if it was originally addressed to us but is in fact remote from our point of view (i.e. remote-deployed)
                    recipient.Tell(payload, sender);
                }
                else
                {
                    log.Error(
                        "Dropping message [{0}] for non-local recipient [{1}] arriving at [{2}] inbound addresses [{3}]",
                        payloadClass, recipient, recipientAddress, string.Join(",", provider.Transport.Addresses));
                }
            }
            else
            {
                log.Error(
                    "Dropping message [{0}] for non-local recipient [{1}] arriving at [{2}] inbound addresses [{3}]",
                    payloadClass, recipient, recipientAddress, string.Join(",", provider.Transport.Addresses));
            }
        }
 public SystemGuardianTests()
 {
     _userGuardian = Sys.ActorOf(Props.Create<GuardianActor>()).AsInstanceOf<IInternalActorRef>();
     _systemGuardian = Sys.ActorOf(Props.Create(() => new SystemGuardianActor(_userGuardian))).AsInstanceOf<IInternalActorRef>();
     _systemGuardian.SendSystemMessage(new Watch(_userGuardian, _systemGuardian));            
 }
Example #8
0
 public void SendSystemMessage(ISystemMessage message, IActorRef sender)
 {
     _delegate.SendSystemMessage(message, sender);
 }