Esempio n. 1
0
        /// <summary>
        /// 转发
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="bufferReceiver"></param>
        /// <param name="messageID"></param>
        /// <param name="extraMessage"></param>
        /// <param name="messageBody"></param>
        /// <param name="forwarder"></param>
        public virtual void Forward <T>(T bufferReceiver, int messageID, ReadOnlyMemory <byte> extraMessage, ReadOnlyMemory <byte> messageBody, IForwarder forwarder)
            where T : IRemoteID, IUID <int>
        {
            RoutingInformationModifier modifier = extraMessage;

            switch (modifier.Mode)
            {
            case EnumRouteMode.Null:
            {
                modifier.Identifier = bufferReceiver.UID;
                break;
            }

            case EnumRouteMode.Find:
            {
                modifier = new RoutingInformationModifier(extraMessage);
                modifier.AddNode(bufferReceiver, forwarder);
                break;
            }

            case EnumRouteMode.Backward:
            case EnumRouteMode.Forward:
            default:
            {
                modifier = new RoutingInformationModifier(extraMessage);
                modifier.MoveCursorNext();
                break;
            }
            }
            using (modifier)
            {
                forwarder.SendAsync(Pack(messageID, extraMessage: modifier, messageBody.Span));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 转发
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="remote"></param>
        /// <param name="messageID"></param>
        /// <param name="extraMessage"></param>
        /// <param name="messageBody"></param>
        /// <param name="forwarder"></param>
        public virtual void Forward <T>(T bufferReceiver, int messageID, ReadOnlyMemory <byte> extraMessage, ReadOnlyMemory <byte> messageBody, IForwarder forwarder)
            where T : IRemoteID, IUID <int>
        {
            RoutingInformationModifier modifier = extraMessage;

            if (modifier.Mode == RouteMode.Null)
            {
                modifier.Identifier = bufferReceiver.UID;
            }
            else if (modifier.Mode == RouteMode.Find)
            {
                modifier = new RoutingInformationModifier(extraMessage);
                modifier.AddNode(bufferReceiver, forwarder);
            }
            else
            {
                modifier = new RoutingInformationModifier(extraMessage);
                modifier.MoveCursorNext();
            }

            forwarder.SendAsync(Pack(messageID, extraMessage: modifier, messageBody.Span));
            modifier.Dispose();
        }