|
|
@@ -123,16 +123,45 @@ namespace Model
|
|
|
this.tcs = null;
|
|
|
this.CancellationTokenSource = new CancellationTokenSource();
|
|
|
}
|
|
|
-
|
|
|
- public void Start()
|
|
|
+
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+ if (this.Id == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ base.Dispose();
|
|
|
+ this.LastSendTime = 0;
|
|
|
+ this.Address = null;
|
|
|
+ this.RunningTasks.Clear();
|
|
|
+ this.WaitingTasks.Clear();
|
|
|
+ this.failTimes = 0;
|
|
|
+ var t = this.tcs;
|
|
|
+ this.tcs = null;
|
|
|
+ t?.SetResult(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async void Start()
|
|
|
{
|
|
|
+ int appId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(this.Id);
|
|
|
+ this.Address = Game.Scene.GetComponent<StartConfigComponent>().Get(appId).GetComponent<InnerConfig>().Address;
|
|
|
+
|
|
|
this.UpdateAsync();
|
|
|
}
|
|
|
|
|
|
private void Add(ActorTask task)
|
|
|
{
|
|
|
+ if (this.Id == 0)
|
|
|
+ {
|
|
|
+ throw new Exception("ActorProxy Disposed! dont hold actorproxy");
|
|
|
+ }
|
|
|
this.WaitingTasks.Enqueue(task);
|
|
|
- this.AllowGet();
|
|
|
+ // failtimes > 0表示正在重试,这时候不能加到正在发送队列
|
|
|
+ if (this.failTimes == 0)
|
|
|
+ {
|
|
|
+ this.AllowGet();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void Remove()
|
|
|
@@ -147,8 +176,7 @@ namespace Model
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
ActorTask task = this.WaitingTasks.Dequeue();
|
|
|
this.RunningTasks.Enqueue(task);
|
|
|
|
|
|
@@ -172,18 +200,13 @@ namespace Model
|
|
|
|
|
|
private async void UpdateAsync()
|
|
|
{
|
|
|
- if (this.Address == null)
|
|
|
- {
|
|
|
- int appId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(this.Id);
|
|
|
- this.Address = Game.Scene.GetComponent<StartConfigComponent>().Get(appId).GetComponent<InnerConfig>().Address;
|
|
|
- }
|
|
|
while (true)
|
|
|
{
|
|
|
+ ActorTask actorTask = await this.GetAsync();
|
|
|
if (this.Id == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- ActorTask actorTask = await this.GetAsync();
|
|
|
if (actorTask == null)
|
|
|
{
|
|
|
return;
|
|
|
@@ -233,7 +256,6 @@ namespace Model
|
|
|
Game.Scene.GetComponent<ActorProxyComponent>().Remove(this.Id);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 等待一会再发送
|
|
|
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(this.failTimes * 500);
|
|
|
int appId = await Game.Scene.GetComponent<LocationProxyComponent>().Get(this.Id);
|
|
|
@@ -244,6 +266,7 @@ namespace Model
|
|
|
}
|
|
|
|
|
|
// 发送成功
|
|
|
+ this.LastSendTime = TimeHelper.Now();
|
|
|
this.failTimes = 0;
|
|
|
if (this.WindowSize < MaxWindowSize)
|
|
|
{
|
|
|
@@ -259,14 +282,12 @@ namespace Model
|
|
|
|
|
|
public void Send(AMessage message)
|
|
|
{
|
|
|
- this.LastSendTime = TimeHelper.Now();
|
|
|
ActorMessageTask task = new ActorMessageTask(this, message);
|
|
|
this.Add(task);
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
@@ -298,24 +319,5 @@ namespace Model
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
|
-
|
|
|
- public override void Dispose()
|
|
|
- {
|
|
|
- if (this.Id == 0)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- base.Dispose();
|
|
|
-
|
|
|
- this.LastSendTime = 0;
|
|
|
- this.Address = "";
|
|
|
- this.RunningTasks.Clear();
|
|
|
- this.WaitingTasks.Clear();
|
|
|
- this.failTimes = 0;
|
|
|
- var t = this.tcs;
|
|
|
- this.tcs = null;
|
|
|
- t?.SetResult(null);
|
|
|
- }
|
|
|
}
|
|
|
}
|