Ejemplo n.º 1
0
        /// <summary>
        /// Closes the current <see cref="FeedRecoveryManager"/> so it will stop checking for recovery requests
        /// </summary>
        /// <remarks>The <see cref="Close"/> method does not dispose resources associated with the current instance so the instance can be re-opened by calling the Open() method. In order to dispose resources associated
        /// with the current instance you must call the <see cref="IDisposable.Dispose"/> method. Once the instance is disposed it can no longer be opened.</remarks>
        public void Close()
        {
            if (Interlocked.CompareExchange(ref _isOpened, 0, 1) == 0)
            {
                return;
            }

            if (_inactivityTimer != null)
            {
                _inactivityTimer.Stop();
                _inactivityTimer.Elapsed -= OnTimerElapsed;
            }

            if (_systemSession != null)
            {
                _systemSession.Close();
                _systemSession.AliveReceived -= OnSystemSessionMessageReceived;
            }

            foreach (var recoveryTracker in _producerRecoveryManagers)
            {
                recoveryTracker.Value.StatusChanged          -= OnRecoveryTrackerStatusChanged;
                recoveryTracker.Value.EventRecoveryCompleted -= OnRecoveryTrackerEventRecoveryCompleted;
            }

            foreach (var sessionMessageManager in _sessionMessageManagers)
            {
                sessionMessageManager.FeedMessageReceived -= OnUserSessionMessageReceived;
            }
        }
        /// <summary>
        /// Closes the current <see cref="FeedRecoveryManager"/> so it will stop checking for recovery requests
        /// </summary>
        /// <remarks>The <see cref="Close"/> method does not dispose resources associated with the current instance so the instance can be re-opened by calling the Open() method. In order to dispose resources associated
        /// with the current instance you must call the <see cref="IDisposable.Dispose"/> method. Once the instance is disposed it can no longer be opened.</remarks>
        public void Close()
        {
            if (Interlocked.CompareExchange(ref _isOpened, 0, 1) == 0)
            {
                throw new InvalidOperationException("Current FeedRecoveryManager is already closed");
            }

            _inactivityTimer.Stop();
            _inactivityTimer.Elapsed -= OnTimerElapsed;

            _systemSession.Close();
            _systemSession.AliveReceived -= OnSystemSessionMessageReceived;

            foreach (var recoveryTracker in _producerRecoveryManagers)
            {
                recoveryTracker.Value.StatusChanged          -= OnRecoveryTrackerStatusChanged;
                recoveryTracker.Value.EventRecoveryCompleted -= OnRecoveryTrackerEventRecoveryCompleted;
            }

            foreach (var sessionMessageManager in _sessionMessageManagers)
            {
                sessionMessageManager.FeedMessageReceived -= OnUserSessionMessageReceived;
            }
        }