activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r592504 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp: MessageConsumer.cs Transport/Tcp/TcpTransport.cs
Date Tue, 06 Nov 2007 17:58:15 GMT
Author: chirino
Date: Tue Nov  6 09:58:14 2007
New Revision: 592504

URL: http://svn.apache.org/viewvc?rev=592504&view=rev
Log:
- Fixed a deadlock situation in TcpTransport.cs where if the client thread calls close() and
the async run thread calls close() then they hang waiting for each other.
- AutoAcks were not being sent back to the broker and therefore no message were being consumed.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs?rev=592504&r1=592503&r2=592504&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
Tue Nov  6 09:58:14 2007
@@ -94,19 +94,19 @@
 		public IMessage Receive()
 		{
 			CheckClosed();
-			return AutoClientAcknowledge(dispatcher.Dequeue());
+            return SetupAcknowledge(dispatcher.Dequeue());
 		}
 
 		public IMessage Receive(System.TimeSpan timeout)
 		{
 			CheckClosed();
-			return AutoClientAcknowledge(dispatcher.Dequeue(timeout));
+            return SetupAcknowledge(dispatcher.Dequeue(timeout));
 		}
 
 		public IMessage ReceiveNoWait()
 		{
 			CheckClosed();
-			return AutoClientAcknowledge(dispatcher.DequeueNoWait());
+            return SetupAcknowledge(dispatcher.DequeueNoWait());
 		}
 
 		public void Dispose()
@@ -190,7 +190,7 @@
 					break;
 				}
 
-				message = AutoClientAcknowledge(message);
+                message = SetupAcknowledge(message);
 				// invoke listener. Exceptions caught by the dispatcher thread
 				listener(message);
 			}
@@ -207,33 +207,42 @@
 			}
 		}
 
-		protected IMessage AutoClientAcknowledge(IMessage message)
+		protected IMessage SetupAcknowledge(IMessage message)
 		{
-			if(AcknowledgementMode.AutoAcknowledge != acknowledgementMode)
-			{
-				if(message is ActiveMQMessage)
-				{
-					ActiveMQMessage activeMessage = (ActiveMQMessage) message;
-
-					// lets register the handler for client acknowledgment
-					activeMessage.Acknowledger += new AcknowledgeHandler(DoClientAcknowledge);
-				}
+            if (message == null)
+                return null;
 
-				message.Acknowledge();
-			}
+            if (acknowledgementMode == AcknowledgementMode.ClientAcknowledge)
+            {
+                if (message is ActiveMQMessage)
+                {
+                    ActiveMQMessage activeMessage = (ActiveMQMessage)message;
+                    activeMessage.Acknowledger += new AcknowledgeHandler(DoClientAcknowledge);
+                }
+            }
+            else
+            {
+                if (message is ActiveMQMessage)
+                {
+                    ActiveMQMessage activeMessage = (ActiveMQMessage)message;
+                    activeMessage.Acknowledger += new AcknowledgeHandler(DoNothingAcknowledge);
+
+                    MessageAck ack = CreateMessageAck(activeMessage);
+                    Tracer.Debug("Sending Ack: " + ack);
+                    session.Connection.OneWay(ack);
+                }
+            }
 			return message;
 		}
 
-		protected void DoClientAcknowledge(ActiveMQMessage message)
-		{
-			if(AcknowledgementMode.AutoClientAcknowledge == acknowledgementMode
-				|| AcknowledgementMode.DupsOkAcknowledge == acknowledgementMode
-				|| AcknowledgementMode.ClientAcknowledge == acknowledgementMode)
-			{
-				MessageAck ack = CreateMessageAck(message);
-				Tracer.Debug("Sending Ack: " + ack);
-				session.Connection.OneWay(ack);
-			}
+        protected void DoNothingAcknowledge(ActiveMQMessage message)
+        {
+        }
+        protected void DoClientAcknowledge(ActiveMQMessage message)
+		{
+			MessageAck ack = CreateMessageAck(message);
+			Tracer.Debug("Sending Ack: " + ack);
+			session.Connection.OneWay(ack);
 		}
 
 		protected virtual MessageAck CreateMessageAck(Message message)

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs?rev=592504&r1=592503&r2=592504&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs
Tue Nov  6 09:58:14 2007
@@ -125,11 +125,11 @@
 
         public void Close()
         {
-			lock (initLock)
+			if (closed.CompareAndSet(false, true))
 			{
-				if (closed.CompareAndSet(false, true))
-				{
-					try
+                lock (initLock)
+                {
+                        try
 					{
 						socket.Shutdown(SocketShutdown.Both);
 					}



Mime
View raw message