Beispiel #1
0
        /// <summary>
        /// 关门
        /// </summary>
        public void Close()
        {
            _managerElectionWatchThreadCts.Cancel();
            if (_managerElectionWatchThread != null)
            {
                try
                {
                    _managerElectionWatchThread.Join();
                }
                catch (Exception ex)
                {
                    LogWriter.Write("wait for manager election thread exit go exception", ex, LogLevel.Warn);
                }
            }
            LogWriter.Write("clean manager elections thread has exited");

            if (_managerPlay != null)
            {
                _managerPlay.Stop();
                _managerPlay = null;
            }

            if (_workerPlay != null)
            {
                _workerPlay.Stop();
                _workerPlay = null;
            }

            StopCommunicator();
        }
Beispiel #2
0
        /// <summary>
        /// 处理当前成员Manager选举结果
        /// </summary>
        /// <param name="result">If set to <c>true</c> result.</param>
        /// <param name="currentMemberId">Current member identifier.</param>
        private void HandleManagerElectCompleted(bool result, string currentMemberId)
        {
            LogWriter.Write(string.Format("current member elect result: {0},New Manager is: {1}", result, currentMemberId));

            lock (_roleTransferLocker)
            {
                if (result)
                {
                    // 本机选举为Manager
                    if (_workerPlay != null)
                    {
                        _workerPlay.Stop();
                        _workerPlay = null;
                    }

                    // 剧本切换后,考虑到一些涉及成员的操作,比如作业任务重新分配,上个Manager节点可能永久下线,
                    // 应该首先执行这个健康检查,以避免进入不可用节点超时处理机制,耽误时间。
                    // 在这里放个这可能有点怪,如何处理呢?
                    Cluster.CheckMembersHealth();

                    if (_managerPlay == null)
                    {
                        _managerPlay = new ManagerPlay(this);
                        _managerPlay.Start();
                    }
                }
                else
                {
                    // 本机未能选举为Manager
                    if (_managerPlay != null)
                    {
                        _managerPlay.Stop();
                        _managerPlay = null;
                    }

                    if (_workerPlay == null)
                    {
                        _workerPlay = new WorkerPlay(this);
                        _workerPlay.Start();
                    }
                }
            }
        }