Exemple #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="message">TBD</param>
        /// <returns>TBD</returns>
        protected override bool Business(object message)
        {
            switch (message)
            {
            case Subscribe subscribe when subscribe.Group != null:
                var encodedGroup = Utils.EncodeName(subscribe.Group);
                _buffer.BufferOr(Utils.MakeKey(Self.Path / encodedGroup), subscribe, Sender, () =>
                {
                    var child = Context.Child(encodedGroup);
                    if (!child.IsNobody())
                    {
                        child.Forward(message);
                    }
                    else
                    {
                        NewGroupActor(encodedGroup).Forward(message);
                    }
                });
                PruneDeadline = null;
                return(true);

            case Unsubscribe unsubscribe when unsubscribe.Group != null:
                encodedGroup = Utils.EncodeName(unsubscribe.Group);
                _buffer.BufferOr(Utils.MakeKey(Self.Path / encodedGroup), unsubscribe, Sender, () =>
                {
                    var child = Context.Child(encodedGroup);
                    if (!child.IsNobody())
                    {
                        child.Forward(message);
                    }
                    else
                    {
                        // no such group here
                    }
                });
                return(true);

            case Subscribed _:
                Context.Parent.Forward(message);
                return(true);

            case Unsubscribed _:
                Context.Parent.Forward(message);
                return(true);

            case NoMoreSubscribers _:
                var key = Utils.MakeKey(Sender);
                _buffer.InitializeGrouping(key);
                Sender.Tell(TerminateRequest.Instance);
                return(true);

            case NewSubscriberArrived _:
                key = Utils.MakeKey(Sender);
                _buffer.ForwardMessages(key, Sender);
                return(true);

            case Terminated terminated:
                key = Utils.MakeKey(terminated.ActorRef);
                _buffer.RecreateAndForwardMessagesIfNeeded(key, () => NewGroupActor(terminated.ActorRef.Path.Name));
                Remove(terminated.ActorRef);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="message">TBD</param>
        /// <returns>TBD</returns>
        protected override bool Business(object message)
        {
            Subscribe   subscribe;
            Unsubscribe unsubscribe;

            if ((subscribe = message as Subscribe) != null && subscribe.Group != null)
            {
                var encodedGroup = Utils.EncodeName(subscribe.Group);
                _buffer.BufferOr(Utils.MakeKey(Self.Path / encodedGroup), subscribe, Sender, () =>
                {
                    var child = Context.Child(encodedGroup);
                    if (!child.IsNobody())
                    {
                        child.Forward(message);
                    }
                    else
                    {
                        NewGroupActor(encodedGroup).Forward(message);
                    }
                });
                PruneDeadline = null;
            }
            else if ((unsubscribe = message as Unsubscribe) != null && unsubscribe.Group != null)
            {
                var encodedGroup = Utils.EncodeName(unsubscribe.Group);
                _buffer.BufferOr(Utils.MakeKey(Self.Path / encodedGroup), unsubscribe, Sender, () =>
                {
                    var child = Context.Child(encodedGroup);
                    if (!child.IsNobody())
                    {
                        child.Forward(message);
                    }
                    else
                    {
                        // no such group here
                    }
                });
            }
            else if (message is Subscribed)
            {
                Context.Parent.Forward(message);
            }
            else if (message is Unsubscribed)
            {
                Context.Parent.Forward(message);
            }
            else if (message is NoMoreSubscribers)
            {
                var key = Utils.MakeKey(Sender);
                _buffer.InitializeGrouping(key);
                Sender.Tell(TerminateRequest.Instance);
            }
            else if (message is NewSubscriberArrived)
            {
                var key = Utils.MakeKey(Sender);
                _buffer.ForwardMessages(key, Sender);
            }
            else if (message is Terminated)
            {
                var terminated = (Terminated)message;
                var key        = Utils.MakeKey(terminated.ActorRef);
                _buffer.RecreateAndForwardMessagesIfNeeded(key, () => NewGroupActor(terminated.ActorRef.Path.Name));
                Remove(terminated.ActorRef);
            }
            else
            {
                return(false);
            }
            return(true);
        }