示例#1
0
        private void initRpcs()
        {
            Type currentType            = GetType();
            RpcClassAttribute classAttr =
                Attribute.GetCustomAttribute(currentType, typeof(RpcClassAttribute)) as RpcClassAttribute;

            if (classAttr == null)
            {
                throw new MessageException("RpcClassAttribute NOT FOUND!");
            }

            MethodInfo[] methods = currentType.GetMethods(BindingFlags.Public |
                                                          BindingFlags.NonPublic | BindingFlags.Instance);

            for (int i = 0, count = methods.Length; i < count; ++i)
            {
                MethodInfo mi = methods[i];
                if (Attribute.IsDefined(mi, typeof(RpcForwardAttribute)))
                {
                    string rpcName = makeRpcName(classAttr.className, mi.Name, mi.GetParameters().Length);
                    RpcId  rpcId   = new RpcId(rpcName);
                    _forwardRpcIdMap.Add(mi.Name, rpcId);
                }
                else if (Attribute.IsDefined(mi, typeof(RpcReceiveAttribute)))
                {
                    string  rpcName = makeRpcName(classAttr.className, mi.Name, mi.GetParameters().Length);
                    RpcId   rpcId   = new RpcId(rpcName);
                    RpcBind rpcBind = new RpcBind(rpcId, mi);
                    _receiveRpcMap.Add(rpcId.value, rpcBind);
                }
            }
        }
示例#2
0
        private RpcId getForwardRpcId(string methodName)
        {
            RpcId rpcId = null;

            _forwardRpcIdMap.TryGetValue(methodName, out rpcId);
            return(rpcId);
        }
示例#3
0
 public virtual void forward(RpcId rpcId, params object[] args)
 {
     if (delRpcForwarding != null)
     {
         delRpcForwarding(rpcId);
     }
 }
示例#4
0
        public bool receive(out RpcId rpcId, UInt32 rpcIdValue, InputStream inputStream)
        {
            RpcBind rpcBind = getRpcBind(rpcIdValue);

            if (rpcBind == null)
            {
                rpcId = null;
                return(false);
            }
            rpcId = rpcBind.rpcId;
            rpcBind.execute(this, inputStream);
            return(true);
        }
示例#5
0
        public override void forward(RpcId rpcId, params object[] args)
        {
            base.forward(rpcId, args);

            StreamBuffer marshaledBuffer = marshal(rpcId, args);

            ushort bodySize    = (ushort)marshaledBuffer.size();
            byte   messageType = (byte)MessageType.Value.csmtRpc;

            _sendStream.replace(StreamBufferPool.instance.acquire());
            _sendStream.write(bodySize);
            _sendStream.write(messageType);
            _sendStream.write(marshaledBuffer.data, marshaledBuffer.size());
            send(_sendStream.buffer);
        }
示例#6
0
 private StreamBuffer marshal(RpcId rpcId, params object[] args)
 {
     _marshalStream.reset();
     _marshalStream.write(rpcId.value);
     for (int i = 0, count = args.Length; i < count; ++i)
     {
         object arg = args[i];
         if (arg is IStreamable)
         {
             (arg as IStreamable).serialize(_marshalStream);
         }
         else
         {
             _marshalStream.writeObject(arg);
         }
     }
     return(_marshalStream.buffer);
 }
示例#7
0
 public RpcBind(RpcId rpcId, MethodInfo mi)
 {
     _rpcId          = rpcId;
     _method         = mi;
     _parameterInfos = mi.GetParameters();
 }