|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using Ice;
|
|
|
using System.Web.Helpers;
|
|
|
using CommonLang;
|
|
|
+using System.Collections.Concurrent;
|
|
|
|
|
|
namespace Pomelo
|
|
|
{
|
|
@@ -72,18 +73,36 @@ namespace Pomelo
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /** ice通知消息信息 */
|
|
|
+ public class ICENotifyData
|
|
|
+ {
|
|
|
+ public string name;
|
|
|
+ public string jsonData; // 通知数据
|
|
|
+ public long failTime; // 失败时间
|
|
|
+
|
|
|
+ public ICENotifyData(string name, string jsonData)
|
|
|
+ {
|
|
|
+ this.name = name;
|
|
|
+ this.jsonData = jsonData;
|
|
|
+ this.failTime = CommonLang.TimeUtil.GetTimestampMS();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public class ICEZoneSession
|
|
|
{
|
|
|
private CommonLang.Log.Logger log = CommonLang.Log.LoggerFactory.GetLogger("ICEZoneSession");
|
|
|
|
|
|
+ public ZoneManagerCallbackPrx client;
|
|
|
public ZoneManagerCallbackPrx callback;
|
|
|
public IFastSession fastSession;
|
|
|
public int failTimes = 0;
|
|
|
+ public ConcurrentQueue<ICENotifyData> notifyFailData = new ConcurrentQueue<ICENotifyData>();
|
|
|
|
|
|
- public ICEZoneSession(ZoneManagerCallbackPrx callback)
|
|
|
+ public ICEZoneSession(ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ this.client = client;
|
|
|
this.callback = callback;
|
|
|
this.failTimes = 0;
|
|
|
}
|
|
@@ -99,12 +118,50 @@ namespace Pomelo
|
|
|
this.failTimes = 0;
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /** 重新通知所有时间 */
|
|
|
+ public void RetryFailNotifys()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ this.callback.ice_ping();
|
|
|
+ }
|
|
|
+ catch (System.Exception e)
|
|
|
+ {
|
|
|
+ log.Warn("RetryFailNotifys ping 异常:", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ this.callback = (ZoneManagerCallbackPrx)client.ice_oneway();
|
|
|
+ log.Info("RetryFailNotifys start begin 1: " + notifyFailData.Count);
|
|
|
+ this.callback.ice_ping();
|
|
|
+ long ltimeEnd = CommonLang.TimeUtil.GetTimestampMS() - 120000;
|
|
|
+ while (notifyFailData.Count > 0)
|
|
|
+ {
|
|
|
+ ICENotifyData notifyData = new ICENotifyData("", "");
|
|
|
+ if (notifyFailData.TryDequeue(out notifyData) && ltimeEnd < notifyData.failTime)
|
|
|
+ {
|
|
|
+ log.Info("RetryFailNotifys start begin 2: " + notifyFailData.Count + ", " + notifyData.name + ", " + notifyData.jsonData + ", time: " + notifyData.failTime);
|
|
|
+ this.callback.eventNotify(notifyData.name, notifyData.jsonData);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log.Info("RetryFailNotifys start begin 3 skip: " + notifyFailData.Count + ", " + notifyData.name + ", " + notifyData.jsonData + ", time: " + notifyData.failTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(System.Exception e)
|
|
|
+ {
|
|
|
+ log.Error("RetryFailNotifys catch: " + e.Message, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public class IceManager : Ice.Application
|
|
|
{
|
|
|
private static IceManager _instance;
|
|
|
-
|
|
|
private CommonLang.Log.Logger log = CommonLang.Log.LoggerFactory.GetLogger("IceManager");
|
|
|
private Dictionary<string, Ice.ObjectImpl> proxys;
|
|
|
|
|
@@ -120,7 +177,7 @@ namespace Pomelo
|
|
|
return callbacks.Get(gameServerId);
|
|
|
}
|
|
|
}
|
|
|
- public int setCallback(string gameServerId, ZoneManagerCallbackPrx callback)
|
|
|
+ public int setCallback(string gameServerId, ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
|
|
|
{
|
|
|
lock (callbacks)
|
|
|
{
|
|
@@ -137,12 +194,14 @@ namespace Pomelo
|
|
|
{
|
|
|
log.Error("ice连入,远端已经失效,重新设置!");
|
|
|
cacheSession.callback = callback;
|
|
|
- return 0;
|
|
|
+ //cacheSession.RetryFailNotifys();
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- callbacks.Put(gameServerId, new ICEZoneSession(callback));
|
|
|
+ callbacks.Put(gameServerId, new ICEZoneSession(client, callback));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -231,11 +290,11 @@ namespace Pomelo
|
|
|
initData.properties.setProperty("Ice.ThreadPool.Server.Size", "4");
|
|
|
initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "8");
|
|
|
initData.properties.setProperty("Ice.MessageSizeMax", "10240");
|
|
|
- //initData.properties.setProperty("Ice.RetryIntervals", "0 500 2000 5000");
|
|
|
+ initData.properties.setProperty("Ice.RetryIntervals", "0 500 2000 5000");
|
|
|
|
|
|
initData.properties.setProperty("Ice.Trace.Network", config.isTraceNetwork ? "1" : "0");
|
|
|
initData.properties.setProperty("Ice.Trace.Protocol", config.isTraceProtocol ? "1" : "0");
|
|
|
- //initData.properties.setProperty("Ice.Trace.Retry", "2");
|
|
|
+ initData.properties.setProperty("Ice.Trace.Retry", "2");
|
|
|
|
|
|
var thread = new System.Threading.Thread(() =>
|
|
|
{
|