Beispiel #1
0
 private void OnLoadReply(NLRep_Load msg, PBChannel channel, int src, uint session)
 {
     if (null != m_RunningThread)
     {
         m_RunningThread.QueueAction(this.DoLoadReply, msg, channel, src, session);
     }
 }
Beispiel #2
0
 private void LoadHandler(LNReq_Load msg, PBChannel channel, int handle, uint seq)
 {
     if (!Enable)
     {
         LogSys.Log(LOG_TYPE.ERROR, "Load a message while DataOperator is Disable");
         return;
     }
     try
     {
         DataCacheSystem.Instance.LoadActionQueue.QueueAction((MyAction <uint, string, MyAction <DSLoadResult, string, IMessage> >)DataCacheSystem.Instance.Load,
                                                              msg.DsMsgId,
                                                              msg.Key,
                                                              (ret, error, data) =>
         {
             //这段代码必须保证线程安全,会在不同线程调用!!!
             var reply = NLRep_Load.CreateBuilder();
             reply.SetDsMsgId(msg.DsMsgId);
             reply.SetKey(msg.Key);
             if (ret == DSLoadResult.Success)
             {
                 reply.SetResult(NLRep_Load.Types.LoadResult.Success);
                 reply.SetData(ByteString.Unsafe.FromBytes(channel_.Encode(data)));
             }
             else if (ret == DSLoadResult.Undone)
             {
                 reply.SetResult(NLRep_Load.Types.LoadResult.Undone);
                 reply.SetData(ByteString.Unsafe.FromBytes(channel_.Encode(data)));
             }
             else if (ret == DSLoadResult.NotFound)
             {
                 reply.SetResult(NLRep_Load.Types.LoadResult.NotFound);
                 reply.SetError(error);
             }
             else
             {
                 reply.SetResult(NLRep_Load.Types.LoadResult.Error);
                 reply.SetError(error);
             }
             NLRep_Load replyData = reply.Build();
             channel.Send(replyData);
             LogSys.Log(LOG_TYPE.INFO, "Load data finished. msgId:({0}) key:({1}) result:({2}) ", msg.DsMsgId, msg.Key, ret);
         });
     }
     catch (Exception e)
     {
         var errorReply = NLRep_Load.CreateBuilder();
         errorReply.SetResult(NLRep_Load.Types.LoadResult.Error);
         errorReply.SetError(e.Message);
         channel.Send(errorReply.Build());
         LogSys.Log(LOG_TYPE.ERROR, "DataStore load data failed. msgId:({0}) key:({1}) seq:({2}) error:({3} detail:{4})",
                    msg.DsMsgId, msg.Key, seq, e.Message, e.StackTrace);
     }
 }
Beispiel #3
0
        private void DoLoadReply(NLRep_Load msg, PBChannel channel, int src, uint session)
        {
            string    timeoutKey = string.Format("{0}:{1}", msg.DsMsgId, msg.Key);
            LoadCBBox cbbox      = loadOpt_timeout_.Get(timeoutKey);

            if (null != cbbox)
            {
                DSLoadResult loadRet  = DSLoadResult.UnknownError;
                string       errorStr = "Save Unknown Error";
                IMessage     data     = null;
                if (msg.Result == NLRep_Load.Types.LoadResult.Success)
                {
                    loadRet  = DSLoadResult.Success;
                    data     = channel_.Decode(ByteString.Unsafe.GetBuffer(msg.Data));
                    errorStr = "Load Success";
                    loadOpt_timeout_.Remove(timeoutKey);
                }
                else if (msg.Result == NLRep_Load.Types.LoadResult.Undone)
                {
                    loadRet  = DSLoadResult.Undone;
                    data     = channel_.Decode(ByteString.Unsafe.GetBuffer(msg.Data));
                    errorStr = "Load Undone";
                }
                else if (msg.Result == NLRep_Load.Types.LoadResult.NotFound)
                {
                    loadRet = DSLoadResult.NotFound;
                    if (msg.HasError)
                    {
                        errorStr = msg.Error.ToString();
                    }
                    else
                    {
                        errorStr = "Load Key NOT Found in DataStore";
                    }
                    loadOpt_timeout_.Remove(timeoutKey);
                }
                else
                {
                    loadRet = DSLoadResult.PostError;
                    if (msg.HasError)
                    {
                        errorStr = msg.Error.ToString();
                    }
                    else
                    {
                        errorStr = "Load data error";
                    }
                    loadOpt_timeout_.Remove(timeoutKey);
                }
                cbbox.Invoke(loadRet, errorStr, data);
                //LogSys.Log(LOG_TYPE.DEBUG, "Load Reply ! result:({0}) session:({1})  error:({2})", loadRet, session, errorStr);
            }
        }