You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/09/22 20:09:39 UTC
svn commit: r449028 -
/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs
Author: jstrachan
Date: Fri Sep 22 11:09:38 2006
New Revision: 449028
URL: http://svn.apache.org/viewvc?view=rev&rev=449028
Log:
Added a patch for AMQ-930 to synchronize access to consumers.Values
Modified:
incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs
Modified: incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs?view=diff&rev=449028&r1=449027&r2=449028
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs Fri Sep 22 11:09:38 2006
@@ -32,7 +32,7 @@
private long consumerCounter;
private long producerCounter;
private int prefetchSize = 1000;
- private IDictionary consumers = new Hashtable();
+ private IDictionary consumers = Hashtable.Synchronized(new Hashtable());
private TransactionContext transactionContext;
public Session(Connection connection, SessionInfo info, AcknowledgementMode acknowledgementMode)
@@ -218,7 +218,7 @@
transactionContext.Rollback();
// lets ensure all the consumers redeliver any rolled back messages
- foreach (MessageConsumer consumer in consumers.Values)
+ foreach (MessageConsumer consumer in GetConsumers())
{
consumer.RedeliverRolledBackMessages();
}
@@ -282,13 +282,25 @@
{
// lets ensure that only 1 thread dispatches messages in a consumer at once
- foreach (MessageConsumer consumer in consumers.Values)
+ foreach (MessageConsumer consumer in GetConsumers())
{
consumer.DispatchAsyncMessages();
}
}
}
-
+
+
+ /// <summary>
+ /// Returns a copy of the current consumers in a thread safe way to avoid concurrency
+ /// problems if the consumers are changed in another thread
+ /// </summary>
+ protected ICollection GetConsumers()
+ {
+ lock (consumers.SyncRoot)
+ {
+ return new ArrayList(consumers.Values);
+ }
+ }
protected virtual ConsumerInfo CreateConsumerInfo(IDestination destination, string selector)
{