Beispiel #1
0
        public override int ProcessModuleRedirectAllResult(ModuleRedirectAllResult protocol)
        {
            var sourcerProvider = App.ProviderService.GetSocket(protocol.Argument.SourceProvider);

            if (null != sourcerProvider)
            {
                protocol.Send(sourcerProvider);
            }
            return(Zeze.Transaction.Procedure.Success);
        }
Beispiel #2
0
        private void SendResultIfSizeExceed(Zeze.Net.AsyncSocket sender, ModuleRedirectAllResult result)
        {
            int size = 0;

            foreach (var hashResult in result.Argument.Hashs.Values)
            {
                size += hashResult.Params.Count;
                foreach (var hashActions in hashResult.Actions)
                {
                    size += hashActions.Params.Count;
                }
            }
            if (size > 2 * 1024 * 1024) // 2M
            {
                result.Send(sender);
                result.Argument.Hashs.Clear();
            }
        }
Beispiel #3
0
        public override int ProcessModuleRedirectAllRequest(ModuleRedirectAllRequest protocol)
        {
            var result = new ModuleRedirectAllResult();

            try
            {
                // replace RootProcedure.ActionName. 为了统计和日志输出。
                Transaction.Current.TopProcedure.ActionName = protocol.Argument.MethodFullName;

                // common parameters for result
                result.Argument.ModuleId       = protocol.Argument.ModuleId;
                result.Argument.AutoKeyLocalId = App.Zeze.Config.AutoKeyLocalId;
                result.Argument.SourceProvider = protocol.Argument.SourceProvider;
                result.Argument.SessionId      = protocol.Argument.SessionId;
                result.Argument.MethodFullName = protocol.Argument.MethodFullName;

                if (false == Game.ModuleRedirect.Instance.Handles.TryGetValue(
                        protocol.Argument.MethodFullName, out var handle))
                {
                    result.ResultCode = ModuleRedirect.ResultCodeMethodFullNameNotFound;
                    // 失败了,需要把hash返回。此时是没有处理结果的。
                    foreach (var hash in protocol.Argument.HashCodes)
                    {
                        result.Argument.Hashs.Add(hash, new BModuleRedirectAllHash()
                        {
                            ReturnCode = Procedure.NotImplement
                        });
                    }
                    result.Send(protocol.Sender);
                    return(Procedure.LogicError);
                }
                result.ResultCode = ModuleRedirect.ResultCodeSuccess;

                foreach (var hash in protocol.Argument.HashCodes)
                {
                    // 嵌套存储过程,某个分组处理失败不影响其他分组。
                    var             hashResult = new BModuleRedirectAllHash();
                    Zeze.Net.Binary Params     = null;
                    hashResult.ReturnCode = App.Zeze.NewProcedure(() =>
                    {
                        var(_ReturnCode, _Params) = handle(protocol.Argument.SessionId, hash, protocol.Argument.Params, hashResult.Actions);
                        Params = _Params;
                        return(_ReturnCode);
                    }, Transaction.Current.TopProcedure.ActionName).Call();

                    // 单个分组处理失败继续执行。XXX
                    if (hashResult.ReturnCode == Procedure.Success)
                    {
                        hashResult.Params = Params;
                    }
                    result.Argument.Hashs.Add(hash, hashResult);
                    SendResultIfSizeExceed(protocol.Sender, result);
                }

                // send remain
                if (result.Argument.Hashs.Count > 0)
                {
                    result.Send(protocol.Sender);
                }
                return(Procedure.Success);
            }
            catch (Exception)
            {
                result.ResultCode = ModuleRedirect.ResultCodeHandleException;
                result.Send(protocol.Sender);
                throw;
            }
        }
Beispiel #4
0
        public override int ProcessModuleRedirectAllRequest(ModuleRedirectAllRequest protocol)
        {
            Dictionary <long, ModuleRedirectAllRequest> transmits = new Dictionary <long, ModuleRedirectAllRequest>();

            ModuleRedirectAllResult miss = new ModuleRedirectAllResult();

            miss.Argument.ModuleId       = protocol.Argument.ModuleId;
            miss.Argument.MethodFullName = protocol.Argument.MethodFullName;
            miss.Argument.SourceProvider = protocol.Sender.SessionId; // not used
            miss.Argument.SessionId      = protocol.Argument.SessionId;
            miss.Argument.AutoKeyLocalId = 0;                         // 在这里没法知道逻辑服务器id,错误报告就不提供这个了。
            miss.ResultCode = ModuleRedirect.ResultCodeLinkdNoProvider;

            for (int i = 0; i < protocol.Argument.HashCodeConcurrentLevel; ++i)
            {
                long provider;
                if (ChoiceProvider(protocol.Argument.ServiceNamePrefix, protocol.Argument.ModuleId, i, out provider))
                {
                    if (false == transmits.TryGetValue(provider, out var exist))
                    {
                        exist = new ModuleRedirectAllRequest();
                        exist.Argument.ModuleId = protocol.Argument.ModuleId;
                        exist.Argument.HashCodeConcurrentLevel = protocol.Argument.HashCodeConcurrentLevel;
                        exist.Argument.MethodFullName          = protocol.Argument.MethodFullName;
                        exist.Argument.SourceProvider          = protocol.Sender.SessionId;
                        exist.Argument.SessionId = protocol.Argument.SessionId;
                        exist.Argument.Params    = protocol.Argument.Params;
                        transmits.Add(provider, exist);
                    }
                    exist.Argument.HashCodes.Add(i);
                }
                else
                {
                    miss.Argument.Hashs[i] = new BModuleRedirectAllHash()
                    {
                        ReturnCode = Zeze.Transaction.Procedure.ProviderNotExist
                    };
                }
            }

            // 转发给provider
            foreach (var transmit in transmits)
            {
                var socket = App.ProviderService.GetSocket(transmit.Key);
                if (null != socket)
                {
                    transmit.Value.Send(socket);
                }
                else
                {
                    foreach (var hashindex in transmit.Value.Argument.HashCodes)
                    {
                        miss.Argument.Hashs[hashindex] = new BModuleRedirectAllHash()
                        {
                            ReturnCode = Zeze.Transaction.Procedure.ProviderNotExist
                        };
                    }
                }
            }

            // 没有转发成功的provider的hash分组,马上发送结果报告错误。
            if (miss.Argument.Hashs.Count > 0)
            {
                miss.Send(protocol.Sender);
            }
            return(Zeze.Transaction.Procedure.Success);
        }