Skip to content

Commit 73852d3

Browse files
committed
Merge branch 'stable' into 4.x
2 parents 8b4da21 + f7a7dc7 commit 73852d3

File tree

3 files changed

+62
-52
lines changed

3 files changed

+62
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gensrc/
66
[Ll]ocal.props
77
[Ll]ocal.dist
88

9+
.vscode
910
*.pyc
1011
docs/pyle.log
1112
docs/pyle.pid

projects/client/RabbitMQ.Client/src/client/events/EventingBasicConsumer.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,14 @@ public EventingBasicConsumer(IModel model) : base(model)
6868
public override void HandleBasicCancelOk(string consumerTag)
6969
{
7070
base.HandleBasicCancelOk(consumerTag);
71-
72-
if (Unregistered != null)
73-
{
74-
Unregistered(this, new ConsumerEventArgs(consumerTag));
75-
}
71+
Raise(Unregistered, new ConsumerEventArgs(consumerTag));
7672
}
7773

7874
///<summary>Fires the Registered event.</summary>
7975
public override void HandleBasicConsumeOk(string consumerTag)
8076
{
8177
base.HandleBasicConsumeOk(consumerTag);
82-
83-
if (Registered != null)
84-
{
85-
Registered(this, new ConsumerEventArgs(consumerTag));
86-
}
78+
Raise(Registered, new ConsumerEventArgs(consumerTag));
8779
}
8880

8981
///<summary>Fires the Received event.</summary>
@@ -102,26 +94,28 @@ public override void HandleBasicDeliver(string consumerTag,
10294
routingKey,
10395
properties,
10496
body);
105-
if (Received != null)
106-
{
107-
Received(this, new BasicDeliverEventArgs(consumerTag,
108-
deliveryTag,
109-
redelivered,
110-
exchange,
111-
routingKey,
112-
properties,
113-
body));
114-
}
97+
Raise(Received, new BasicDeliverEventArgs(consumerTag,
98+
deliveryTag,
99+
redelivered,
100+
exchange,
101+
routingKey,
102+
properties,
103+
body));
115104
}
116105

117106
///<summary>Fires the Shutdown event.</summary>
118107
public override void HandleModelShutdown(object model, ShutdownEventArgs reason)
119108
{
120109
base.HandleModelShutdown(model, reason);
110+
Raise(Shutdown, reason);
111+
}
121112

122-
if (Shutdown != null)
113+
private void Raise<TEvent>(EventHandler<TEvent> eventHandler, TEvent evt)
114+
{
115+
var handler = eventHandler;
116+
if(handler != null)
123117
{
124-
Shutdown(this, reason);
118+
handler(this, evt);
125119
}
126120
}
127121
}

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

Lines changed: 45 additions & 30 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

@@ -53,6 +53,8 @@ namespace RabbitMQ.Client.Framing.Impl
5353
public class AutorecoveringConnection : IConnection, IRecoverable
5454
{
5555
public readonly object m_eventLock = new object();
56+
57+
public readonly object manuallyClosedLock = new object();
5658
protected Connection m_delegate;
5759
protected ConnectionFactory m_factory;
5860

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

7274
protected List<AutorecoveringModel> m_models = new List<AutorecoveringModel>();
7375

74-
protected HashSet<RecordedBinding> m_recordedBindings = new HashSet<RecordedBinding>();
76+
protected IDictionary<RecordedBinding, byte> m_recordedBindings =
77+
new ConcurrentDictionary<RecordedBinding, byte>();
7578

7679
protected List<EventHandler<ConnectionBlockedEventArgs>> m_recordedBlockedEventHandlers =
7780
new List<EventHandler<ConnectionBlockedEventArgs>>();
7881

7982
protected IDictionary<string, RecordedConsumer> m_recordedConsumers =
80-
new Dictionary<string, RecordedConsumer>();
83+
new ConcurrentDictionary<string, RecordedConsumer>();
8184

8285
protected IDictionary<string, RecordedExchange> m_recordedExchanges =
83-
new Dictionary<string, RecordedExchange>();
86+
new ConcurrentDictionary<string, RecordedExchange>();
8487

8588
protected IDictionary<string, RecordedQueue> m_recordedQueues =
86-
new Dictionary<string, RecordedQueue>();
89+
new ConcurrentDictionary<string, RecordedQueue>();
8790

8891
protected List<EventHandler<ShutdownEventArgs>> m_recordedShutdownEventHandlers =
8992
new List<EventHandler<ShutdownEventArgs>>();
@@ -101,6 +104,23 @@ public AutorecoveringConnection(ConnectionFactory factory, string clientProvided
101104
this.ClientProvidedName = clientProvidedName;
102105
}
103106

107+
private bool ManuallyClosed
108+
{
109+
get
110+
{
111+
lock(manuallyClosedLock)
112+
{
113+
return manuallyClosed;
114+
}
115+
}
116+
set
117+
{
118+
lock(manuallyClosedLock)
119+
{
120+
manuallyClosed = value; }
121+
}
122+
}
123+
104124
public event EventHandler<CallbackExceptionEventArgs> CallbackException
105125
{
106126
add
@@ -338,7 +358,7 @@ public void BeginAutomaticRecovery()
338358

339359
recoveryTaskFactory.StartNew(() =>
340360
{
341-
if(!self.manuallyClosed)
361+
if(!self.ManuallyClosed)
342362
{
343363
try
344364
{
@@ -396,7 +416,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
396416
{
397417
lock (m_recordedEntitiesLock)
398418
{
399-
m_recordedBindings.RemoveWhere(b => b.Equals(rb));
419+
m_recordedBindings.Remove(rb);
400420
}
401421
}
402422

@@ -423,11 +443,10 @@ public void DeleteRecordedExchange(string name)
423443

424444
// find bindings that need removal, check if some auto-delete exchanges
425445
// 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));
446+
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
429447
foreach (RecordedBinding b in bs)
430448
{
449+
m_recordedBindings.Remove(b);
431450
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
432451
}
433452
}
@@ -440,11 +459,10 @@ public void DeleteRecordedQueue(string name)
440459
m_recordedQueues.Remove(name);
441460
// find bindings that need removal, check if some auto-delete exchanges
442461
// 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));
462+
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
446463
foreach (RecordedBinding b in bs)
447464
{
465+
m_recordedBindings.Remove(b);
448466
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
449467
}
450468
}
@@ -466,7 +484,7 @@ public void MaybeDeleteRecordedAutoDeleteExchange(string exchange)
466484
{
467485
lock (m_recordedEntitiesLock)
468486
{
469-
if (!HasMoreDestinationsBoundToExchange(m_recordedBindings, exchange))
487+
if (!HasMoreDestinationsBoundToExchange(m_recordedBindings.Keys, exchange))
470488
{
471489
RecordedExchange rx;
472490
m_recordedExchanges.TryGetValue(exchange, out rx);
@@ -503,7 +521,7 @@ public void RecordBinding(RecordedBinding rb)
503521
{
504522
lock (m_recordedEntitiesLock)
505523
{
506-
m_recordedBindings.Add(rb);
524+
m_recordedBindings.Add(rb, 0);
507525
}
508526
}
509527

@@ -601,56 +619,56 @@ private void Init(IFrameHandler fh)
601619
///<summary>API-side invocation of connection abort.</summary>
602620
public void Abort()
603621
{
604-
this.manuallyClosed = true;
622+
this.ManuallyClosed = true;
605623
m_delegate.Abort();
606624
}
607625

608626
///<summary>API-side invocation of connection abort.</summary>
609627
public void Abort(ushort reasonCode, string reasonText)
610628
{
611-
this.manuallyClosed = true;
629+
this.ManuallyClosed = true;
612630
m_delegate.Abort(reasonCode, reasonText);
613631
}
614632

615633
///<summary>API-side invocation of connection abort with timeout.</summary>
616634
public void Abort(int timeout)
617635
{
618-
this.manuallyClosed = true;
636+
this.ManuallyClosed = true;
619637
m_delegate.Abort(timeout);
620638
}
621639

622640
///<summary>API-side invocation of connection abort with timeout.</summary>
623641
public void Abort(ushort reasonCode, string reasonText, int timeout)
624642
{
625-
this.manuallyClosed = true;
643+
this.ManuallyClosed = true;
626644
m_delegate.Abort(reasonCode, reasonText, timeout);
627645
}
628646

629647
///<summary>API-side invocation of connection.close.</summary>
630648
public void Close()
631649
{
632-
this.manuallyClosed = true;
650+
this.ManuallyClosed = true;
633651
m_delegate.Close();
634652
}
635653

636654
///<summary>API-side invocation of connection.close.</summary>
637655
public void Close(ushort reasonCode, string reasonText)
638656
{
639-
this.manuallyClosed = true;
657+
this.ManuallyClosed = true;
640658
m_delegate.Close(reasonCode, reasonText);
641659
}
642660

643661
///<summary>API-side invocation of connection.close with timeout.</summary>
644662
public void Close(int timeout)
645663
{
646-
this.manuallyClosed = true;
664+
this.ManuallyClosed = true;
647665
m_delegate.Close(timeout);
648666
}
649667

650668
///<summary>API-side invocation of connection.close with timeout.</summary>
651669
public void Close(ushort reasonCode, string reasonText, int timeout)
652670
{
653-
this.manuallyClosed = true;
671+
this.ManuallyClosed = true;
654672
m_delegate.Close(reasonCode, reasonText, timeout);
655673
}
656674

@@ -719,8 +737,7 @@ protected void PropagateQueueNameChangeToBindings(string oldName, string newName
719737
{
720738
lock (m_recordedBindings)
721739
{
722-
IEnumerable<RecordedBinding> bs = m_recordedBindings.
723-
Where(b => b.Destination.Equals(oldName));
740+
var bs = m_recordedBindings.Keys.Where(b => b.Destination.Equals(oldName));
724741
foreach (RecordedBinding b in bs)
725742
{
726743
b.Destination = newName;
@@ -743,7 +760,7 @@ protected void PropagateQueueNameChangeToConsumers(string oldName, string newNam
743760

744761
protected void RecoverBindings()
745762
{
746-
foreach (RecordedBinding b in m_recordedBindings)
763+
foreach (var b in m_recordedBindings.Keys)
747764
{
748765
try
749766
{
@@ -815,8 +832,7 @@ protected void RecoverConnectionUnblockedHandlers()
815832

816833
protected void RecoverConsumers()
817834
{
818-
var dict = new Dictionary<string, RecordedConsumer>(m_recordedConsumers);
819-
foreach (KeyValuePair<string, RecordedConsumer> pair in dict)
835+
foreach (KeyValuePair<string, RecordedConsumer> pair in m_recordedConsumers)
820836
{
821837
string tag = pair.Key;
822838
RecordedConsumer cons = pair.Value;
@@ -903,8 +919,7 @@ protected void RecoverQueues()
903919
{
904920
lock (m_recordedQueues)
905921
{
906-
var rqs = new Dictionary<string, RecordedQueue>(m_recordedQueues);
907-
foreach (KeyValuePair<string, RecordedQueue> pair in rqs)
922+
foreach (KeyValuePair<string, RecordedQueue> pair in m_recordedQueues)
908923
{
909924
string oldName = pair.Key;
910925
RecordedQueue rq = pair.Value;

0 commit comments

Comments
 (0)