Exemple #1
0
        private void ProcessProtocol(object state)
        {
            HoxisProtocol proto = (HoxisProtocol)state;

            OnProtocolEntry(proto);
            switch (proto.type)
            {
            case ProtocolType.Response:
                ReqHandle handle = FF.JsonToObject <ReqHandle>(proto.handle);
                // todo 消除等待
                if (proto.err != C.RESP_SUCCESS)
                {
                    OnResponseError(proto.err, proto.desc); return;
                }
                respCbTable[proto.action.method](proto.action.args);

                break;

            case ProtocolType.Synchronization:
                HoxisAgent agent = GetAgent(proto.sender.aid);
                if (agent != null)
                {
                    agent.CallBehaviour(proto.action);
                }
                break;

            case ProtocolType.Proclamation:

                break;
            }
        }
        /// <summary>
        /// Check the request name and time stamp
        /// </summary>
        /// <param name="proto"></param>
        /// <param name="ret"></param>
        public void CheckRequest(HoxisProtocol proto, out Ret ret)
        {
            ReqHandle handle = FF.JsonToObject <ReqHandle>(proto.handle, out ret);

            if (ret.code != 0)
            {
                return;
            }
            // Check if request name matches method name
            if (handle.req != proto.action.method)
            {
                ret = new Ret(LogLevel.Info, 1, "request name doesn't match method name"); return;
            }
            // Check if expired
            long ts   = handle.ts;
            long intv = Math.Abs(SF.GetTimeStamp(TimeUnit.Millisecond) - ts);

            if (intv > requestTTL)
            {
                ret = new Ret(LogLevel.Info, 1, "request is expired"); return;
            }
            ret = Ret.ok;
        }