示例#1
0
        public ISnapshotCompleted MapSnapShotCompleted(snapshot_complete message)
        {
            Contract.Requires(message != null);
            Contract.Ensures(Contract.Result <ISnapshotCompleted>() != null);

            return(Contract.Result <ISnapshotCompleted>());
        }
示例#2
0
        /// <summary>
        /// Validates the provided <see cref="snapshot_complete" /> message
        /// </summary>
        /// <param name="message">The <see cref="snapshot_complete" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateSnapshotCompleted(snapshot_complete message)
        {
            Contract.Requires(message != null);

            ValidateMessageProducer(message);

            return(ValidateMessage(message)
                ? ValidationResult.SUCCESS
                : ValidationResult.FAILURE);
        }
        /// <summary>
        /// Validates the provided <see cref="snapshot_complete" /> message
        /// </summary>
        /// <param name="message">The <see cref="snapshot_complete" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateSnapshotCompleted(snapshot_complete message)
        {
            Guard.Argument(message, nameof(message)).NotNull();

            ValidateMessageProducer(message);

            return(ValidateMessage(message)
                ? ValidationResult.SUCCESS
                : ValidationResult.FAILURE);
        }
示例#4
0
        /// <summary>
        /// Processes the <see cref="snapshot_complete"/> message. Only snapshot_complete(s) from user's sessions should be processed
        /// </summary>
        /// <param name="snapshotCompleted">The <see cref="snapshot_complete"/> message received on the system user's session</param>
        /// <param name="interest">The <see cref="MessageInterest"/> associated with the session which received the message</param>
        /// <returns>A <see cref="ProducerRecoveryStatus"/> specifying the new status of the manager or null reference if no change is needed</returns>
        private ProducerRecoveryStatus?ProcessSnapshotCompleteMessage(snapshot_complete snapshotCompleted, MessageInterest interest)
        {
            URN eventId;

            if (_producer.EventRecoveries.TryRemove(snapshotCompleted.request_id, out eventId))
            {
                ExecutionLog.Info($"Recovery with requestId={snapshotCompleted.request_id} for producer={Producer.Id}, eventId={eventId} completed.");
                EventRecoveryCompleted?.Invoke(this, new EventRecoveryCompletedEventArgs(snapshotCompleted.request_id, eventId));
                return(null);
            }

            //The snapshot message not for us
            if (!_recoveryOperation.IsRunning || !_recoveryOperation.RequestId.HasValue || _recoveryOperation.RequestId.Value != snapshotCompleted.RequestId)
            {
                return(null);
            }

            //Debug.Assert(Status == ProducerRecoveryStatus.Started);

            RecoveryResult recoveryResult;

            ExecutionLog.Debug($"SnapshotComplete[{"requestId" + snapshotCompleted.request_id}] for producer=[{"id=" + Producer.Id}] on session {interest.Name} received");
            if (!_recoveryOperation.TryComplete(interest, out recoveryResult))
            {
                //The recovery is not complete, nothing to do.
                ExecutionLog.Debug($"Recovery with requestId={snapshotCompleted.request_id} for producer={Producer.Id} is not yet completed. Waiting for snapshots from other sessions");
                return(null);
            }

            // The recovery operation completed. Check the result and act accordingly
            if (recoveryResult.Success)
            {
                // the recovery was interrupted
                if (recoveryResult.InterruptedAt.HasValue)
                {
                    ExecutionLog.Warn($"Recovery with requestId={snapshotCompleted.request_id} for producer={Producer.Id} completed with interruption at:{recoveryResult.InterruptedAt.Value}");
                    _producer.SetLastTimestampBeforeDisconnect(recoveryResult.InterruptedAt.Value);
                    return(ProducerRecoveryStatus.Error);
                }
                // the recovery was not interrupted
                var recoveryDuration = TimeProviderAccessor.Current.Now - recoveryResult.StartTime;
                ExecutionLog.Info($"Recovery with requestId={snapshotCompleted.request_id} for producer={Producer.Id} completed in {recoveryDuration.TotalSeconds} sec.");
                _producer.SetLastTimestampBeforeDisconnect(SdkInfo.FromEpochTime(snapshotCompleted.timestamp));
                return(_timestampTracker.IsBehind
                           ? ProducerRecoveryStatus.Delayed
                           : ProducerRecoveryStatus.Completed);
            }

            // The recovery operation timed-out
            var timeOutDuration = TimeProviderAccessor.Current.Now - recoveryResult.StartTime;

            ExecutionLog.Warn($"Recovery with requestId={snapshotCompleted.RequestId} timed out after:{timeOutDuration}");
            return(ProducerRecoveryStatus.Error);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotCompleteEventArgs"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="snapshot_complete"/> message received from the feed</param>
        /// <param name="interest">A <see cref="MessageInterest"/> of the session which received the message</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal SnapshotCompleteEventArgs(IFeedMessageMapper messageMapper, snapshot_complete feedMessage, MessageInterest interest, byte[] rawMessage)
        {
            Contract.Requires(messageMapper != null);
            Contract.Requires(feedMessage != null);
            Contract.Requires(interest != null);

            _messageMapper = messageMapper;
            _feedMessage   = feedMessage;
            _interest      = interest;
            _rawMessage    = rawMessage;
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotCompleteEventArgs"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="snapshot_complete"/> message received from the feed</param>
        /// <param name="interest">A <see cref="MessageInterest"/> of the session which received the message</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal SnapshotCompleteEventArgs(IFeedMessageMapper messageMapper, snapshot_complete feedMessage, MessageInterest interest, byte[] rawMessage)
        {
            Guard.Argument(messageMapper, nameof(messageMapper)).NotNull();
            Guard.Argument(feedMessage, nameof(feedMessage)).NotNull();
            Guard.Argument(interest, nameof(interest)).NotNull();

            _messageMapper = messageMapper;
            _feedMessage   = feedMessage;
            _interest      = interest;
            _rawMessage    = rawMessage;
        }
 /// <summary>
 /// Maps (converts) the provided <see cref="snapshot_complete"/> instance to the <see cref="ISnapshotCompleted"/> instance
 /// </summary>
 /// <param name="message">A <see cref="snapshot_complete"/> instance to be mapped (converted)</param>
 /// <returns>A <see cref="ISnapshotCompleted"/> instance constructed from information in the provided <see cref="snapshot_complete"/></returns>
 public ISnapshotCompleted MapSnapShotCompleted(snapshot_complete message)
 {
     return(new SnapshotCompleted(new MessageTimestamp(message.GeneratedAt, message.SentAt, message.ReceivedAt, SdkInfo.ToEpochTime(DateTime.Now)), _producerManager.Get(message.product), message.request_id));
 }