Exemplo n.º 1
0
        public void SendProtocol()
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            foreach (KVString kv in arguments)
            {
                args.Add(kv.key, kv.val);
            }
            HoxisProtocol proto = new HoxisProtocol
            {
                type   = protocolType,
                handle = FF.ObjectToJson(new ReqHandle {
                    req = method, ts = SF.GetTimeStamp(TimeUnit.Millisecond)
                }),
                err      = error,
                receiver = new HoxisProtocolReceiver {
                    type = receiverType, uid = receiverUID
                },
                sender = new HoxisProtocolSender {
                    uid = senderUID, aid = senderAgentID, loopback = loopback
                },
                action = new HoxisProtocolAction(method, new HoxisProtocolArgs(args)),
                desc   = description
            };

            HoxisDirector.Ins.ProtocolPost(proto);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rapidly send a request protocol
        /// </summary>
        /// <param name="method"></param>
        /// <param name="kvs"></param>
        public void Request(string method, params KVString[] kvs)
        {
            HoxisProtocol proto = new HoxisProtocol
            {
                type   = ProtocolType.Request,
                handle = FF.ObjectToJson(new ReqHandle {
                    req = method, ts = SF.GetTimeStamp(TimeUnit.Millisecond)
                }),
                err      = "",
                receiver = HoxisProtocolReceiver.undef,
                sender   = HoxisProtocolSender.undef,
                action   = new HoxisProtocolAction(method, kvs),
                desc     = ""
            };

            ProtocolPost(proto);
            // todo wait for response
        }
        /// <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;
        }
 /// <summary>
 /// New log name of an user
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public static string NewUserLogName(long uid)
 {
     return(FF.StringAppend(uid.ToString(), "@", SF.GetTimeStamp().ToString(), ".log"));
 }