Skip to content

Commit 6a0488e

Browse files
Merge branch 'bollhals-minor.improvements'
2 parents 29f78bf + c8f368a commit 6a0488e

12 files changed

+82
-83
lines changed

projects/RabbitMQ.Client/client/api/ConnectionFactory.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ public Uri Uri
329329
public IAuthMechanismFactory AuthMechanismFactory(IList<string> mechanismNames)
330330
{
331331
// Our list is in order of preference, the server one is not.
332-
foreach (IAuthMechanismFactory factory in AuthMechanisms)
332+
for (int index = 0; index < AuthMechanisms.Count; index++)
333333
{
334+
IAuthMechanismFactory factory = AuthMechanisms[index];
334335
string factoryName = factory.Name;
335336
if (mechanismNames.Any<string>(x => string.Equals(x, factoryName, StringComparison.OrdinalIgnoreCase)))
336337
{
337338
return factory;
338339
}
339340
}
341+
340342
return null;
341343
}
342344

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs

+25-23
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ internal sealed class AutorecoveringConnection : IAutorecoveringConnection
6767

6868
private readonly object _recordedEntitiesLock = new object();
6969

70-
private readonly IDictionary<string, RecordedExchange> _recordedExchanges = new Dictionary<string, RecordedExchange>();
70+
private readonly Dictionary<string, RecordedExchange> _recordedExchanges = new Dictionary<string, RecordedExchange>();
7171

72-
private readonly IDictionary<string, RecordedQueue> _recordedQueues = new Dictionary<string, RecordedQueue>();
72+
private readonly Dictionary<string, RecordedQueue> _recordedQueues = new Dictionary<string, RecordedQueue>();
7373

74-
private readonly IDictionary<RecordedBinding, byte> _recordedBindings = new Dictionary<RecordedBinding, byte>();
74+
private readonly Dictionary<RecordedBinding, byte> _recordedBindings = new Dictionary<RecordedBinding, byte>();
7575

76-
private readonly IDictionary<string, RecordedConsumer> _recordedConsumers = new Dictionary<string, RecordedConsumer>();
76+
private readonly Dictionary<string, RecordedConsumer> _recordedConsumers = new Dictionary<string, RecordedConsumer>();
7777

78-
private readonly ICollection<AutorecoveringModel> _models = new List<AutorecoveringModel>();
78+
private readonly List<AutorecoveringModel> _models = new List<AutorecoveringModel>();
7979

8080
private EventHandler<ConnectionBlockedEventArgs> _recordedBlockedEventHandlers;
8181
private EventHandler<ShutdownEventArgs> _recordedShutdownEventHandlers;
@@ -485,12 +485,11 @@ public void DeleteRecordedBinding(RecordedBinding rb)
485485

486486
public RecordedConsumer DeleteRecordedConsumer(string consumerTag)
487487
{
488-
RecordedConsumer rc = null;
488+
RecordedConsumer rc;
489489
lock (_recordedEntitiesLock)
490490
{
491-
if (_recordedConsumers.ContainsKey(consumerTag))
491+
if (_recordedConsumers.TryGetValue(consumerTag, out rc))
492492
{
493-
rc = _recordedConsumers[consumerTag];
494493
_recordedConsumers.Remove(consumerTag);
495494
}
496495
}
@@ -912,10 +911,12 @@ private void PropagateQueueNameChangeToBindings(string oldName, string newName)
912911
{
913912
lock (_recordedBindings)
914913
{
915-
IEnumerable<RecordedBinding> bs = _recordedBindings.Keys.Where(b => b.Destination.Equals(oldName));
916-
foreach (RecordedBinding b in bs)
914+
foreach (RecordedBinding b in _recordedBindings.Keys)
917915
{
918-
b.Destination = newName;
916+
if (b.Destination.Equals(oldName))
917+
{
918+
b.Destination = newName;
919+
}
919920
}
920921
}
921922
}
@@ -924,21 +925,22 @@ private void PropagateQueueNameChangeToConsumers(string oldName, string newName)
924925
{
925926
lock (_recordedConsumers)
926927
{
927-
IEnumerable<KeyValuePair<string, RecordedConsumer>> cs = _recordedConsumers.
928-
Where(pair => pair.Value.Queue.Equals(oldName));
929-
foreach (KeyValuePair<string, RecordedConsumer> c in cs)
928+
foreach (KeyValuePair<string, RecordedConsumer> c in _recordedConsumers)
930929
{
931-
c.Value.Queue = newName;
930+
if (c.Value.Queue.Equals(oldName))
931+
{
932+
c.Value.Queue = newName;
933+
}
932934
}
933935
}
934936
}
935937

936938
private void RecoverBindings()
937939
{
938-
IDictionary<RecordedBinding, byte> recordedBindingsCopy = null;
940+
Dictionary<RecordedBinding, byte> recordedBindingsCopy;
939941
lock (_recordedBindings)
940942
{
941-
recordedBindingsCopy = _recordedBindings.ToDictionary(e => e.Key, e => e.Value);
943+
recordedBindingsCopy = new Dictionary<RecordedBinding, byte>(_recordedBindings);
942944
}
943945

944946
foreach (RecordedBinding b in recordedBindingsCopy.Keys)
@@ -1031,10 +1033,10 @@ private void RecoverConsumers()
10311033
throw new ObjectDisposedException(GetType().FullName);
10321034
}
10331035

1034-
IDictionary<string, RecordedConsumer> recordedConsumersCopy = null;
1036+
Dictionary<string, RecordedConsumer> recordedConsumersCopy;
10351037
lock (_recordedConsumers)
10361038
{
1037-
recordedConsumersCopy = _recordedConsumers.ToDictionary(e => e.Key, e => e.Value);
1039+
recordedConsumersCopy = new Dictionary<string, RecordedConsumer>(_recordedConsumers);
10381040
}
10391041

10401042
foreach (KeyValuePair<string, RecordedConsumer> pair in recordedConsumersCopy)
@@ -1091,10 +1093,10 @@ private void RecoverEntities()
10911093

10921094
private void RecoverExchanges()
10931095
{
1094-
IDictionary<string, RecordedExchange> recordedExchangesCopy = null;
1096+
Dictionary<string, RecordedExchange> recordedExchangesCopy;
10951097
lock (_recordedEntitiesLock)
10961098
{
1097-
recordedExchangesCopy = _recordedExchanges.ToDictionary(e => e.Key, e => e.Value);
1099+
recordedExchangesCopy = new Dictionary<string, RecordedExchange>(_recordedExchanges);
10981100
}
10991101

11001102
foreach (RecordedExchange rx in recordedExchangesCopy.Values)
@@ -1125,10 +1127,10 @@ private void RecoverModels()
11251127

11261128
private void RecoverQueues()
11271129
{
1128-
IDictionary<string, RecordedQueue> recordedQueuesCopy = null;
1130+
Dictionary<string, RecordedQueue> recordedQueuesCopy;
11291131
lock (_recordedEntitiesLock)
11301132
{
1131-
recordedQueuesCopy = _recordedQueues.ToDictionary(entry => entry.Key, entry => entry.Value);
1133+
recordedQueuesCopy = new Dictionary<string, RecordedQueue>(_recordedQueues);
11321134
}
11331135

11341136
foreach (KeyValuePair<string, RecordedQueue> pair in recordedQueuesCopy)

projects/RabbitMQ.Client/client/impl/BasicProperties.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,7 @@ public override object Clone()
284284
var clone = MemberwiseClone() as BasicProperties;
285285
if (IsHeadersPresent())
286286
{
287-
clone.Headers = new Dictionary<string, object>();
288-
foreach (KeyValuePair<string, object> entry in Headers)
289-
{
290-
clone.Headers[entry.Key] = entry.Value;
291-
}
287+
clone.Headers = new Dictionary<string, object>(Headers);
292288
}
293289

294290
return clone;

projects/RabbitMQ.Client/client/impl/Connection.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,9 @@ public void PrettyPrintShutdownReport()
730730
{
731731
Console.Error.WriteLine(
732732
"Log of errors while closing connection {0}:", this);
733-
foreach (ShutdownReportEntry entry in ShutdownReport)
733+
for (int index = 0; index < ShutdownReport.Count; index++)
734734
{
735-
Console.Error.WriteLine(
736-
entry.ToString());
735+
Console.Error.WriteLine(ShutdownReport[index].ToString());
737736
}
738737
}
739738
}

projects/RabbitMQ.Client/client/impl/ContentHeaderPropertyReader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
namespace RabbitMQ.Client.Impl
4747
{
48-
struct ContentHeaderPropertyReader
48+
internal struct ContentHeaderPropertyReader
4949
{
5050
private ushort m_bitCount;
5151
private ushort m_flagWord;
@@ -143,9 +143,9 @@ public string ReadShortstr()
143143
}
144144

145145
/// <returns>A type of <seealso cref="System.Collections.Generic.IDictionary{TKey,TValue}"/>.</returns>
146-
public IDictionary<string, object> ReadTable()
146+
public Dictionary<string, object> ReadTable()
147147
{
148-
IDictionary<string, object> result = WireFormatting.ReadTable(_memory.Slice(_memoryOffset), out int bytesRead);
148+
Dictionary<string, object> result = WireFormatting.ReadTable(_memory.Slice(_memoryOffset), out int bytesRead);
149149
_memoryOffset += bytesRead;
150150
return result;
151151
}

projects/RabbitMQ.Client/client/impl/MethodArgumentReader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
namespace RabbitMQ.Client.Impl
4747
{
48-
struct MethodArgumentReader
48+
internal struct MethodArgumentReader
4949
{
5050
private int? _bit;
5151
private int _bits;
@@ -125,10 +125,10 @@ public string ReadShortstr()
125125
return result;
126126
}
127127

128-
public IDictionary<string, object> ReadTable()
128+
public Dictionary<string, object> ReadTable()
129129
{
130130
ClearBits();
131-
IDictionary<string, object> result = WireFormatting.ReadTable(_memory.Slice(_memoryOffset), out int bytesRead);
131+
Dictionary<string, object> result = WireFormatting.ReadTable(_memory.Slice(_memoryOffset), out int bytesRead);
132132
_memoryOffset += bytesRead;
133133
return result;
134134
}

projects/RabbitMQ.Client/client/impl/ModelBase.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ namespace RabbitMQ.Client.Impl
5555
{
5656
abstract class ModelBase : IFullModel, IRecoverable
5757
{
58-
public readonly IDictionary<string, IBasicConsumer> m_consumers = new Dictionary<string, IBasicConsumer>();
59-
6058
///<summary>Only used to kick-start a connection open
6159
///sequence. See <see cref="Connection.Open"/> </summary>
6260
public BlockingCell<ConnectionStartDetails> m_connectionStartCell = null;
6361

62+
private readonly Dictionary<string, IBasicConsumer> _consumers = new Dictionary<string, IBasicConsumer>();
63+
6464
private TimeSpan _handshakeContinuationTimeout = TimeSpan.FromSeconds(10);
6565
private TimeSpan _continuationTimeout = TimeSpan.FromSeconds(20);
6666

@@ -500,11 +500,11 @@ public void OnSessionShutdown(object sender, ShutdownEventArgs reason)
500500
ConsumerDispatcher.Quiesce();
501501
SetCloseReason(reason);
502502
OnModelShutdown(reason);
503-
BroadcastShutdownToConsumers(m_consumers, reason);
503+
BroadcastShutdownToConsumers(_consumers, reason);
504504
ConsumerDispatcher.Shutdown(this).GetAwaiter().GetResult();;
505505
}
506506

507-
protected void BroadcastShutdownToConsumers(IDictionary<string, IBasicConsumer> cs, ShutdownEventArgs reason)
507+
protected void BroadcastShutdownToConsumers(Dictionary<string, IBasicConsumer> cs, ShutdownEventArgs reason)
508508
{
509509
foreach (KeyValuePair<string, IBasicConsumer> c in cs)
510510
{
@@ -578,10 +578,10 @@ public void HandleBasicAck(ulong deliveryTag,
578578
public void HandleBasicCancel(string consumerTag, bool nowait)
579579
{
580580
IBasicConsumer consumer;
581-
lock (m_consumers)
581+
lock (_consumers)
582582
{
583-
consumer = m_consumers[consumerTag];
584-
m_consumers.Remove(consumerTag);
583+
consumer = _consumers[consumerTag];
584+
_consumers.Remove(consumerTag);
585585
}
586586
if (consumer == null)
587587
{
@@ -601,10 +601,10 @@ public void HandleBasicCancelOk(string consumerTag)
601601
consumerTag
602602
));
603603
*/
604-
lock (m_consumers)
604+
lock (_consumers)
605605
{
606-
k.m_consumer = m_consumers[consumerTag];
607-
m_consumers.Remove(consumerTag);
606+
k.m_consumer = _consumers[consumerTag];
607+
_consumers.Remove(consumerTag);
608608
}
609609
ConsumerDispatcher.HandleBasicCancelOk(k.m_consumer, consumerTag);
610610
k.HandleCommand(null); // release the continuation.
@@ -615,9 +615,9 @@ public void HandleBasicConsumeOk(string consumerTag)
615615
var k =
616616
(BasicConsumerRpcContinuation)_continuationQueue.Next();
617617
k.m_consumerTag = consumerTag;
618-
lock (m_consumers)
618+
lock (_consumers)
619619
{
620-
m_consumers[consumerTag] = k.m_consumer;
620+
_consumers[consumerTag] = k.m_consumer;
621621
}
622622
ConsumerDispatcher.HandleBasicConsumeOk(k.m_consumer, consumerTag);
623623
k.HandleCommand(null); // release the continuation.
@@ -632,9 +632,9 @@ public virtual void HandleBasicDeliver(string consumerTag,
632632
ReadOnlyMemory<byte> body)
633633
{
634634
IBasicConsumer consumer;
635-
lock (m_consumers)
635+
lock (_consumers)
636636
{
637-
consumer = m_consumers[consumerTag];
637+
consumer = _consumers[consumerTag];
638638
}
639639
if (consumer == null)
640640
{
@@ -1005,9 +1005,9 @@ public void BasicCancel(string consumerTag)
10051005
k.GetReply(ContinuationTimeout);
10061006
}
10071007

1008-
lock (m_consumers)
1008+
lock (_consumers)
10091009
{
1010-
m_consumers.Remove(consumerTag);
1010+
_consumers.Remove(consumerTag);
10111011
}
10121012

10131013
ModelShutdown -= k.m_consumer.HandleModelShutdown;
@@ -1017,9 +1017,9 @@ public void BasicCancelNoWait(string consumerTag)
10171017
{
10181018
_Private_BasicCancel(consumerTag, true);
10191019

1020-
lock (m_consumers)
1020+
lock (_consumers)
10211021
{
1022-
m_consumers.Remove(consumerTag);
1022+
_consumers.Remove(consumerTag);
10231023
}
10241024
}
10251025

projects/RabbitMQ.Client/client/impl/ProtocolBase.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ namespace RabbitMQ.Client.Framing.Impl
4747
{
4848
abstract class ProtocolBase : IProtocol
4949
{
50-
public IDictionary<string, bool> Capabilities = new Dictionary<string, bool>();
50+
public IDictionary<string, bool> Capabilities;
5151

5252
public ProtocolBase()
5353
{
54-
Capabilities["publisher_confirms"] = true;
55-
Capabilities["exchange_exchange_bindings"] = true;
56-
Capabilities["basic.nack"] = true;
57-
Capabilities["consumer_cancel_notify"] = true;
58-
Capabilities["connection.blocked"] = true;
59-
Capabilities["authentication_failure_close"] = true;
54+
Capabilities = new Dictionary<string, bool>
55+
{
56+
["publisher_confirms"] = true,
57+
["exchange_exchange_bindings"] = true,
58+
["basic.nack"] = true,
59+
["consumer_cancel_notify"] = true,
60+
["connection.blocked"] = true,
61+
["authentication_failure_close"] = true
62+
};
6063
}
6164

6265
public abstract string ApiName { get; }

projects/RabbitMQ.Client/client/impl/Session.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ public Session(Connection connection, int channelNumber)
5555

5656
public override void HandleFrame(in InboundFrame frame)
5757
{
58-
using (Command cmd = _assembler.HandleFrame(in frame))
58+
Command cmd = _assembler.HandleFrame(in frame);
59+
if (cmd != null)
5960
{
60-
if (cmd != null)
61+
using (cmd)
6162
{
6263
OnCommandReceived(cmd);
6364
}

projects/RabbitMQ.Client/client/impl/SessionManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SessionManager
5050
public readonly ushort ChannelMax;
5151
private readonly IntAllocator _ints;
5252
private readonly Connection _connection;
53-
private readonly IDictionary<int, ISession> _sessionMap = new Dictionary<int, ISession>();
53+
private readonly Dictionary<int, ISession> _sessionMap = new Dictionary<int, ISession>();
5454

5555
public SessionManager(Connection connection, ushort channelMax)
5656
{

projects/RabbitMQ.Client/client/impl/StreamProperties.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ public override object Clone()
5555
var clone = MemberwiseClone() as StreamProperties;
5656
if (IsHeadersPresent())
5757
{
58-
clone.Headers = new Dictionary<string, object>();
59-
foreach (KeyValuePair<string, object> entry in Headers)
60-
{
61-
clone.Headers[entry.Key] = entry.Value;
62-
}
58+
clone.Headers = new Dictionary<string, object>(Headers);
6359
}
6460

6561
return clone;

0 commit comments

Comments
 (0)