Skip to content

Commit 2e56379

Browse files
committed
cleanup
1 parent 20b0a2c commit 2e56379

File tree

8 files changed

+24
-35
lines changed

8 files changed

+24
-35
lines changed

src/SignalR/perf/Microbenchmarks/RedisProtocolBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
1313
{
1414
public class RedisProtocolBenchmark
1515
{
16-
private RedisProtocol<Hub> _protocol;
16+
private RedisProtocol _protocol;
1717
private RedisGroupCommand _groupCommand;
1818
private object[] _args;
1919
private string _methodName;
@@ -28,7 +28,7 @@ public class RedisProtocolBenchmark
2828
[GlobalSetup]
2929
public void GlobalSetup()
3030
{
31-
_protocol = new RedisProtocol<Hub>(new [] {
31+
_protocol = new RedisProtocol(new [] {
3232
new DummyProtocol("protocol1"),
3333
new DummyProtocol("protocol2")
3434
});

src/SignalR/server/Core/src/HubConnectionContext.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,10 @@ internal async Task<bool> HandshakeAsync(TimeSpan timeout, IReadOnlyList<string>
437437
Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols);
438438
if (Protocol == null)
439439
{
440-
if (Protocol == null)
441-
{
442-
Log.HandshakeFailed(_logger, null);
440+
Log.HandshakeFailed(_logger, null);
443441

444-
await WriteHandshakeResponseAsync(new HandshakeResponseMessage($"The protocol '{handshakeRequestMessage.Protocol}' is not supported."));
445-
return false;
446-
}
442+
await WriteHandshakeResponseAsync(new HandshakeResponseMessage($"The protocol '{handshakeRequestMessage.Protocol}' is not supported."));
443+
return false;
447444
}
448445

449446
if (!Protocol.IsVersionSupported(handshakeRequestMessage.Version))

src/SignalR/server/Core/src/HubOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.AspNetCore.SignalR.Protocol;
76

87
namespace Microsoft.AspNetCore.SignalR
98
{

src/SignalR/server/StackExchangeRedis/src/Internal/DefaultHubMessageSerializer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Microsoft.AspNetCore.SignalR.Protocol;
8-
using Microsoft.Extensions.Options;
98

109
namespace Microsoft.AspNetCore.SignalR.Internal
1110
{
12-
internal class DefaultHubMessageSerializer<THub> where THub : Hub
11+
internal class DefaultHubMessageSerializer
1312
{
1413
private readonly List<IHubProtocol> _hubProtocols = new List<IHubProtocol>();
1514

16-
public DefaultHubMessageSerializer(IHubProtocolResolver hubProtocolResolver, IOptions<HubOptions> globalHubOptions, IOptions<HubOptions<THub>> hubOptions)
15+
public DefaultHubMessageSerializer(IHubProtocolResolver hubProtocolResolver, IList<string> globalSupportedProtocols, IList<string> hubSupportedProtocols)
1716
{
18-
var supportedProtocols = hubOptions.Value.SupportedProtocols ?? globalHubOptions.Value.SupportedProtocols ?? Array.Empty<string>();
17+
var supportedProtocols = hubSupportedProtocols ?? globalSupportedProtocols ?? Array.Empty<string>();
1918
foreach (var protocolName in supportedProtocols)
2019
{
2120
var protocol = hubProtocolResolver.GetProtocol(protocolName, (supportedProtocols as IReadOnlyList<string>) ?? supportedProtocols.ToList());

src/SignalR/server/StackExchangeRedis/src/Internal/RedisProtocol.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Internal
1515
{
16-
internal class RedisProtocol<THub> where THub : Hub
16+
internal class RedisProtocol
1717
{
1818
private readonly IReadOnlyList<IHubProtocol> _protocols;
19-
private readonly DefaultHubMessageSerializer<THub> _messageSerializer;
19+
private readonly DefaultHubMessageSerializer _messageSerializer;
2020

2121
public RedisProtocol(IReadOnlyList<IHubProtocol> protocols)
2222
{
2323
_protocols = protocols;
2424
}
2525

26-
public RedisProtocol(DefaultHubMessageSerializer<THub> messageSerializer)
26+
public RedisProtocol(DefaultHubMessageSerializer messageSerializer)
2727
{
2828
_messageSerializer = messageSerializer;
2929
}

src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class RedisHubLifetimeManager<THub> : HubLifetimeManager<THub>, IDisposab
2828
private readonly RedisOptions _options;
2929
private readonly RedisChannels _channels;
3030
private readonly string _serverName = GenerateServerName();
31-
private readonly RedisProtocol<THub> _protocol;
31+
private readonly RedisProtocol _protocol;
3232
private readonly SemaphoreSlim _connectionLock = new SemaphoreSlim(1);
3333

3434
private readonly AckHandler _ackHandler;
@@ -53,11 +53,11 @@ public RedisHubLifetimeManager(ILogger<RedisHubLifetimeManager<THub>> logger,
5353
_channels = new RedisChannels(typeof(THub).FullName);
5454
if (globalHubOptions != null && hubOptions != null)
5555
{
56-
_protocol = new RedisProtocol<THub>(new DefaultHubMessageSerializer<THub>(hubProtocolResolver, globalHubOptions, hubOptions));
56+
_protocol = new RedisProtocol(new DefaultHubMessageSerializer(hubProtocolResolver, globalHubOptions.Value.SupportedProtocols, hubOptions.Value.SupportedProtocols));
5757
}
5858
else
5959
{
60-
_protocol = new RedisProtocol<THub>(hubProtocolResolver.AllProtocols);
60+
_protocol = new RedisProtocol(hubProtocolResolver.AllProtocols);
6161
}
6262

6363
RedisLog.ConnectingToEndpoints(_logger, options.Value.Configuration.EndPoints, _serverName);

src/SignalR/server/StackExchangeRedis/test/DefaultHubMessageSerializerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SerializeMessages(string testName)
2424

2525
var resolver = CreateHubProtocolResolver(new List<IHubProtocol> { new MessagePackHubProtocol(), new JsonHubProtocol() });
2626
var protocolNames = testData.SupportedHubProtocols.ConvertAll(p => p.Name);
27-
var serializer = new DefaultHubMessageSerializer<Hub>(resolver, Options.Create(new HubOptions() { SupportedProtocols = protocolNames }), Options.Create(new HubOptions<Hub>()));
27+
var serializer = new DefaultHubMessageSerializer(resolver, protocolNames, hubSupportedProtocols: null);
2828
var serializedHubMessage = serializer.SerializeMessage(_testMessage);
2929

3030
var serializedMessages = serializedHubMessage.GetAllSerializations();

src/SignalR/server/StackExchangeRedis/test/RedisProtocolTests.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class RedisProtocolTests
3232
public void ParseAck(string testName)
3333
{
3434
var testData = _ackTestData[testName];
35-
var protocol = new RedisProtocol<EchoHub>(Array.Empty<IHubProtocol>());
35+
var protocol = new RedisProtocol(Array.Empty<IHubProtocol>());
3636

3737
var decoded = protocol.ReadAck(testData.Encoded);
3838

@@ -44,7 +44,7 @@ public void ParseAck(string testName)
4444
public void WriteAck(string testName)
4545
{
4646
var testData = _ackTestData[testName];
47-
var protocol = new RedisProtocol<EchoHub>(Array.Empty<IHubProtocol>());
47+
var protocol = new RedisProtocol(Array.Empty<IHubProtocol>());
4848

4949
var encoded = protocol.WriteAck(testData.Decoded);
5050

@@ -64,7 +64,7 @@ public void WriteAck(string testName)
6464
public void ParseGroupCommand(string testName)
6565
{
6666
var testData = _groupCommandTestData[testName];
67-
var protocol = new RedisProtocol<EchoHub>(Array.Empty<IHubProtocol>());
67+
var protocol = new RedisProtocol(Array.Empty<IHubProtocol>());
6868

6969
var decoded = protocol.ReadGroupCommand(testData.Encoded);
7070

@@ -80,7 +80,7 @@ public void ParseGroupCommand(string testName)
8080
public void WriteGroupCommand(string testName)
8181
{
8282
var testData = _groupCommandTestData[testName];
83-
var protocol = new RedisProtocol<EchoHub>(Array.Empty<IHubProtocol>());
83+
var protocol = new RedisProtocol(Array.Empty<IHubProtocol>());
8484

8585
var encoded = protocol.WriteGroupCommand(testData.Decoded);
8686

@@ -140,7 +140,7 @@ public void ParseInvocation(string testName)
140140
{
141141
var testData = _invocationTestData[testName];
142142
var hubProtocols = new[] { new DummyHubProtocol("p1"), new DummyHubProtocol("p2") };
143-
var protocol = new RedisProtocol<EchoHub>(hubProtocols);
143+
var protocol = new RedisProtocol(hubProtocols);
144144

145145
var expected = testData.Decoded();
146146

@@ -171,7 +171,7 @@ public void ParseInvocation(string testName)
171171
public void WriteInvocation(string testName)
172172
{
173173
var testData = _invocationTestData[testName];
174-
var protocol = new RedisProtocol<EchoHub>(new [] { new DummyHubProtocol("p1"), new DummyHubProtocol("p2") });
174+
var protocol = new RedisProtocol(new [] { new DummyHubProtocol("p1"), new DummyHubProtocol("p2") });
175175

176176
// Actual invocation doesn't matter because we're using a dummy hub protocol.
177177
// But the dummy protocol will check that we gave it the test message to make sure everything flows through properly.
@@ -187,7 +187,7 @@ public void WriteInvocationWithHubMessageSerializer(string testName)
187187
{
188188
var testData = _invocationTestData[testName];
189189
var hubMessageSerializer = CreateHubMessageSerializer(new List<IHubProtocol>() { new DummyHubProtocol("p1"), new DummyHubProtocol("p2") });
190-
var protocol = new RedisProtocol<Hub>(hubMessageSerializer);
190+
var protocol = new RedisProtocol(hubMessageSerializer);
191191

192192
// Actual invocation doesn't matter because we're using a dummy hub protocol.
193193
// But the dummy protocol will check that we gave it the test message to make sure everything flows through properly.
@@ -215,17 +215,11 @@ public ProtocolTestData(string name, T decoded, byte[] encoded)
215215
}
216216
}
217217

218-
private DefaultHubMessageSerializer<Hub> CreateHubMessageSerializer(List<IHubProtocol> protocols)
218+
private DefaultHubMessageSerializer CreateHubMessageSerializer(List<IHubProtocol> protocols)
219219
{
220-
var hubTypeOptions = Options.Create(new HubOptions<Hub>());
221-
var globalHubOptions = Options.Create(new HubOptions()
222-
{
223-
SupportedProtocols = protocols.ConvertAll(p => p.Name)
224-
});
225-
226220
var protocolResolver = new DefaultHubProtocolResolver(protocols, NullLogger<DefaultHubProtocolResolver>.Instance);
227221

228-
return new DefaultHubMessageSerializer<Hub>(protocolResolver, globalHubOptions, hubTypeOptions);
222+
return new DefaultHubMessageSerializer(protocolResolver, protocols.ConvertAll(p => p.Name), hubSupportedProtocols: null);
229223
}
230224
}
231225
}

0 commit comments

Comments
 (0)