private static void Add(this ActorProxy 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(); } }
private static async Task RunTask(this ActorProxy self, ActorTask task) { try { IResponse response = await task.Run(); // 如果没找到Actor,重试 if (response.Error == ErrorCode.ERR_NotFoundActor) { ++self.FailTimes; // 失败10次则清空actor发送队列,返回失败 if (self.FailTimes > self.MaxFailTimes) { // 失败直接删除actorproxy Log.Info($"actor send message fail, actorid: {self.Id}"); Game.Scene.GetComponent <ActorProxyComponent>().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; } // 发送成功 self.LastSendTime = TimeHelper.Now(); self.FailTimes = 0; self.WaitingTasks.Dequeue(); } catch (Exception e) { Log.Error(e); } }