Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 5b70a3b

Browse files
committed
Minor changes related to Tracing configuration
1 parent ec489a4 commit 5b70a3b

File tree

9 files changed

+88
-67
lines changed

9 files changed

+88
-67
lines changed

src/Client.Android/ClientFactory.cs

+18-13
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@ public class ClientFactory : IFactory<Client>
1111
readonly string hostAddress;
1212
readonly IProtocolBinding binding;
1313

14-
public ClientFactory (string hostAddress, IProtocolBinding binding)
15-
{
16-
tracerManager = new DefaultTracerManager ();
17-
tracer = tracerManager.Get<ClientFactory> ();
18-
this.hostAddress = hostAddress;
19-
this.binding = binding;
20-
}
14+
public ClientFactory (string hostAddress, IProtocolBinding binding)
15+
: this (hostAddress, binding, new DefaultTracerManager ())
16+
{
17+
}
18+
19+
public ClientFactory (string hostAddress, IProtocolBinding binding, ITracerManager tracerManager)
20+
{
21+
tracer = tracerManager.Get<ClientFactory> ();
22+
this.tracerManager = tracerManager;
23+
this.hostAddress = hostAddress;
24+
this.binding = binding;
25+
}
2126

22-
/// <exception cref="ClientException">ClientException</exception>
23-
public Client Create (ProtocolConfiguration configuration)
27+
/// <exception cref="ClientException">ClientException</exception>
28+
public Client Create (ProtocolConfiguration configuration)
2429
{
2530
try {
26-
var topicEvaluator = new TopicEvaluator(configuration);
31+
var topicEvaluator = new TopicEvaluator (configuration);
2732
var innerChannelFactory = binding.GetChannelFactory (hostAddress, tracerManager, configuration);
28-
var channelFactory = new PacketChannelFactory(innerChannelFactory, topicEvaluator, tracerManager, configuration);
33+
var channelFactory = new PacketChannelFactory (innerChannelFactory, topicEvaluator, tracerManager, configuration);
2934
var packetIdProvider = new PacketIdProvider ();
30-
var repositoryProvider = new InMemoryRepositoryProvider();
31-
var flowProvider = new ClientProtocolFlowProvider(topicEvaluator, repositoryProvider, tracerManager, configuration);
35+
var repositoryProvider = new InMemoryRepositoryProvider ();
36+
var flowProvider = new ClientProtocolFlowProvider (topicEvaluator, repositoryProvider, tracerManager, configuration);
3237
var packetChannel = channelFactory.Create ();
3338

3439
return new Client (packetChannel, flowProvider, repositoryProvider, packetIdProvider, tracerManager, configuration);

src/Client.Android/TcpChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected virtual void Dispose (bool disposing)
108108
}
109109
}
110110

111-
private IDisposable SubscribeStream ()
111+
IDisposable SubscribeStream ()
112112
{
113113
return Observable.Defer (() => {
114114
var buffer = new byte[client.ReceiveBufferSize];

src/Client.Library/ClientFactory.cs

+18-13
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@ public class ClientFactory : IFactory<Client>
1111
readonly string hostAddress;
1212
readonly IProtocolBinding binding;
1313

14-
public ClientFactory (string hostAddress, IProtocolBinding binding)
15-
{
16-
tracerManager = new DiagnosticsTracerManager ();
17-
tracer = tracerManager.Get<ClientFactory> ();
18-
this.hostAddress = hostAddress;
19-
this.binding = binding;
20-
}
14+
public ClientFactory (string hostAddress, IProtocolBinding binding)
15+
: this (hostAddress, binding, new DefaultTracerManager ())
16+
{
17+
}
18+
19+
public ClientFactory (string hostAddress, IProtocolBinding binding, ITracerManager tracerManager)
20+
{
21+
tracer = tracerManager.Get<ClientFactory> ();
22+
this.tracerManager = tracerManager;
23+
this.hostAddress = hostAddress;
24+
this.binding = binding;
25+
}
2126

22-
/// <exception cref="ClientException">ClientException</exception>
23-
public Client Create (ProtocolConfiguration configuration)
27+
/// <exception cref="ClientException">ClientException</exception>
28+
public Client Create (ProtocolConfiguration configuration)
2429
{
2530
try {
26-
var topicEvaluator = new TopicEvaluator(configuration);
31+
var topicEvaluator = new TopicEvaluator (configuration);
2732
var innerChannelFactory = binding.GetChannelFactory (hostAddress, tracerManager, configuration);
28-
var channelFactory = new PacketChannelFactory(innerChannelFactory, topicEvaluator, tracerManager, configuration);
33+
var channelFactory = new PacketChannelFactory (innerChannelFactory, topicEvaluator, tracerManager, configuration);
2934
var packetIdProvider = new PacketIdProvider ();
30-
var repositoryProvider = new InMemoryRepositoryProvider();
31-
var flowProvider = new ClientProtocolFlowProvider(topicEvaluator, repositoryProvider, tracerManager, configuration);
35+
var repositoryProvider = new InMemoryRepositoryProvider ();
36+
var flowProvider = new ClientProtocolFlowProvider (topicEvaluator, repositoryProvider, tracerManager, configuration);
3237
var packetChannel = channelFactory.Create ();
3338

3439
return new Client (packetChannel, flowProvider, repositoryProvider, packetIdProvider, tracerManager, configuration);

src/Client.iOS/ClientFactory.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ public class ClientFactory : IFactory<Client>
1212
readonly IProtocolBinding binding;
1313

1414
public ClientFactory (string hostAddress, IProtocolBinding binding)
15+
: this (hostAddress, binding, new DefaultTracerManager ())
16+
{
17+
}
18+
19+
public ClientFactory (string hostAddress, IProtocolBinding binding, ITracerManager tracerManager)
1520
{
16-
tracerManager = new DefaultTracerManager ();
1721
tracer = tracerManager.Get<ClientFactory> ();
22+
this.tracerManager = tracerManager;
1823
this.hostAddress = hostAddress;
1924
this.binding = binding;
2025
}

src/Client.iOS/TcpChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected virtual void Dispose (bool disposing)
108108
}
109109
}
110110

111-
private IDisposable SubscribeStream ()
111+
IDisposable SubscribeStream ()
112112
{
113113
return Observable.Defer (() => {
114114
var buffer = new byte[client.ReceiveBufferSize];

src/Core.Library/TcpChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected virtual void Dispose (bool disposing)
108108
}
109109
}
110110

111-
private IDisposable SubscribeStream ()
111+
IDisposable SubscribeStream ()
112112
{
113113
return Observable.Defer (() => {
114114
var buffer = new byte[client.ReceiveBufferSize];

src/Core/TaskRunner.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace System.Net.Mqtt
55
{
66
internal class TaskRunner : IDisposable
77
{
8-
private TaskFactory taskFactory;
9-
private bool disposed;
8+
TaskFactory taskFactory;
9+
bool disposed;
1010

1111
private TaskRunner ()
1212
{

src/Server.Library/ServerFactory.cs

+40-34
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,48 @@
55

66
namespace System.Net.Mqtt.Server
77
{
8-
public class ServerFactory : IFactory<Server>
9-
{
10-
readonly ITracerManager tracerManager;
11-
readonly ITracer tracer;
12-
readonly IProtocolBinding binding;
13-
readonly IAuthenticationProvider authenticationProvider;
8+
public class ServerFactory : IFactory<Server>
9+
{
10+
readonly ITracerManager tracerManager;
11+
readonly ITracer tracer;
12+
readonly IProtocolBinding binding;
13+
readonly IAuthenticationProvider authenticationProvider;
1414

15-
public ServerFactory (IProtocolBinding binding, IAuthenticationProvider authenticationProvider = null)
16-
{
17-
tracerManager = new DiagnosticsTracerManager ();
18-
tracer = tracerManager.Get<ServerFactory> ();
19-
this.binding = binding;
20-
this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance;
21-
}
15+
public ServerFactory (IProtocolBinding binding, IAuthenticationProvider authenticationProvider = null)
16+
: this (binding, new DefaultTracerManager (), authenticationProvider)
17+
{
18+
this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance;
19+
}
2220

23-
/// <exception cref="ServerException">ServerException</exception>
24-
public Server Create (ProtocolConfiguration configuration)
25-
{
26-
try {
27-
var topicEvaluator = new TopicEvaluator (configuration);
28-
var channelProvider = binding.GetChannelProvider (tracerManager, configuration);
29-
var channelFactory = new PacketChannelFactory (topicEvaluator, tracerManager, configuration);
30-
var repositoryProvider = new InMemoryRepositoryProvider ();
31-
var connectionProvider = new ConnectionProvider (tracerManager);
32-
var packetIdProvider = new PacketIdProvider ();
33-
var eventStream = new EventStream ();
34-
var flowProvider = new ServerProtocolFlowProvider (authenticationProvider, connectionProvider, topicEvaluator,
35-
repositoryProvider, packetIdProvider, eventStream, tracerManager, configuration);
21+
public ServerFactory (IProtocolBinding binding, ITracerManager tracerManager, IAuthenticationProvider authenticationProvider = null)
22+
{
23+
tracer = tracerManager.Get<ServerFactory> ();
24+
this.tracerManager = tracerManager;
25+
this.binding = binding;
26+
this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance;
27+
}
3628

37-
return new Server (channelProvider, channelFactory,
38-
flowProvider, connectionProvider, eventStream, tracerManager, configuration);
39-
} catch (Exception ex) {
40-
tracer.Error (ex, Properties.Resources.Server_InitializeError);
29+
/// <exception cref="ServerException">ServerException</exception>
30+
public Server Create (ProtocolConfiguration configuration)
31+
{
32+
try {
33+
var topicEvaluator = new TopicEvaluator (configuration);
34+
var channelProvider = binding.GetChannelProvider (tracerManager, configuration);
35+
var channelFactory = new PacketChannelFactory (topicEvaluator, tracerManager, configuration);
36+
var repositoryProvider = new InMemoryRepositoryProvider ();
37+
var connectionProvider = new ConnectionProvider (tracerManager);
38+
var packetIdProvider = new PacketIdProvider ();
39+
var eventStream = new EventStream ();
40+
var flowProvider = new ServerProtocolFlowProvider (authenticationProvider, connectionProvider, topicEvaluator,
41+
repositoryProvider, packetIdProvider, eventStream, tracerManager, configuration);
4142

42-
throw new ServerException (Properties.Resources.Server_InitializeError, ex);
43-
}
44-
}
45-
}
43+
return new Server (channelProvider, channelFactory,
44+
flowProvider, connectionProvider, eventStream, tracerManager, configuration);
45+
} catch (Exception ex) {
46+
tracer.Error (ex, Properties.Resources.Server_InitializeError);
47+
48+
throw new ServerException (Properties.Resources.Server_InitializeError, ex);
49+
}
50+
}
51+
}
4652
}

src/Server/NullAuthenticationProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
internal class NullAuthenticationProvider : IAuthenticationProvider
44
{
5-
private static readonly Lazy<NullAuthenticationProvider> instance;
5+
static readonly Lazy<NullAuthenticationProvider> instance;
66

77
static NullAuthenticationProvider ()
88
{

0 commit comments

Comments
 (0)