コード例 #1
0
        public async Task Handle(Session session, Entity entity, ActorRequest message)
        {
            Message msg = message.AMessage as Message;

            if (msg == null)
            {
                Log.Error($"消息类型转换错误: {message.GetType().FullName} to {typeof (Message).Name}");
                return;
            }
            E e = entity as E;

            if (e == null)
            {
                Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}");
                return;
            }

            await this.Run(e, msg);

            // 等回调回来,session可以已经断开了,所以需要判断session id是否为0
            if (session.Id == 0)
            {
                return;
            }
            ActorResponse response = new ActorResponse
            {
                RpcId = message.RpcId
            };

            session.Reply(response);
        }
コード例 #2
0
ファイル: AMActorHandler.cs プロジェクト: kevinofsias/ET
 public async Task Handle(Session session, Entity entity, uint rpcId, ActorRequest message)
 {
     try
     {
         Request request = message.AMessage as Request;
         if (request == null)
         {
             Log.Error($"消息类型转换错误: {message.GetType().FullName} to {typeof (Request).Name}");
             return;
         }
         E e = entity as E;
         if (e == null)
         {
             Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}");
             return;
         }
         await this.Run(e, request, response =>
         {
             // 等回调回来,session可以已经断开了,所以需要判断session id是否为0
             if (session.Id == 0)
             {
                 return;
             }
             ActorResponse actorResponse = new ActorResponse
             {
                 AMessage = response
             };
             session.Reply(rpcId, actorResponse);
         });
     }
     catch (Exception e)
     {
         throw new Exception($"解释消息失败: {message.GetType().FullName}", e);
     }
 }
コード例 #3
0
		public async Task<bool> Handle(Session session, Entity entity, ActorRequest message)
		{
			((Session)entity).Send(message.AMessage);
			ActorResponse response = new ActorResponse();
			response.RpcId = message.RpcId;
			session.Reply(response);
			return true;
		}
コード例 #4
0
        public async Task Handle(Session session, Entity entity, ActorRequest message)
        {
            if (!this.handlers.TryGetValue(message.AMessage.GetType(), out IMActorHandler handler))
            {
                throw new Exception($"not found message handler: {MongoHelper.ToJson(message)}");
            }

            await handler.Handle(session, entity, message);
        }
コード例 #5
0
        public override async Task <AResponse> Run()
        {
            ActorRequest request = new ActorRequest()
            {
                Id = this.proxy.Id, AMessage = this.message
            };
            ActorResponse response = await this.proxy.RealCall <ActorResponse>(request, this.proxy.CancellationTokenSource.Token);

            return(response);
        }
コード例 #6
0
        public async Task Handle(Session session, Entity entity, ActorRequest message)
        {
            ((Session)entity).Send(message.AMessage);
            ActorResponse response = new ActorResponse
            {
                RpcId = message.RpcId
            };

            session.Reply(response);
        }
コード例 #7
0
        public async Task <bool> Handle(Session session, Entity entity, ActorRequest message)
        {
            if (!this.handlers.TryGetValue(message.AMessage.GetType(), out IMActorHandler handler))
            {
                Log.Error($"not found message handler: {message.GetType().FullName}");
                return(false);
            }

            return(await handler.Handle(session, entity, message));
        }
コード例 #8
0
        public override async Task <AResponse> Run()
        {
            ActorRequest request = new ActorRequest()
            {
                Id = this.proxy.Id, AMessage = this.message
            };
            Response response = await this.proxy.RealCall <Response>(request, this.proxy.CancellationTokenSource.Token);

            if (response.Error != ErrorCode.ERR_NotFoundActor)
            {
                this.Tcs.SetResult(response);
            }
            return(response);
        }
コード例 #9
0
        public async Task <IResponse> Run()
        {
            ActorRequest request = new ActorRequest()
            {
                Id = this.proxy.Id, AMessage = this.message
            };
            ActorResponse response = (ActorResponse)await this.proxy.RealCall(request, this.proxy.CancellationTokenSource.Token);

            if (response.Error != ErrorCode.ERR_NotFoundActor)
            {
                this.Tcs?.SetResult((IResponse)response.AMessage);
            }
            return(response);
        }
コード例 #10
0
        public async Task <Response> RealCall <Response>(ActorRequest request, CancellationToken cancellationToken) where Response : AResponse
        {
            try
            {
                //Log.Debug($"realcall {MongoHelper.ToJson(request)} {this.Address}");
                request.Id = this.Id;
                Session  session  = Game.Scene.GetComponent <NetInnerComponent>().Get(this.Address);
                Response response = await session.Call <Response>(request, cancellationToken);

                return(response);
            }
            catch (RpcException e)
            {
                Log.Error($"{this.Address} {e}");
                throw;
            }
        }
コード例 #11
0
		public async Task<bool> Handle(Session session, Entity entity, ActorRequest message)
		{
			return await Game.Scene.GetComponent<ActorMessageDispatherComponent>().Handle(session, entity, message);
		}
コード例 #12
0
 public async Task <bool> Handle(Session session, Entity entity, ActorRequest message)
 {
     ((Session)entity).Send(message.AMessage);
     return(true);
 }