activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r449028 - /incubator/activemq/activemq-dotnet/trunk/src/main/csharp/ActiveMQ/Session.cs
Date Fri, 22 Sep 2006 18:09:39 GMT
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)
         {



Mime
View raw message