protected internal void StopQueues()
        {
#if NETSTANDARD2_0
            sbClients.Each(async kvp => await kvp.Value.CloseAsync());
#else
            sbClients.Each(kvp => kvp.Value.Close());
#endif
            sbClients.Clear();
        }
Example #2
0
        public override Task <ParameterIdentification> InitializeRun(CancellationToken cancellationToken)
        {
            var parallelOptions = new ParallelOptions
            {
                CancellationToken      = cancellationToken,
                MaxDegreeOfParallelism = _coreUserSettings.MaximumNumberOfCoresToUse
            };

            // save which simulations was created based on the old simulation so that we can swap OUTSIDE of the parallel loop
            var concurrentDictionary = new ConcurrentDictionary <ISimulation, ISimulation>();

            return(Task.Run(() =>
            {
                var newParameterIdentification = _cloneManager.Clone(ParameterIdentification);

                //ToList() required here as the collection will be modified
                Parallel.ForEach(newParameterIdentification.AllSimulations.ToList(), parallelOptions, originalSimulation =>
                {
                    parallelOptions.CancellationToken.ThrowIfCancellationRequested();
                    var newSimulation = createNewSimulationFrom(originalSimulation, _calculationMethodCombination.CalculationMethods);
                    concurrentDictionary.TryAdd(originalSimulation, newSimulation);
                });

                concurrentDictionary.Each(kv =>
                {
                    //Key is the old simulation, value is the corresponding updated new simulation
                    newParameterIdentification.SwapSimulations(kv.Key, kv.Value);
                });

                newParameterIdentification.Description = _descriptionCreator.CreateDescriptionFor(_calculationMethodCombination, _runMode, _isSingleCategory);
                return newParameterIdentification;
            }, cancellationToken));
        }
Example #3
0
        public IDictionary <string, Metric> GetMetrics()
        {
            var timingStatistics = new Dictionary <string, Metric>();

            metrics.Each(kv =>
            {
                var metric = kv.Value;
                timingStatistics[kv.Key] = metric.Snapshot();
                metric.Clear();
            });
            return(timingStatistics);
        }
Example #4
0
        public FanoutMetric GetMetric(string key)
        {
            FanoutMetric metric;

            if (!metrics.TryGetValue(key, out metric))
            {
                metric = new FanoutMetric();
                lock (this)
                {
                    listeners.Each(l => metric.AddFanout(l.Key.GetMetric(key)));
                }
                metric = metrics.AddOrUpdate(key, metric, (k, m) => metric);
            }
            return(metric);
        }
Example #5
0
 public void Clear()
 {
     _objects.Each(@object => TryDispose(@object.Value));
     _objects.Clear();
 }
Example #6
0
 internal void EachInstance(Action <Type, Instance> action)
 {
     _families.Each(family => family.Value.Instances.Each(i => action(family.Value.PluginType, i)));
 }