/// <summary> /// /// </summary> public void Stop() { Interlocked.Exchange(ref _runningQueue, 0); if (EnableHttp) { httpListener.Stop(); } socketLintener.Close(); OnServiceStop(); try { singal.Set(); threadPool.Dispose(); queueProcessThread.Abort(); _LockedQueueChecker.Dispose(); singal.Dispose(); EntitySyncManger.Dispose(); threadPool = null; queueProcessThread = null; _LockedQueueChecker = null; singal = null; } catch { } GC.SuppressFinalize(this); }
/// <summary> /// /// </summary> protected GameSocketHost() { ActionDispatcher = new ActionDispatcher(); int port = GameEnvironment.Setting.GamePort; IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port); int maxConnections = ConfigUtils.GetSetting("MaxConnections", 10000); int backlog = ConfigUtils.GetSetting("Backlog", 1000); int maxAcceptOps = ConfigUtils.GetSetting("MaxAcceptOps", 1000); int bufferSize = ConfigUtils.GetSetting("BufferSize", 8192); int expireInterval = ConfigUtils.GetSetting("ExpireInterval", 600) * 1000; int expireTime = ConfigUtils.GetSetting("ExpireTime", 3600) * 1000; threadPool = new SmartThreadPool(180 * 1000, 100, 5); threadPool.Start(); var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime); socketLintener = new SocketListener(socketSettings); socketLintener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived); socketLintener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted); socketLintener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected); httpListener = new HttpListener(); var httpHost = ConfigUtils.GetSetting("Game.Http.Host"); var httpPort = ConfigUtils.GetSetting("Game.Http.Port", 80); var httpName = ConfigUtils.GetSetting("Game.Http.Name", "Service.aspx"); if (!string.IsNullOrEmpty(httpHost)) { EnableHttp = true; var hosts = httpHost.Split(','); foreach (var host in hosts) { string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ? host : "http://" + host; httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, httpPort, httpName)); } } Interlocked.Exchange(ref _runningQueue, 1); queueProcessThread = new Thread(ProcessQueue); queueProcessThread.Start(); _LockedQueueChecker = new Timer(LockedQueueChecker, null, 100, 100); }
/// <summary> /// Initializes a new instance of the <see cref="ZyGames.Framework.RPC.Sockets.Threading.WorkItemsGroup"/> class. /// </summary> /// <param name="stp">Stp.</param> /// <param name="concurrency">Concurrency.</param> /// <param name="wigStartInfo">Wig start info.</param> public WorkItemsGroup( SmartThreadPool stp, int concurrency, WIGStartInfo wigStartInfo) { if (concurrency <= 0) { throw new ArgumentOutOfRangeException( "concurrency", #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) concurrency, #endif "concurrency must be greater than zero"); } _stp = stp; _concurrency = concurrency; _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly(); _workItemsQueue = new PriorityQueue(); Name = "WorkItemsGroup"; // The _workItemsInStpQueue gets the number of currently executing work items, // because once a work item is executing, it cannot be cancelled. _workItemsInStpQueue = _workItemsExecutingInStp; _isSuspended = _workItemsGroupStartInfo.StartSuspended; }
/// <summary> /// Start /// </summary> public static void Start() { _queueWatchTimers = new Timer[SqlSyncQueueNum]; for (int i = 0; i < SqlSyncQueueNum; i++) { _queueWatchTimers[i] = new Timer(OnCheckSqlSyncQueue, i, 100, 100); } _threadPools = new SmartThreadPool(180 * 1000, 100, 5); _threadPools.Start(); }
public ThreadEntry(SmartThreadPool stp) { _associatedSmartThreadPool = stp; _creationTime = DateTime.UtcNow; _lastAliveTime = DateTime.MinValue; }
/// <summary> /// Start /// </summary> /// <param name="setting"></param> public static void Start(CacheSetting setting) { _queueWatchTimers = new Timer[DataSyncQueueNum]; for (int i = 0; i < DataSyncQueueNum; i++) { _queueWatchTimers[i] = new Timer(OnCheckRedisSyncQueue, i, 100, 100); } _threadPools = new SmartThreadPool(180 * 1000, 100, 5); _threadPools.Start(); _enableWriteToDb = setting.EnableWriteToDb; if (_enableWriteToDb) { int sqlSyncInterval = ConfigUtils.GetSetting("Game.Cache.UpdateDbInterval", 300 * 1000); _sqlWaitTimers = new Timer[SqlWaitSyncQueueNum]; for (int i = 0; i < SqlWaitSyncQueueNum; i++) { _sqlWaitTimers[i] = new Timer(OnCheckSqlWaitSyncQueue, i, 100, sqlSyncInterval); } SqlStatementManager.Start(); } }