Example #1
0
        public void Select_WithClient_should_update_Client_and_copy_the_rest_of_the_properties_BUG_427()
        {
            var deadline = new DateTime(1919, 5, 24);
            Predicate <object> predicate = o => true;
            var actorRef = new EmptyLocalActorRef(((ActorSystemImpl)Sys).Provider, new RootActorPath(new Address("akka", "test")), Sys.EventStream);
            var select   = new Select(deadline, predicate, actorRef);

            var updatedActorRef = new EmptyLocalActorRef(((ActorSystemImpl)Sys).Provider, new RootActorPath(new Address("akka2", "test2")), Sys.EventStream);

            var updatedSelect = (Select)select.WithClient(updatedActorRef);

            updatedSelect.Deadline.ShouldBe(deadline);
            updatedSelect.Predicate.ShouldBe(predicate);
            updatedSelect.Client.ShouldBe(updatedActorRef);
        }
Example #2
0
        public void Select_WithClient_should_update_Client_and_copy_the_rest_of_the_properties_BUG_427()
        {
            var deadline = new TimeSpan(Sys.Scheduler.MonotonicClock.Ticks / 2); //Some point in the past
            Predicate <object> predicate = o => true;
            var actorRef = new EmptyLocalActorRef(((ActorSystemImpl)Sys).Provider, new RootActorPath(new Address("akka", "test")), Sys.EventStream);
            var select   = new Select(deadline, predicate, actorRef);

            var updatedActorRef = new EmptyLocalActorRef(((ActorSystemImpl)Sys).Provider, new RootActorPath(new Address("akka2", "test2")), Sys.EventStream);

            var updatedSelect = (Select)select.WithClient(updatedActorRef);

            updatedSelect.Deadline.ShouldBe(deadline);
            updatedSelect.Predicate.ShouldBe(predicate);
            updatedSelect.Client.ShouldBe(updatedActorRef);
        }
        /// <summary>
        ///     Tells the internal.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="sender">The sender.</param>
        protected override void TellInternal(object message, IActorRef sender)
        {
            //note: RemoteDaemon does not handle ActorSelection messages - those are handled directly by the RemoteActorRefProvider.
            if (message is IDaemonMsg)
            {
                Log.Debug("Received command [{0}] to RemoteSystemDaemon on [{1}]", message, Path.Address);
                if (message is DaemonMsgCreate)
                {
                    HandleDaemonMsgCreate((DaemonMsgCreate)message);
                }
            }
            else if (message is ActorSelectionMessage sel)
            {
                var iter = sel.Elements.Iterator();

                (IEnumerable <string>, object) Rec(IImmutableList <string> acc)
                {
                    while (true)
                    {
                        if (iter.IsEmpty())
                        {
                            return(acc.Reverse(), sel.Message);
                        }

                        // find child elements, and the message to send, which is a remaining ActorSelectionMessage
                        // in case of SelectChildPattern, otherwise the actual message of the selection
                        switch (iter.Next())
                        {
                        case SelectChildName n:
                            acc = ImmutableList.Create(n.Name).AddRange(acc);
                            continue;

                        case SelectParent p when !acc.Any():
                            continue;

                        case SelectParent p:
                            acc = acc.Skip(1).ToImmutableList();
                            continue;

                        case SelectChildPattern pat:
                            return(acc.Reverse(), sel.Copy(elements: new[] { pat }.Concat(iter.ToVector()).ToArray()));

                        default:     // compiler ceremony - should never be hit
                            throw new InvalidOperationException("Unknown ActorSelectionPart []");
                        }
                    }
                }

                var t = Rec(ImmutableList <string> .Empty);
                var concatenatedChildNames = t.Item1;
                var m = t.Item2;

                var child = GetChild(concatenatedChildNames);
                if (child.IsNobody())
                {
                    var emptyRef = new EmptyLocalActorRef(_system.Provider,
                                                          Path / sel.Elements.Select(el => el.ToString()), _system.EventStream);
                    emptyRef.Tell(sel, sender);
                }
                else
                {
                    child.Tell(m, sender);
                }
            }
            //Remote ActorSystem on another process / machine has died.
            //Need to clean up any references to remote deployments here.
            else if (message is AddressTerminated)
            {
                var addressTerminated = (AddressTerminated)message;
                //stop any remote actors that belong to this address
                ForEachChild(@ref =>
                {
                    if (@ref.Parent.Path.Address == addressTerminated.Address)
                    {
                        _system.Stop(@ref);
                    }
                });
            }
            else if (message is Identify identify)
            {
                sender.Tell(new ActorIdentity(identify.MessageId, this));
            }
            else if (message is TerminationHook)
            {
                _terminating.SwitchOn(() =>
                {
                    TerminationHookDoneWhenNoChildren();
                    ForEachChild(c => _system.Stop(c));
                });
            }
        }