コード例 #1
0
        private long _frequencyTicks;                                                                          // interlocked -- the current audit frequency, adjusted based on how long the audit takes (slower audits should run less frequently) and what the resulting rating status is.

        /// <summary>
        /// Constructs an <see cref="StatusAuditor"/> with the specified values.
        /// </summary>
        /// <param name="targetSystem">The name of the target system (if any).</param>
        /// <param name="baselineAuditFrequency">
        /// The baseline frequency with which audits should be run.
        /// The system will start running tests this frequently but will automatically tune the frequency to between one quarter this frequency and ten times this frequency based on the status rating (worse rating means do audits more frequently) and the duration of the audit (fast audits cause more frequent audits).
        /// This means that systems that process status audits faster will automatically be more responsive in reporting issues.
        /// If audits start to timeout, audits will happen less frequently even if they are failing so that the status tests don't contribute to system congestion.
        /// <see cref="TimeSpan.Zero"/> and negative time spans are treated as if they were <see cref="TimeSpan.MaxValue"/>.
        /// </param>
        /// <param name="status">The <see cref="Status"/> this auditor belongs to, or null if this should be a standalone auditor owned by the caller.</param>
        protected internal StatusAuditor(string targetSystem, TimeSpan baselineAuditFrequency, Status?status)
            : base(targetSystem)
        {
            _status = status;
            _baselineAuditFrequency = baselineAuditFrequency;

            _frequencyTicks = baselineAuditFrequency.Ticks;
            _nextAuditTime  = AmbientClock.UtcNow.AddMilliseconds(10).Ticks;
            // create a timer for the initial audit (we'll dispose of this one immediately as soon as that audit finishes)
            _initialAuditTimer           = new System.Timers.Timer(10);
            _initialAuditTimer.Elapsed  += InitialAuditTimer_Elapsed;
            _initialAuditTimer.AutoReset = false;
            // should we update periodically?
            if (baselineAuditFrequency < TimeSpan.MaxValue && baselineAuditFrequency > TimeSpan.FromTicks(0))
            {
                _auditTimer          = new AmbientEventTimer(TimeSpan.FromTicks(_frequencyTicks).TotalMilliseconds);
                _auditTimer.Elapsed += AuditTimer_Elapsed;
            }
            else // other parts of the code assume that _auditTimer is not null, so we will create one here that we don't hook up to any event handler
            {
                _auditTimer = new AmbientEventTimer(Int32.MaxValue - 1);
            }
            _auditTimer.AutoReset = false;
            // note that the audit timer should remain stopped until we start it after the first audit happens
            _shutdownInProgress = StatusResults.GetPendingResults(null, targetSystem);
        }
コード例 #2
0
 /// <summary>
 /// Constructs a <see cref="StatusChecker"/>.
 /// </summary>
 /// <param name="targetSystem">The name of the target system (if any).</param>
 /// <remarks>
 /// Target system names are concatenated with ancestor and descendant nodes and used to aggregate errors from the same system reported by multiple sources so that they can be summarized rather than listed individually.
 /// Targets with a leading slash character indicate that the system is a shared system and may have status results measured by other source systems which should be combined.
 /// Shared targets are not concatenated to the targets indicated by ancestor nodes, and their parents are ignored during summarization, treating shared systems as top-level nodes.
 /// Defaults to null, but should almost always be set to a non-empty string.
 /// Null should only be used to indicate that this node is not related to any specific target system, which would probably only happen if <see cref="StatusResults.NatureOfSystem"/> this, parent, and child nodes is such that some kind of special grouping is needed to make the overall status rating computation work correctly and the target system identifier for child nodes makes more sense without any identifier at this level.
 /// </remarks>
 protected internal StatusChecker(string targetSystem)
 {
     _targetSystem   = targetSystem;
     _resultsTracker = new StatusResultsTracker(StatusResults.GetPendingResults(null, targetSystem));
 }