private MetricStatsEngineQueue ReplaceStatsEngineQueue()
        {
            MetricStatsEngineQueue oldMetricStatsEngineQueue = _metricStatsEngineQueue;

            _metricStatsEngineQueue = CreateMetricStatsEngineQueue();
            return(oldMetricStatsEngineQueue);
        }
        public MetricAggregator(IDataTransportService dataTransportService, IMetricBuilder metricBuilder, IMetricNameService metricNameService, IEnumerable <IOutOfBandMetricSource> outOfBandMetricSources, IProcessStatic processStatic, IScheduler scheduler)
            : base(dataTransportService, scheduler, processStatic)
        {
            _metricBuilder          = metricBuilder;
            _metricNameService      = metricNameService;
            _outOfBandMetricSources = outOfBandMetricSources;

            foreach (var source in outOfBandMetricSources)
            {
                if (source != null)
                {
                    source.RegisterPublishMetricHandler(Collect);
                }
            }

            _metricStatsEngineQueue = CreateMetricStatsEngineQueue();
        }
        /// <summary>
        /// Replaces the current MetricStatsEngineQueue with a new one and combines all the StatsEngines in the
        /// old queue into a single MetricStatsCollection that can serve as the source of aggregated metrics to
        /// send to the collector.
        /// </summary>
        /// <returns></returns>
        private MetricStatsCollection GetStatsEngineForHarvest()
        {
            MetricStatsEngineQueue oldMetricStatsEngineQueue = ReplaceStatsEngineQueue();

            return(oldMetricStatsEngineQueue.GetStatsEngineForHarvest());
        }