Пример #1
0
        /// <inheritdoc />
        protected override TimeSpan RunOnce(CancellationToken token)
        {
            // Every Process() invocation locks the sync root until
            // the changes have been processed. The goal is to minimize
            // total process time and to prevent locking for too long.
            // The following number has been empirically determined
            // via testing and it felt alright :P
            const int maxLineCount  = 5 * MaximumBatchSizePerSource;
            bool      performedWork = false;

            while (TryDequeueUpTo(maxLineCount, out var modifications))
            {
                performedWork = true;

                var changes = _index.Process(modifications);
                UpdateProperties();
                NotifyListeners(changes);
            }

            if (!performedWork)
            {
                UpdateProperties();
            }

            if (_pendingModifications.IsEmpty && _properties.GetValue(Core.Properties.PercentageProcessed) == Percentage.HundredPercent)
            {
                Listeners.Flush();
            }

            return(_maximumWaitTime);
        }
Пример #2
0
        /// <summary>
        ///    Processes all newly arrived log entries.
        /// </summary>
        /// <param name="token"></param>
        private void ProcessNewLogEntries(CancellationToken token)
        {
            if (!_fullSourceSection.IsEndOfSection(_currentSourceIndex))
            {
                int remaining   = _fullSourceSection.Index + _fullSourceSection.Count - _currentSourceIndex;
                int nextCount   = Math.Min(remaining, BatchSize);
                var nextSection = new LogSourceSection(_currentSourceIndex, nextCount);
                _source.GetEntries(nextSection, _array);

                for (int i = 0; i < nextCount; ++i)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    var logEntry = _array[i];
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Processing: LineIndex={0}, OriginalLineIndex={1}, LogEntryIndex={2}, Message={3}",
                                        logEntry.Index,
                                        logEntry.OriginalIndex,
                                        logEntry.LogEntryIndex,
                                        logEntry.RawContent);
                    }

                    if (_lastLogBuffer.Count == 0 || _lastLogBuffer[0].LogEntryIndex == logEntry.LogEntryIndex)
                    {
                        TryAddLogLine(logEntry);
                    }
                    else if (logEntry.LogEntryIndex != _lastLogBuffer[0].LogEntryIndex)
                    {
                        TryAddLogEntry(_lastLogBuffer);
                        _lastLogBuffer.Clear();
                        TryAddLogLine(logEntry);
                    }
                }

                _currentSourceIndex += nextCount;
            }

            // Now that we've processes all newly added log entries, we can check if we're at the end just yet...
            if (_fullSourceSection.IsEndOfSection(_currentSourceIndex))
            {
                TryAddLogEntry(_lastLogBuffer);
                UpdateProperties();                 //< we need to update our own properties after we've added the last entry, but before we notify listeners...
                Listeners.OnRead(_indices.Count);

                if (_properties.GetValue(Core.Properties.PercentageProcessed) == Percentage.HundredPercent)
                {
                    Listeners.Flush();
                }
            }
            else
            {
                UpdateProperties();
            }
        }
 public override object GetProperty(IReadOnlyPropertyDescriptor property)
 {
     return(_properties.GetValue(property));
 }