public void Dispose() { if (_isDisposed) { return; } _isDisposed = true; if (!Consumers.Any()) { Logger.LogDebug($"Disposed consumer pool with no consumers in the pool."); return; } var poolDisposeStopwatch = Stopwatch.StartNew(); Logger.LogInformation($"Disposing consumer pool ({Consumers.Count} consumers)."); var remainingWaitDuration = TotalDisposeWaitDuration; foreach (var consumer in Consumers.Values) { var poolItemDisposeStopwatch = Stopwatch.StartNew(); try { consumer.Value.Unsubscribe(); consumer.Value.Close(); consumer.Value.Dispose(); } catch { } poolItemDisposeStopwatch.Stop(); remainingWaitDuration = remainingWaitDuration > poolItemDisposeStopwatch.Elapsed ? remainingWaitDuration.Subtract(poolItemDisposeStopwatch.Elapsed) : TimeSpan.Zero; } poolDisposeStopwatch.Stop(); Logger.LogInformation( $"Disposed Kafka Consumer Pool ({Consumers.Count} consumers in {poolDisposeStopwatch.Elapsed.TotalMilliseconds:0.00} ms)."); if (poolDisposeStopwatch.Elapsed.TotalSeconds > 5.0) { Logger.LogWarning( $"Disposing Kafka Consumer Pool got time greather than expected: {poolDisposeStopwatch.Elapsed.TotalMilliseconds:0.00} ms."); } Consumers.Clear(); }
/// <summary> /// Writes the class diagram. /// </summary> /// <param name="class">The class.</param> /// <param name="useIncludes">if set to <c>true</c> [use includes].</param> /// <returns></returns> internal static string WriteClassDiagram(Models.Class @class, bool useIncludes = false) { string markup = Templates.Descriptor; if (@class.Module) { markup = markup.Replace(ProtoTypeElement, "").Replace(StereoTypeElement, string.Format(StereoType, "M", "application", "module ")); } else if (@class.Static && @class.Abstract) { markup = markup.Replace(ProtoTypeElement, "").Replace(StereoTypeElement, string.Format(StereoType, "S", "orchid", "static ")); } else if (@class.Abstract) { markup = markup.Replace(ProtoTypeElement, "abstract ").Replace(StereoTypeElement, ""); } else { markup = markup.Replace(ProtoTypeElement, "").Replace(StereoTypeElement, ""); } markup = markup.Replace(TypeElement, "class ").Replace(NameElement, @class.Name); markup = markup.Replace(BodyElement, WriteBody(@class)); if (@class.Implements != null) { markup += Lollipop(@class.Name, @class.Implements.Name); } if (@class.Inherits != null) { markup += Extend(@class.Name, @class.Inherits.Name); } var aggregates = Aggregations.Distinct().ToList(); Aggregations.Clear(); var composites = Compositions.Distinct().ToList(); Compositions.Clear(); var consumption = Consumers.Distinct().ToList(); Consumers.Clear(); var provision = Providers.Distinct().ToList(); Providers.Clear(); aggregates.ForEach((n) => { if (useIncludes) { markup = ((IncludeDiagram(n).Length > 0) ? IncludeDiagram(n) : "") + markup; } markup += Aggregate(@class.Name, n); Relationships.Add(new Models.Relationship { PrincipalObject = @class, AncillaryObject = new Models.Generic { Name = n }, Type = Models.RelationshipType.Aggregation }); }); composites.ForEach((n) => { if (useIncludes) { markup = ((IncludeDiagram(n).Length > 0) ? IncludeDiagram(n) : "") + markup; } markup += Composite(@class.Name, n); Relationships.Add(new Models.Relationship { PrincipalObject = @class, AncillaryObject = new Models.Generic { Name = n }, Type = Models.RelationshipType.Composition }); }); consumption.ForEach((n) => { if (useIncludes) { markup = ((IncludeDiagram(n).Length > 0) ? IncludeDiagram(n) : "") + markup; } markup += Consumes(@class.Name, n); Relationships.Add(new Models.Relationship { PrincipalObject = @class, AncillaryObject = new Models.Generic { Name = n }, Type = Models.RelationshipType.Dependency }); }); Providers.ForEach((n) => { if (useIncludes) { markup = ((IncludeDiagram(n).Length > 0) ? IncludeDiagram(n) : "") + markup; } markup += Provides(@class.Name, n); Relationships.Add(new Models.Relationship { PrincipalObject = @class, AncillaryObject = new Models.Generic { Name = n }, Type = Models.RelationshipType.Association }); }); return(markup); }