protected void AddWatching(IInternalActorRef watchee, IInternalActorRef watcher) { // TODO: replace with Code Contracts assertion if (watcher.Equals(Self)) { throw new InvalidOperationException("Watcher cannot be the RemoteWatcher!"); } Log.Debug("Watching: [{0} -> {1}]", watcher.Path, watchee.Path); HashSet <IInternalActorRef> watching; if (Watching.TryGetValue(watchee, out watching)) { watching.Add(watcher); } else { Watching.Add(watchee, new HashSet <IInternalActorRef> { watcher }); } WatchNode(watchee); // add watch from self, this will actually send a Watch to the target when necessary Context.Watch(watchee); }
private void SendTerminated(bool ifLocal, IInternalActorRef watcher) { if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent)) { watcher.SendSystemMessage(new DeathWatchNotification(Self, true, false)); } }
/// <summary> /// TBD /// </summary> /// <param name="watchee">TBD</param> /// <param name="watcher">TBD</param> /// <exception cref="InvalidOperationException">TBD</exception> protected void RemoveWatch(IInternalActorRef watchee, IInternalActorRef watcher) { if (watcher.Equals(Self)) { throw new InvalidOperationException("Watcher cannot be the RemoteWatcher!"); } Log.Debug($"Unwatching: [{watcher.Path} -> {watchee.Path}]"); if (Watching.TryGetValue(watchee, out var watchers)) { watchers.Remove(watcher); if (!watchers.Any()) { // clean up self watch when no more watchers of this watchee Log.Debug("Cleanup self watch of [{0}]", watchee.Path); Context.Unwatch(watchee); RemoveWatchee(watchee); } } }
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 bool Equals(IActorRef other) { return(_delegate.Equals(other)); }