activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1066863 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp: Connection.cs MessageConsumer.cs MessageProducer.cs Session.cs
Date Thu, 03 Feb 2011 16:49:40 GMT
Author: tabish
Date: Thu Feb  3 16:49:39 2011
New Revision: 1066863

URL: http://svn.apache.org/viewvc?rev=1066863&view=rev
Log:
Fix up the close / dispose methods to better handle shutdown when a parent resource is closed
before its child.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs?rev=1066863&r1=1066862&r2=1066863&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs Thu Feb
 3 16:49:39 2011
@@ -518,13 +518,18 @@ namespace Apache.NMS.ActiveMQ
 
         public void Close()
         {
+			if(!this.closed.Value && !transportFailed.Value)
+			{
+				this.Stop();
+			}
+						
             lock(myLock)
             {
                 if(this.closed.Value)
                 {
                     return;
                 }
-
+				
                 try
                 {
                     Tracer.Info("Connection.Close(): Closing Connection Now.");
@@ -534,7 +539,7 @@ namespace Apache.NMS.ActiveMQ
                     {
                         foreach(Session session in sessions)
                         {
-                            session.DoClose();
+                            session.Shutdown();
                         }
                     }
                     sessions.Clear();
@@ -548,7 +553,7 @@ namespace Apache.NMS.ActiveMQ
 
                     executor.Shutdown();
 
-                    Tracer.Info("Disposing of the Transport.");
+                    Tracer.Info("Connection: Disposing of the Transport.");
                     transport.Dispose();
                 }
                 catch(Exception ex)
@@ -557,6 +562,11 @@ namespace Apache.NMS.ActiveMQ
                 }
                 finally
                 {
+					if(executor != null)
+					{
+                    	executor.Shutdown();
+					}
+					
                     this.transport = null;
                     this.closed.Value = true;
                     this.connected.Value = false;
@@ -585,9 +595,6 @@ namespace Apache.NMS.ActiveMQ
 
             try
             {
-                // For now we do not distinguish between Dispose() and Close().
-                // In theory Dispose should possibly be lighter-weight and perform a (faster)
-                // disorderly close.
                 Close();
             }
             catch
@@ -909,7 +916,7 @@ namespace Apache.NMS.ActiveMQ
             {
                 try
                 {
-                    session.Dispose();
+                    session.Shutdown();
                 }
                 catch(Exception ex)
                 {

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=1066863&r1=1066862&r2=1066863&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
Thu Feb  3 16:49:39 2011
@@ -344,9 +344,32 @@ namespace Apache.NMS.ActiveMQ
 
 		internal void DoClose()
 		{
+	        Shutdown();
+			RemoveInfo removeCommand = new RemoveInfo();
+			removeCommand.ObjectId = this.ConsumerId;
+	        if (Tracer.IsDebugEnabled) 
+			{
+				Tracer.DebugFormat("Remove of Consumer[{0}] sent last delivered Id[{1}].", 
+				                   this.ConsumerId, this.lastDeliveredSequenceId);
+	        }
+	        removeCommand.LastDeliveredSequenceId = lastDeliveredSequenceId;
+	        this.session.Connection.Oneway(removeCommand);
+		}
+		
+		/// <summary>
+		/// Called from the parent Session of this Consumer to indicate that its
+		/// parent session is closing and this Consumer should close down but not
+		/// send any message to the Broker as the parent close will take care of
+		/// removing its child resources at the broker.
+		/// </summary>
+		internal void Shutdown()
+		{
 			if(!this.unconsumedMessages.Closed)
 			{
-				Tracer.Debug("Closing down the Consumer");
+				if(Tracer.IsDebugEnabled)
+				{
+					Tracer.DebugFormat("Shutdown of Consumer[{0}] started.", ConsumerId);
+				}
 
 				// Do we have any acks we need to send out before closing?
 				// Ack any delivered messages now.
@@ -367,18 +390,14 @@ namespace Apache.NMS.ActiveMQ
 					}
 				}
 
+				this.session.RemoveConsumer(this.ConsumerId);
 				this.unconsumedMessages.Close();
-				this.session.RemoveConsumer(this.info.ConsumerId);
 
-				RemoveInfo removeCommand = new RemoveInfo();
-				removeCommand.ObjectId = this.info.ConsumerId;
-				removeCommand.LastDeliveredSequenceId = this.lastDeliveredSequenceId;
-
-				this.session.Connection.Oneway(removeCommand);
-				this.session = null;
-
-				Tracer.Debug("Consumer instance Closed.");
-			}
+				if(Tracer.IsDebugEnabled)
+				{
+					Tracer.DebugFormat("Shutdown of Consumer[{0}] completed.", ConsumerId);
+				}
+			}			
 		}
 
 		#endregion

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs?rev=1066863&r1=1066862&r2=1066863&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageProducer.cs
Thu Feb  3 16:49:39 2011
@@ -117,15 +117,23 @@ namespace Apache.NMS.ActiveMQ
 					return;
 				}
 
-				DoClose();
+				Shutdown();
 				RemoveInfo removeInfo = new RemoveInfo();
 				removeInfo.ObjectId = this.info.ProducerId;
 				this.session.Connection.Oneway(removeInfo);
-				this.session = null;
+				if(Tracer.IsDebugEnabled)
+				{
+					Tracer.DebugFormat("Remove of Producer[{0}] sent.", this.ProducerId);
+				}
 			}
 		}
 
-		internal void DoClose()
+		/// <summary>
+		/// Called from the Parent session to deactivate this Producer, when a parent
+		/// is closed all children are automatically removed from the broker so this
+		/// method circumvents the need to send a Remove command to the broker.
+		/// </summary>
+		internal void Shutdown()
 		{
 			lock(closedLock)
 			{

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs?rev=1066863&r1=1066862&r2=1066863&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs Thu Feb
 3 16:49:39 2011
@@ -331,6 +331,15 @@ namespace Apache.NMS.ActiveMQ
 
         internal void DoClose()
         {
+			Shutdown();
+            RemoveInfo info = new RemoveInfo();
+            info.ObjectId = this.info.SessionId;
+            info.LastDeliveredSequenceId = this.lastDeliveredSequenceId;
+            this.connection.Oneway(info);
+		}
+		
+        internal void Shutdown()
+        {
             lock(myLock)
             {
                 if(this.closed)
@@ -350,7 +359,7 @@ namespace Apache.NMS.ActiveMQ
                         foreach(MessageConsumer consumer in consumers.Values)
                         {
                             consumer.FailureError = this.connection.FirstFailureError;
-                            consumer.DoClose();
+                            consumer.Shutdown();
                             this.lastDeliveredSequenceId =
                                 Math.Min(this.lastDeliveredSequenceId, consumer.LastDeliveredSequenceId);
                         }
@@ -361,7 +370,7 @@ namespace Apache.NMS.ActiveMQ
                     {
                         foreach(MessageProducer producer in producers.Values)
                         {
-                            producer.DoClose();
+                            producer.Shutdown();
                         }
                     }
                     producers.Clear();
@@ -386,12 +395,6 @@ namespace Apache.NMS.ActiveMQ
                 }
                 finally
                 {
-                    // Make sure we attempt to inform the broker this Session is done.
-                    RemoveInfo info = new RemoveInfo();
-                    info.ObjectId = this.info.SessionId;
-                    info.LastDeliveredSequenceId = this.lastDeliveredSequenceId;
-                    this.connection.Oneway(info);
-                    this.connection = null;
                     this.closed = true;
                     this.closing = false;
                 }



Mime
View raw message