Skip to content

Commit 2191c44

Browse files
Merge branch 'stable'
2 parents 302235c + f335e2d commit 2191c44

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
using RabbitMQ.Client.Impl;
4444
using System;
4545
using System.Collections.Generic;
46+
using System.Collections.Concurrent;
4647
using System.Linq;
47-
using System.Net;
4848
using System.Threading;
4949
using System.Threading.Tasks;
5050

@@ -71,19 +71,20 @@ public class AutorecoveringConnection : IConnection, IRecoverable
7171

7272
protected List<AutorecoveringModel> m_models = new List<AutorecoveringModel>();
7373

74-
protected HashSet<RecordedBinding> m_recordedBindings = new HashSet<RecordedBinding>();
74+
protected IDictionary<RecordedBinding, byte> m_recordedBindings =
75+
new ConcurrentDictionary<RecordedBinding, byte>();
7576

7677
protected List<EventHandler<ConnectionBlockedEventArgs>> m_recordedBlockedEventHandlers =
7778
new List<EventHandler<ConnectionBlockedEventArgs>>();
7879

7980
protected IDictionary<string, RecordedConsumer> m_recordedConsumers =
80-
new Dictionary<string, RecordedConsumer>();
81+
new ConcurrentDictionary<string, RecordedConsumer>();
8182

8283
protected IDictionary<string, RecordedExchange> m_recordedExchanges =
83-
new Dictionary<string, RecordedExchange>();
84+
new ConcurrentDictionary<string, RecordedExchange>();
8485

8586
protected IDictionary<string, RecordedQueue> m_recordedQueues =
86-
new Dictionary<string, RecordedQueue>();
87+
new ConcurrentDictionary<string, RecordedQueue>();
8788

8889
protected List<EventHandler<ShutdownEventArgs>> m_recordedShutdownEventHandlers =
8990
new List<EventHandler<ShutdownEventArgs>>();
@@ -396,7 +397,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
396397
{
397398
lock (m_recordedEntitiesLock)
398399
{
399-
m_recordedBindings.RemoveWhere(b => b.Equals(rb));
400+
m_recordedBindings.Remove(rb);
400401
}
401402
}
402403

@@ -423,11 +424,10 @@ public void DeleteRecordedExchange(string name)
423424

424425
// find bindings that need removal, check if some auto-delete exchanges
425426
// might need the same
426-
List<RecordedBinding> bs = m_recordedBindings.Where(b => name.Equals(b.Destination)).
427-
ToList();
428-
m_recordedBindings.RemoveWhere(b => name.Equals(b.Destination));
427+
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
429428
foreach (RecordedBinding b in bs)
430429
{
430+
m_recordedBindings.Remove(b);
431431
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
432432
}
433433
}
@@ -440,11 +440,10 @@ public void DeleteRecordedQueue(string name)
440440
m_recordedQueues.Remove(name);
441441
// find bindings that need removal, check if some auto-delete exchanges
442442
// might need the same
443-
List<RecordedBinding> bs = m_recordedBindings.Where(b => name.Equals(b.Destination)).
444-
ToList();
445-
m_recordedBindings.RemoveWhere(b => name.Equals(b.Destination));
443+
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
446444
foreach (RecordedBinding b in bs)
447445
{
446+
m_recordedBindings.Remove(b);
448447
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
449448
}
450449
}
@@ -466,7 +465,7 @@ public void MaybeDeleteRecordedAutoDeleteExchange(string exchange)
466465
{
467466
lock (m_recordedEntitiesLock)
468467
{
469-
if (!HasMoreDestinationsBoundToExchange(m_recordedBindings, exchange))
468+
if (!HasMoreDestinationsBoundToExchange(m_recordedBindings.Keys, exchange))
470469
{
471470
RecordedExchange rx;
472471
m_recordedExchanges.TryGetValue(exchange, out rx);
@@ -503,7 +502,7 @@ public void RecordBinding(RecordedBinding rb)
503502
{
504503
lock (m_recordedEntitiesLock)
505504
{
506-
m_recordedBindings.Add(rb);
505+
m_recordedBindings.Add(rb, 0);
507506
}
508507
}
509508

@@ -719,8 +718,7 @@ protected void PropagateQueueNameChangeToBindings(string oldName, string newName
719718
{
720719
lock (m_recordedBindings)
721720
{
722-
IEnumerable<RecordedBinding> bs = m_recordedBindings.
723-
Where(b => b.Destination.Equals(oldName));
721+
var bs = m_recordedBindings.Keys.Where(b => b.Destination.Equals(oldName));
724722
foreach (RecordedBinding b in bs)
725723
{
726724
b.Destination = newName;
@@ -743,7 +741,7 @@ protected void PropagateQueueNameChangeToConsumers(string oldName, string newNam
743741

744742
protected void RecoverBindings()
745743
{
746-
foreach (RecordedBinding b in m_recordedBindings)
744+
foreach (var b in m_recordedBindings.Keys)
747745
{
748746
try
749747
{
@@ -815,8 +813,7 @@ protected void RecoverConnectionUnblockedHandlers()
815813

816814
protected void RecoverConsumers()
817815
{
818-
var dict = new Dictionary<string, RecordedConsumer>(m_recordedConsumers);
819-
foreach (KeyValuePair<string, RecordedConsumer> pair in dict)
816+
foreach (KeyValuePair<string, RecordedConsumer> pair in m_recordedConsumers)
820817
{
821818
string tag = pair.Key;
822819
RecordedConsumer cons = pair.Value;
@@ -903,8 +900,7 @@ protected void RecoverQueues()
903900
{
904901
lock (m_recordedQueues)
905902
{
906-
var rqs = new Dictionary<string, RecordedQueue>(m_recordedQueues);
907-
foreach (KeyValuePair<string, RecordedQueue> pair in rqs)
903+
foreach (KeyValuePair<string, RecordedQueue> pair in m_recordedQueues)
908904
{
909905
string oldName = pair.Key;
910906
RecordedQueue rq = pair.Value;

0 commit comments

Comments
 (0)