Example #1
0
        /// <summary>
        /// Stops the recovery operation if all snapshots were received
        /// </summary>
        /// <param name="interest">The <see cref="MessageInterest"/> of the session which received the snapshot message</param>
        /// <param name="result">If the operation was successfully completed, it contains the results of the completed recovery</param>
        /// <returns>True if the recovery operation could be completed; False otherwise</returns>
        /// <exception cref="InvalidOperationException">The recovery operation is not running</exception>
        public bool TryComplete(MessageInterest interest, out RecoveryResult result)
        {
            result = null;
            if (!IsRunning)
            {
                ExecutionLog.LogError($"{_producer.Name}: trying to complete recovery which is not running.");
                return(false);
            }

            _snapshotReceivedSessions.Add(interest);
            if (IsRecoveryDone())
            {
                result    = RecoveryResult.ForSuccess(_requestId, _startTime, InterruptionTime);
                IsRunning = false;
                return(true);
            }

            if (HasTimedOut())
            {
                result    = RecoveryResult.ForTimeOut(_requestId, _startTime);
                IsRunning = false;
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Completes the timed-out recovery operation
        /// </summary>
        /// <returns>A <see cref="RecoveryResult"/> containing recovery info</returns>
        /// <exception cref="InvalidOperationException">The recovery operation is not running or it has not timed-out</exception>
        public RecoveryResult CompleteTimedOut()
        {
            if (!IsRunning)
            {
                throw new InvalidOperationException("The recovery is not running");
            }
            if (!HasTimedOut())
            {
                throw new InvalidOperationException("The recovery operation is not timed-out");
            }

            IsRunning = false;
            return(RecoveryResult.ForTimeOut(_requestId, _startTime));
        }
Example #3
0
        /// <summary>
        /// Completes the timed-out recovery operation
        /// </summary>
        /// <returns>A <see cref="RecoveryResult"/> containing recovery info</returns>
        /// <exception cref="InvalidOperationException">The recovery operation is not running or it has not timed-out</exception>
        public RecoveryResult CompleteTimedOut()
        {
            if (!IsRunning)
            {
                ExecutionLog.LogError($"{_producer.Name}: trying to CompleteTimedOut recovery which is not running.");
                return(null);
            }
            if (!HasTimedOut())
            {
                ExecutionLog.LogError($"{_producer.Name}: trying to CompleteTimedOut recovery which is not timed-out.");
                return(null);
            }

            IsRunning = false;
            return(RecoveryResult.ForTimeOut(_requestId, _startTime));
        }
        /// <summary>
        /// Stops the the recovery operation if all snapshots were received
        /// </summary>
        /// <param name="interest">The <see cref="MessageInterest"/> of the session which received the snapshot message</param>
        /// <param name="result">If the operation was successfully completed, it contains the results of the completed recovery</param>
        /// <returns>True if the recovery operation could be completed; False otherwise</returns>
        /// <exception cref="InvalidOperationException">The recovery operation is not running</exception>
        public bool TryComplete(MessageInterest interest, out RecoveryResult result)
        {
            if (!IsRunning)
            {
                throw new InvalidOperationException("The recovery operation is not running");
            }

            result = null;
            _snapshotReceivedSessions.Add(interest);
            if (IsRecoveryDone())
            {
                result    = RecoveryResult.ForSuccess(_requestId, _startTime, _interruptionTime);
                IsRunning = false;
                return(true);
            }

            if (HasTimedOut())
            {
                result    = RecoveryResult.ForTimeOut(_requestId, _startTime);
                IsRunning = false;
                return(true);
            }
            return(false);
        }