/// <summary> /// Directly inject messages into actor receive behavior. Any exceptions /// thrown will be available to you, while still being able to use /// become/unbecome. /// </summary> /// <param name="message">The message.</param> /// <param name="sender">The sender.</param> public void Receive(object message, ActorRef sender = null) { var cell = Cell; sender = sender.IsNobody() ? cell.System.DeadLetters : sender; var envelope = new Envelope { Message = message, Sender = sender }; cell.UseThreadContext(() => cell.ReceiveMessageForTest(envelope)); }
protected virtual void SendUserMessage(object message, ActorRef sender) { if(message == null) throw new InvalidMessageException(); var deadLetter = message as DeadLetter; if(deadLetter != null) HandleDeadLetter(deadLetter); else { var wasHandled = SpecialHandle(message, sender); if(!wasHandled) { _eventStream.Publish(new DeadLetter(message, sender.IsNobody() ? _provider.DeadLetters : sender, this)); } } }
protected virtual bool SpecialHandle(object message, ActorRef sender) { var w = message as Watch; if (w != null) { if (w.Watchee == this && w.Watcher != this) { w.Watcher.Tell(new DeathWatchNotification(w.Watchee, existenceConfirmed: false, addressTerminated: false)); } return(true); } if (message is Unwatch) { return(true); //Just ignore } var identify = message as Identify; if (identify != null) { sender.Tell(new ActorIdentity(identify.MessageId, null)); return(true); } var sel = message as ActorSelectionMessage; if (sel != null) { var selectionIdentify = sel.Message as Identify; if (selectionIdentify != null) { if (!sel.WildCardFanOut) { sender.Tell(new ActorIdentity(selectionIdentify.MessageId, null)); } } else { _eventStream.Publish(new DeadLetter(sel.Message, sender.IsNobody() ? _provider.DeadLetters : sender, this)); } return(true); } return(false); }
protected virtual void SendUserMessage(object message, ActorRef sender) { if (message == null) { throw new InvalidMessageException(); } var deadLetter = message as DeadLetter; if (deadLetter != null) { HandleDeadLetter(deadLetter); } else { var wasHandled = SpecialHandle(message, sender); if (!wasHandled) { _eventStream.Publish(new DeadLetter(message, sender.IsNobody() ? _provider.DeadLetters : sender, this)); } } }
protected virtual bool SpecialHandle(object message, ActorRef sender) { var w = message as Watch; if(w != null) { if(w.Watchee == this && w.Watcher != this) { w.Watcher.Tell(new DeathWatchNotification(w.Watchee, existenceConfirmed: false, addressTerminated: false)); } return true; } if(message is Unwatch) return true; //Just ignore var identify = message as Identify; if(identify != null) { sender.Tell(new ActorIdentity(identify.MessageId, null)); return true; } var sel = message as ActorSelectionMessage; if(sel != null) { var selectionIdentify = sel.Message as Identify; if(selectionIdentify != null) { if(!sel.WildCardFanOut) sender.Tell(new ActorIdentity(selectionIdentify.MessageId, null)); } else { _eventStream.Publish(new DeadLetter(sel.Message, sender.IsNobody() ? _provider.DeadLetters : sender, this)); } return true; } return false; }