Beispiel #1
0
        public object Invoke(object target, MethodInfo methodInfo, object[] parameters)
        {
            if (methodInfo == null)
            {
                throw new ArgumentNullException("methodInfo is null");
            }
            // get class name
            // ReSharper disable once PossibleNullReferenceException
            string className = methodInfo.DeclaringType.FullName;

            ParameterInfo[] paramWrapper = methodInfo.GetParameters();

            var request = new MessageRequest();

            request.MessageId  = Guid.NewGuid().ToString();
            request.ClassName  = methodInfo.DeclaringType.FullName;
            request.MethodName = methodInfo.Name;
            request.ParamTypes = paramWrapper.Select(s => s.ParameterType).ToArray();
            request.Parameters = parameters;

            MessageSendHandler  handler  = RpcServerLoader.Instance.GetMessageSendHandler();
            MessageSendCallBack callBack = handler.SendRequest(request);

            return(callBack.Start());
        }
        public MessageSendCallBack SendRequest(MessageRequest request)
        {
            this.requestMessage = Unpooled.Buffer(MessageSendSettings.Size);
            var callBack = new MessageSendCallBack(request);

            this.callBackActions.TryAdd(request.MessageId, callBack);
            this.requestMessage.WriteBytes(this.serializer.Serialize(request));
            this.channelContext.WriteAndFlushAsync(this.requestMessage);

            return(callBack);
        }
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var byteBuffer = message as IByteBuffer;

            if (byteBuffer != null)
            {
                var response = (MessageResponse)this.serializer.Deserialize(byteBuffer.ToArray());

                MessageSendCallBack callBack = this.callBackActions[response.MessageId];
                callBack.Over(new MessageResponse());
                Console.WriteLine("Received from server: " + response.MessageId);
            }
        }