internal IDcaProducer CreateProducer(string producerInstance, ProducerInitializationParameters initParam, string producerType)
        {
            // Create the producer object
            IDcaProducer producer;

#if DotNetCoreClrLinux
            if (producerType.Equals(StandardPluginTypes.LttProducer))
            {
                producer = new LttProducer(
                    this.diskSpaceManager,
                    new TraceEventSourceFactory(),
                    initParam);
            }
#else
            if (producerType.Equals(StandardPluginTypes.EtlFileProducer))
            {
                var configReaderFactory = new EtlProducerConfigReader.EtlProducerConfigReaderFactory(
                    new ConfigReader(initParam.ApplicationInstanceId),
                    initParam.SectionName);
                producer = new EtlProducer(
                    this.diskSpaceManager,
                    configReaderFactory,
                    new TraceFileEventReaderFactory(),
                    new TraceEventSourceFactory(),
                    initParam);
            }
            else if (producerType.Equals(StandardPluginTypes.EtlInMemoryProducer))
            {
                var configReaderFactory = new EtlInMemoryProducerConfigReader.EtlInMemoryProducerConfigReaderFactory(
                    new ConfigReader(initParam.ApplicationInstanceId),
                    initParam.SectionName);
                producer = new EtlInMemoryProducer(
                    this.diskSpaceManager,
                    configReaderFactory,
                    new TraceFileEventReaderFactory(),
                    new TraceEventSourceFactory(),
                    initParam);
            }
#if !DotNetCoreClrIOT
            else if (producerType.Equals(StandardPluginTypes.PerfCounterConfigReader))
            {
                producer = new PerfCounterConfigReader(initParam);
            }
#endif
#endif
            else
            {
                Debug.Assert(
                    producerType.Equals(StandardPluginTypes.FolderProducer),
                    "No other producer types exist.");
                producer = new FolderProducer(this.diskSpaceManager, initParam);
            }

            Utility.TraceSource.WriteInfo(
                TraceType,
                "Created producer {0}.",
                producerInstance);

            return(producer);
        }
Exemple #2
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            this.disposed = true;

            if (!this.etlProducerSettings.ProcessingWinFabEtlFiles)
            {
                string applicationType = this.etlProducerSettings.ApplicationType;
                lock (ProducerWorkers)
                {
                    EtlProducerWorkerInfo workerInfo = ProducerWorkers.FirstOrDefault(w => w.ApplicationType.Equals(
                                                                                          applicationType,
                                                                                          StringComparison.Ordinal));
                    if (null != workerInfo)
                    {
                        // Tell the worker object to stop
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Stopping ETL producer worker object for application type {0} ...",
                            applicationType);

                        workerInfo.ProducerWorker.Dispose();
                        workerInfo.ProducerWorker = null;

                        workerInfo.EtlProducers.Remove(this);
                        if (0 == workerInfo.EtlProducers.Count)
                        {
                            // No one else is using the worker object. No need to
                            // restart it.
                            this.traceSource.WriteInfo(
                                this.logSourceId,
                                "No other ETL producer is using the ETL producer worker object for application type {0}, so no need to restart it.",
                                applicationType);
                            ProducerWorkers.Remove(workerInfo);
                        }
                        else
                        {
                            // Restart the worker. Arbitrarily choose one of the remaining
                            // producers for supplying settings.
                            this.traceSource.WriteInfo(
                                this.logSourceId,
                                "Restarting the ETL producer worker object for application type {0} because other ETL producers are using it.",
                                applicationType);
                            EtlProducer producer = workerInfo.EtlProducers[0];
                            EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters()
                            {
                                TraceSource = producer.traceSource,
                                IsReadingFromApplicationManifest = !producer.etlProducerSettings.ProcessingWinFabEtlFiles,
                                ApplicationType    = applicationType,
                                LogDirectory       = producer.logDirectory,
                                ProducerInstanceId = applicationType,
                                EtlProducers       = workerInfo.EtlProducers,
                                LatestSettings     = producer.etlProducerSettings
                            };
                            try
                            {
                                EtlProducerWorker newWorker = new EtlProducerWorker(
                                    newWorkerParam,
                                    this.diskSpaceManager,
                                    this.traceFileEventReaderFactory);
                                workerInfo.ProducerWorker = newWorker;
                            }
                            catch (InvalidOperationException)
                            {
                                this.traceSource.WriteError(
                                    this.logSourceId,
                                    "Failed to restart the ETL producer worker object for application type {0}.",
                                    applicationType);
                            }
                        }
                    }
                }
            }
            else
            {
                if (null != this.producerWorker)
                {
                    this.producerWorker.Dispose();
                }
            }

            GC.SuppressFinalize(this);
        }