Example #1
0
        private void AddLttProducerWorkerToWorkerInfo(LttProducerWorkerInfo workerInfo, ProducerInitializationParameters initParam, long lttReadIntervalMinutes)
        {
            LttProducerWorker.LttProducerWorkerParameters parameters = CreateLttProducerWorkerParameters(workerInfo, initParam, lttReadIntervalMinutes);

            try
            {
                LttProducerWorker newWorker = new LttProducerWorker(parameters);
                workerInfo.LttProducers.Add(this);
                workerInfo.ProducerWorker = newWorker;
            }
            catch (InvalidOperationException)
            {
                this.traceSource.WriteError(
                    this.logSourceId,
                    "Failed to restart Ltt producer worker object.");
            }
        }
        public LttProducer(
            DiskSpaceManager diskSpaceManager,
            ITraceEventSourceFactory traceEventSourceFactory,
            ProducerInitializationParameters initParam)
        {
            this.logSourceId           = string.Concat(initParam.ApplicationInstanceId, "_", initParam.SectionName);
            this.traceSource           = traceEventSourceFactory.CreateTraceEventSource(FabricEvents.Tasks.FabricDCA);
            this.serviceConfigSections = new List <string>();
            this.consumerSinks         = initParam.ConsumerSinks;

            // Read the timer config value from dca section
            var  configReader = new ConfigReader(initParam.ApplicationInstanceId);
            long newLttReadIntervalMinutes = configReader.GetUnencryptedConfigValue(
                initParam.SectionName,
                LttProducerConstants.LttReadIntervalParamName,
                LttProducerConstants.DefaultLttReadIntervalMinutes);

            lock (ProducerWorkers)
            {
                LttProducerWorkerInfo workerInfo = ProducerWorkers.FirstOrDefault();
                if (null != workerInfo)
                {
                    // Existing worker object is available.
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Existing Ltt producer worker object. Restarting the worker object now.");

                    // Save the old value for comparision
                    long oldLttReadIntervalMinutes = workerInfo.ProducerWorker.LttReadIntervalMinutes;

                    // Restart the worker object
                    workerInfo.ProducerWorker.Dispose();
                    workerInfo.ProducerWorker = null;

                    // Keep the smaller value intact
                    // as this worker handles both producers Ltt trace conversion and table events
                    if (oldLttReadIntervalMinutes < newLttReadIntervalMinutes)
                    {
                        newLttReadIntervalMinutes = oldLttReadIntervalMinutes;
                    }

                    List <LttProducer> LttProducers = new List <LttProducer>(workerInfo.LttProducers)
                    {
                        this
                    };
                    LttProducerWorker.LttProducerWorkerParameters newWorkerParam = new LttProducerWorker.LttProducerWorkerParameters()
                    {
                        TraceSource            = this.traceSource,
                        LogDirectory           = initParam.LogDirectory,
                        ProducerInstanceId     = this.logSourceId,
                        LttProducers           = LttProducers,
                        LatestSettings         = initParam,
                        LttReadIntervalMinutes = newLttReadIntervalMinutes
                    };
                    try
                    {
                        LttProducerWorker newWorker = new LttProducerWorker(newWorkerParam);
                        workerInfo.LttProducers.Add(this);
                        workerInfo.ProducerWorker = newWorker;
                    }
                    catch (InvalidOperationException)
                    {
                        this.traceSource.WriteError(
                            this.logSourceId,
                            "Failed to restart Ltt producer worker object.");
                    }
                }
                else
                {
                    // Create a new worker object
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Creating Ltt producer worker object ...");

                    List <LttProducer> LttProducers = new List <LttProducer> {
                        this
                    };
                    LttProducerWorker.LttProducerWorkerParameters newWorkerParam = new LttProducerWorker.LttProducerWorkerParameters()
                    {
                        TraceSource            = this.traceSource,
                        LogDirectory           = initParam.LogDirectory,
                        ProducerInstanceId     = this.logSourceId,
                        LttProducers           = LttProducers,
                        LatestSettings         = initParam,
                        LttReadIntervalMinutes = newLttReadIntervalMinutes
                    };
                    try
                    {
                        LttProducerWorker newWorker = new LttProducerWorker(newWorkerParam);
                        workerInfo = new LttProducerWorkerInfo()
                        {
                            LttProducers   = new List <LttProducer>(),
                            ProducerWorker = newWorker
                        };
                        workerInfo.LttProducers.Add(this);
                        ProducerWorkers.Add(workerInfo);
                    }
                    catch (InvalidOperationException)
                    {
                        this.traceSource.WriteError(
                            this.logSourceId,
                            "Failed to create Ltt producer worker object.");
                    }
                }
            }
        }