Exemple #1
0
        public Task <Response> Call <Response>(ARequest request) where Response : AResponse
        {
            ActorRpcTask <Response> task = new ActorRpcTask <Response>(this, request);

            this.Add(task);
            return(task.Tcs.Task);
        }
Exemple #2
0
        /// <summary>
        /// Rpc调用
        /// </summary>
        public Task <Response> Call <Response>(ARequest request, CancellationToken cancellationToken)
            where Response : AResponse
        {
            request.RpcId = ++RpcId;
            this.SendMessage(request);

            var tcs = new TaskCompletionSource <Response>();

            this.requestCallback[RpcId] = (message) =>
            {
                try
                {
                    Response response = (Response)message;
                    if (response.Error > 100)
                    {
                        tcs.SetException(new RpcException(response.Error, response.Message));
                        return;
                    }
                    //Log.Debug($"recv: {MongoHelper.ToJson(response)}");
                    tcs.SetResult(response);
                }
                catch (Exception e)
                {
                    tcs.SetException(new Exception($"Rpc Error: {typeof(Response).FullName}", e));
                }
            };

            cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); });

            return(tcs.Task);
        }
Exemple #3
0
        /// <summary>
        /// Rpc调用,发送一个消息,等待返回一个消息
        /// </summary>
        public Task <AResponse> Call(ARequest request, bool isHotfix)
        {
            request.RpcId = ++RpcId;
            this.SendMessage(request);

            var tcs = new TaskCompletionSource <AResponse>();

            this.requestCallback[RpcId] = (message) =>
            {
                try
                {
                    AResponse response = (AResponse)message;
                    if (response.Error > 100)
                    {
                        tcs.SetException(new RpcException(response.Error, response.Message));
                        return;
                    }
                    //Log.Debug($"recv: {MongoHelper.ToJson(response)}");
                    tcs.SetResult(response);
                }
                catch (Exception e)
                {
                    tcs.SetException(new Exception($"Rpc Error: {message.GetType().FullName}", e));
                }
            };

            return(tcs.Task);
        }
Exemple #4
0
        /// <summary>
        /// Rpc调用,发送一个消息,等待返回一个消息
        /// </summary>
        public Task <Response> Call <Response>(ARequest rRequest) where Response : AResponse
        {
            rRequest.RpcId = ++RpcId;
            this.SendMessage(rRequest);

            var tcs = new TaskCompletionSource <Response>();

            this.mRequestCallback[RpcId] = (message) =>
            {
                try
                {
                    Response response = (Response)message;
                    if (response.Error > 100)
                    {
                        tcs.SetException(new RpcException(response.Error, response.Message));
                        return;
                    }
                    Log.Debug($"recv: {this.mNetwork.MessagePacker.SerializeToText(response)}");
                    tcs.SetResult(response);
                }
                catch (Exception e)
                {
                    tcs.SetException(new Exception($"Rpc Error: {typeof(Response).FullName}", e));
                }
            };
            return(tcs.Task);
        }
Exemple #5
0
        public Task <Response> Call <Response>(ARequest request) where Response : AResponse
        {
            this.LastSendTime = TimeHelper.Now();
            ActorRpcTask <Response> task = new ActorRpcTask <Response>(this, request);

            this.Add(task);
            return(task.Tcs.Task);
        }
Exemple #6
0
        /// <summary>
        /// Rpc调用
        /// </summary>
        public void CallWithAction(ARequest request, Action <AResponse> action)
        {
            request.RpcId = ++RpcId;
            this.SendMessage(request);

            this.requestCallback[RpcId] = (message) =>
            {
                try
                {
                    AResponse response = (AResponse)message;
                    action(response);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            };
        }
Exemple #7
0
 public ActorRpcTask(ActorProxy proxy, ARequest message)
 {
     this.proxy   = proxy;
     this.message = message;
 }