public static bool FilterWillConsume(IMetricSeriesFilter seriesFilter, MetricSeries series, out IMetricValueFilter valueFilter) { valueFilter = null; try { return((seriesFilter == null) || seriesFilter.WillConsume(series, out valueFilter)); } catch { // Protect against errors in user's implementation of IMetricSeriesFilter.WillConsume(..). // If it throws, assume that the filter is not functional and accept all values. return(true); } }
private List <MetricAggregate> GetPersistentAggregations(DateTimeOffset tactTimestamp, IMetricSeriesFilter previousFilter) { // Complete each persistent aggregator: // The Enumerator of GrowingCollection is a thread-safe lock-free implementation that operates on a "snapshot" of a collection taken at the // time when the enumerator is created. We expand the foreach statement (like the compiler normally does) so that we can use the typed // enumerator's Count property which is constsent with the data in the snapshot. GrowingCollection <IMetricSeriesAggregator> .Enumerator persistentValsAggregators = _aggregatorsForPersistent.Aggregators.GetEnumerator(); List <MetricAggregate> persistentValsAggregations = new List <MetricAggregate>(capacity: persistentValsAggregators.Count); try { while (persistentValsAggregators.MoveNext()) { IMetricSeriesAggregator aggregator = persistentValsAggregators.Current; if (aggregator != null) { // Persistent aggregators are always active, regardless of filters for a particular cycle. // But we can apply the cycle's filters to determine whether or not to pull the aggregator // for a aggregate at this time. Of course, only series filters, not value filters, can be considered. IMetricValueFilter unusedValueFilter; bool satisfiesFilter = (previousFilter == null) || (previousFilter.WillConsume(aggregator.DataSeries, out unusedValueFilter)); if (satisfiesFilter) { MetricAggregate aggregate = aggregator.CompleteAggregation(tactTimestamp); if (aggregate != null) { persistentValsAggregations.Add(aggregate); } } } } } finally { persistentValsAggregators.Dispose(); } return(persistentValsAggregations); }
private static bool AddAggregator(IMetricSeriesAggregator aggregator, AggregatorCollection aggregatorCollection) { if (aggregatorCollection == null) { return(false); } IMetricSeriesFilter seriesFilter = aggregatorCollection.Filter; IMetricValueFilter valueFilter = null; if (seriesFilter != null && !seriesFilter.WillConsume(aggregator.DataSeries, out valueFilter)) { return(false); } aggregator.Reset(aggregatorCollection.PeriodStart, valueFilter); aggregatorCollection.Aggregators.Add(aggregator); return(true); }