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); } } }
private RpcId getForwardRpcId(string methodName) { RpcId rpcId = null; _forwardRpcIdMap.TryGetValue(methodName, out rpcId); return(rpcId); }
public virtual void forward(RpcId rpcId, params object[] args) { if (delRpcForwarding != null) { delRpcForwarding(rpcId); } }
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); }
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); }
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); }
public RpcBind(RpcId rpcId, MethodInfo mi) { _rpcId = rpcId; _method = mi; _parameterInfos = mi.GetParameters(); }