Пример #1
0
        /// <summary>
        /// Initializes a new instance of the BrokerManager class
        /// </summary>
        public BrokerManager(bool needRecover, ITelepathyContext context)
        {
            TraceHelper.TraceEvent(TraceEventType.Verbose, "[BrokerManager] Constructor: needRecover={0}", needRecover);
            this.headnode = SoaHelper.GetSchedulerName();

            this.context = context;

            this.brokerDic = new Dictionary <string, BrokerInfo>();

            this.staleSessionCleanupTimer = new Timer(this.CleanStaleSessionData, null, Timeout.Infinite, Timeout.Infinite);
#if HPCPACK
            if (!SoaHelper.IsOnAzure())
            {
                // TODO: on azure, about the MSMQ. Don't use the MSMQ in the Azure cluster.
                this.updateQueueLengthTimer = new Timer(this.CallbackToUpdateMSMQLength, null, Timeout.Infinite, Timeout.Infinite);
            }
#endif

            this.pool = new BrokerProcessPool();

            // TODO: enable recovery in Telepathy
#if HPCPACK
            if (needRecover && !BrokerLauncherEnvironment.Standalone)
            {
                this.ts = new CancellationTokenSource();
                CancellationToken ct = ts.Token;
                this.RecoverTask = Task.Run(async() => await this.RecoverThreadProc(ct), ct);
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// Dispose the broker manager
        /// </summary>
        /// <param name="disposing">indicating whether it's disposing</param>
        private void Dispose(bool disposing)
        {
            //dispose only once
            if (Interlocked.CompareExchange(ref this.disposed, 1, 0) == 1)
            {
                return;
            }

            List <string> sessionIdList;

            lock (this.brokerDic)
            {
                sessionIdList = new List <string>(this.brokerDic.Keys);
            }

            foreach (string sessionId in sessionIdList)
            {
                // Clean up will not throw exceptions
                this.CleanupAsync(sessionId, true).GetAwaiter().GetResult();
            }

            if (disposing)
            {
                if (this.RecoverTask != null && this.ts != null)
                {
                    // cancel the recover task
                    this.ts.Cancel();
                }

                this.ts?.Dispose();
                this.ts = null;

                // SchedulerHelper.Dispose() will not throw any exception
                if (this.schedulerHelper != null)
                {
                    this.schedulerHelper.Dispose();
                    this.schedulerHelper = null;
                }

                if (this.staleSessionCleanupTimer != null)
                {
                    this.staleSessionCleanupTimer.Dispose();
                    this.staleSessionCleanupTimer = null;
                }

                if (this.updateQueueLengthTimer != null)
                {
                    this.updateQueueLengthTimer.Dispose();
                    this.updateQueueLengthTimer = null;
                }

                if (this.pool != null)
                {
                    this.pool.Close();
                    this.pool = null;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the BrokerInfo class from broker recover info
        /// </summary>
        /// <param name="recoverInfo">indicating the broker recover info</param>
        /// <param name="brokerInfo">indicating the broker start info</param>
        /// <param name="auth">indicating the broker auth</param>
        /// <param name="customBroker">indicating the custom broker configuration</param>
        /// <param name="pool">indicating the broker process pool</param>
        public BrokerInfo(BrokerRecoverInfo recoverInfo, BrokerStartInfo brokerInfo, BrokerAuthorization auth, CustomBrokerRegistration customBroker, BrokerProcessPool pool)
        {
            this.callbackToCloseBroker = new ThreadHelper <IAsyncResult>(new AsyncCallback(this.OnCloseBroker)).CallbackRoot;
            this.durable          = recoverInfo.Durable;
            this.brokerInfo       = brokerInfo;
            this.sessionId        = recoverInfo.SessionId;
            this.sessionStartInfo = recoverInfo.StartInfo;
            this.auth             = auth;
            this.customBroker     = customBroker;
            this.pool             = pool;

            this.sessionStartInfo.IpAddress = BrokerLauncherSettings.Default.SvcHostList.Cast <string>().ToArray();
            this.sessionStartInfo.RegPath   = BrokerLauncherSettings.Default.CCP_SERVICEREGISTRATION_PATH;
        }