IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
DiagnosticChannelProvider.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Concurrent;
3using System.Collections.Generic;
4using System.Linq;
5
7{
8
12 class DiagnosticChannelProvider : IDisposable
13 {
14
15 readonly IEnumerable<IDiagnosticChannelFactory> _factories;
16 readonly ConcurrentDictionary<string, IDiagnosticChannel?> _cache = new();
17
23 public DiagnosticChannelProvider(IEnumerable<IDiagnosticChannelFactory> factories)
24 {
25 _factories = factories ?? throw new ArgumentNullException(nameof(factories));
26 }
27
34 {
35 return _cache.GetOrAdd(spec, _ => _factories.Select(i => i.CreateChannel(_)).FirstOrDefault(i => i != null));
36 }
37
39 public void Dispose()
40 {
41 foreach (var i in _cache.Values)
42 if (i is IDisposable d)
43 d.Dispose();
44
45 _cache.Clear();
46 }
47
48 }
49
50}
Provides the capability to look up diagnostic channels.
DiagnosticChannelProvider(IEnumerable< IDiagnosticChannelFactory > factories)
Initializes a new instance.
IDiagnosticChannel? GetOrCreateChannel(string spec)
Attempts to parse the specification into a diagnostic channel.
Handles consuming and outputting diagnostic events.