private static async Task RunTask(this ActorMessageSender self, ActorTask task) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(null); //Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.Address); task.ActorMessage.ActorId = self.ActorId; IResponse response = await session.Call(task.ActorMessage); Log.Debug("runTask:" + task.ActorMessage.GetType().FullName); Log.Debug("runTask1:" + response.Tag); // 发送成功 switch (response.Tag) { case ErrorCode.ERR_NotFoundActor: // 如果没找到Actor,重试 ++self.FailTimes; // 失败MaxFailTimes次则清空actor发送队列,返回失败 if (self.FailTimes > self.MaxFailTimes) { // 失败直接删除actorproxy Log.Info($"actor send message fail, actorid: {self.Id}"); self.Error = response.Tag; self.GetParent <ActorMessageSenderComponent>().Remove(self.Id); return; } // 等待1s再发送 await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); //self.ActorId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(self.Id); //self.Address = Game.Scene.GetComponent<StartConfigComponent>() // .Get(IdGenerater.GetAppIdFromId(self.ActorId)) // .GetComponent<InnerConfig>().IPEndPoint; self.AllowGet(); return; case ErrorCode.ERR_ActorNoMailBoxComponent: self.Error = response.Tag; self.GetParent <ActorMessageSenderComponent>().Remove(self.Id); return; default: self.LastSendTime = TimeHelper.Now(); self.FailTimes = 0; self.WaitingTasks.Dequeue(); task.Tcs?.SetResult(response); return; } }
private static void Add(this ActorMessageSender self, ActorTask task) { if (self.IsDisposed) { throw new Exception("ActorProxy Disposed! dont hold actorproxy"); } self.WaitingTasks.Enqueue(task); // failtimes > 0表示正在重试,这时候不能加到正在发送队列 if (self.FailTimes == 0) { self.AllowGet(); } }