/// <summary> /// Initializes a new instance of the <see cref="TimestampTracker"/> class /// </summary> /// <param name="producer">The <see cref="Producer"/> associated with the constructed instance</param> /// <param name="allInterests">A <see cref="IEnumerable{T}"/> containing <see cref="MessageInterest"/> for all created sessions</param> /// <param name="maxInactivitySeconds">The max interval in seconds between live messages on a system session</param> /// <param name="maxMessageAgeInSeconds">The maximum latency of the user messages</param> public TimestampTracker(Producer producer, IEnumerable <MessageInterest> allInterests, int maxInactivitySeconds, int maxMessageAgeInSeconds) { Guard.Argument(producer, nameof(producer)).NotNull(); Guard.Argument(maxInactivitySeconds, nameof(maxInactivitySeconds)).Positive(); Guard.Argument(maxMessageAgeInSeconds, nameof(maxInactivitySeconds)).Positive(); Guard.Argument(allInterests, nameof(allInterests)).NotNull().NotEmpty(); _maxInactivitySeconds = maxInactivitySeconds; _maxMessageAgeInSeconds = maxMessageAgeInSeconds; _systemAliveTimingInfo = new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now)); var aliveMessagesTimingInfo = new Dictionary <MessageInterest, MessageTimingInfo>(); var nonAliveMessagesTimingInfo = new Dictionary <MessageInterest, MessageTimingInfo>(); var allInterestsList = allInterests as IList <MessageInterest> ?? allInterests.ToList(); var producerScopes = producer.Scope.Select(MessageInterest.FromScope).ToList(); foreach (var interest in allInterestsList) { if (!interest.IsScopeInterest || producerScopes.Contains(interest)) { aliveMessagesTimingInfo.Add(interest, new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now))); nonAliveMessagesTimingInfo.Add(interest, new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now))); } } _aliveMessagesTimingInfo = new ReadOnlyDictionary <MessageInterest, MessageTimingInfo>(aliveMessagesTimingInfo); _nonAliveMessagesTimingInfo = new ReadOnlyDictionary <MessageInterest, MessageTimingInfo>(nonAliveMessagesTimingInfo); }
/// <summary> /// Initializes a new instance of the <see cref="TimestampTracker"/> class /// </summary> /// <param name="producer">The <see cref="Producer"/> associated with the constructed instance</param> /// <param name="allInterests">A <see cref="IEnumerable{T}"/> containing <see cref="MessageInterest"/> for all created sessions</param> /// <param name="maxInactivitySeconds">The max interval in seconds between live messages on a system session</param> /// <param name="maxMessageAgeInSeconds">The maximum latency of the user messages</param> public TimestampTracker(Producer producer, IEnumerable <MessageInterest> allInterests, int maxInactivitySeconds, int maxMessageAgeInSeconds) { Contract.Requires(producer != null); Contract.Requires(maxInactivitySeconds > 0); Contract.Requires(maxMessageAgeInSeconds > 0); Contract.Requires(allInterests != null); _producer = producer; _maxInactivitySeconds = maxInactivitySeconds; _maxMessageAgeInSeconds = maxMessageAgeInSeconds; _systemAliveTimingInfo = new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now)); var aliveMessagesTimingInfo = new Dictionary <MessageInterest, MessageTimingInfo>(); var nonAliveMessagesTimingInfo = new Dictionary <MessageInterest, MessageTimingInfo>(); var allInterestsList = allInterests as IList <MessageInterest> ?? allInterests.ToList(); var producerScopes = producer.Scope.Select(MessageInterest.FromScope).ToList(); foreach (var interest in allInterestsList) { if (!interest.IsScopeInterest || producerScopes.Contains(interest)) { aliveMessagesTimingInfo.Add(interest, new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now))); nonAliveMessagesTimingInfo.Add(interest, new MessageTimingInfo(SdkInfo.ToEpochTime(TimeProviderAccessor.Current.Now))); } } _aliveMessagesTimingInfo = new ReadOnlyDictionary <MessageInterest, MessageTimingInfo>(aliveMessagesTimingInfo); _nonAliveMessagesTimingInfo = new ReadOnlyDictionary <MessageInterest, MessageTimingInfo>(nonAliveMessagesTimingInfo); }