activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r1135831 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport: Failover/FailoverTransport.cs ITransport.cs Mock/MockTransport.cs MutexTransport.cs Tcp/TcpTransport.cs TransportFilter.cs
Date Tue, 14 Jun 2011 22:31:54 GMT
Author: jgomes
Date: Tue Jun 14 22:31:54 2011
New Revision: 1135831

URL: http://svn.apache.org/viewvc?rev=1135831&view=rev
Log:
Add support for transport timeout while waiting for mutex lock.
Fixes [AMQNET-330]. (See https://issues.apache.org/activemq/browse/AMQNET-330)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Mock/MockTransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
Tue Jun 14 22:31:54 2011
@@ -303,6 +303,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
 		/// <value>The async timeout.</value>
 		public int AsyncTimeout
 		{
+			get { return asyncTimeout; }
 			set { asyncTimeout = value; }
 		}
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/ITransport.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
Tue Jun 14 22:31:54 2011
@@ -83,7 +83,7 @@ namespace Apache.NMS.ActiveMQ.Transport
         /// </returns>
 		Response Request(Command command, TimeSpan timeout);
 
-        /// <summary>
+		/// <summary>
         /// Allows a caller to find a specific type of Transport in the Chain of
         /// Transports that is created.  This allows a caller to find a specific
         /// object in the Transport chain and set or get properties on that specific
@@ -97,6 +97,26 @@ namespace Apache.NMS.ActiveMQ.Transport
         /// </returns>
         Object Narrow(Type type);
 
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending synchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		int Timeout
+		{
+			get;
+			set;
+		}
+
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending asynchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		int AsyncTimeout
+		{
+			get;
+			set;
+		}
+
 		CommandHandler Command
 		{
 			get;

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Mock/MockTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Mock/MockTransport.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Mock/MockTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Mock/MockTransport.cs
Tue Jun 14 22:31:54 2011
@@ -36,6 +36,8 @@ namespace Apache.NMS.ActiveMQ.Transport.
 		#region Properties
 
 		private string name;
+		private int timeout = -1;
+		private int asynctimeout = -1;
 		private bool failOnSendMessage = false;
 		private int numMessagesToRespondTo = -1;
 		private int numMessagesRespondedTo = 0;
@@ -127,7 +129,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
 
 		public Response Request(Command command)
 		{
-			return this.Request(command, TimeSpan.FromMilliseconds(Timeout.Infinite));
+			return this.Request(command, TimeSpan.FromMilliseconds(System.Threading.Timeout.Infinite));
 		}
 
 		public Response Request(Command command, TimeSpan timeout)
@@ -291,6 +293,26 @@ namespace Apache.NMS.ActiveMQ.Transport.
 			set { this.name = value; }
 		}
 
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending synchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int Timeout
+		{
+			get { return this.timeout; }
+			set { this.timeout = value; }
+		}
+
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending asynchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int AsyncTimeout
+		{
+			get { return this.asynctimeout; }
+			set { this.asynctimeout = value; }
+		}
+
 		public CommandHandler Command
 		{
 			get { return commandHandler; }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
Tue Jun 14 22:31:54 2011
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 using System;
+using System.Threading;
 using Apache.NMS.ActiveMQ.Commands;
 
 namespace Apache.NMS.ActiveMQ.Transport
@@ -26,32 +27,74 @@ namespace Apache.NMS.ActiveMQ.Transport
 	{
 		private readonly object transmissionLock = new object();
 
+		private void GetTransmissionLock(int timeout)
+		{
+			if(timeout > 0)
+			{
+				DateTime timeoutTime = DateTime.Now + TimeSpan.FromMilliseconds(timeout);
+
+				while(true)
+				{
+					if(Monitor.TryEnter(transmissionLock))
+					{
+						break;
+					}
+
+					if(DateTime.Now > timeoutTime)
+					{
+						throw new IOException(string.Format("Oneway timed out after {0} milliseconds.", timeout));
+					}
+
+					Thread.Sleep(10);
+				}
+			}
+			else
+			{
+				Monitor.Enter(transmissionLock);
+			}
+		}
+
 		public MutexTransport(ITransport next) : base(next)
 		{
 		}
 
 		public override void Oneway(Command command)
 		{
-			lock(transmissionLock)
+			GetTransmissionLock(this.next.Timeout);
+			try
+			{
+				base.Oneway(command);
+			}
+			finally
 			{
-				this.next.Oneway(command);
+				Monitor.Exit(transmissionLock);
 			}
 		}
 
 		public override FutureResponse AsyncRequest(Command command)
 		{
-			lock(transmissionLock)
+			GetTransmissionLock(this.next.AsyncTimeout);
+			try
 			{
 				return base.AsyncRequest(command);
 			}
+			finally
+			{
+				Monitor.Exit(transmissionLock);
+			}
 		}
 
 		public override Response Request(Command command, TimeSpan timeout)
 		{
-			lock(transmissionLock)
+			GetTransmissionLock((int) timeout.TotalMilliseconds);
+			try
 			{
 				return base.Request(command, timeout);
 			}
+			finally
+			{
+				Monitor.Exit(transmissionLock);
+			}
 		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
Tue Jun 14 22:31:54 2011
@@ -40,6 +40,8 @@ namespace Apache.NMS.ActiveMQ.Transport.
 		private readonly Atomic<bool> closed = new Atomic<bool>(false);
 		private volatile bool seenShutdown;
 		private readonly Uri connectedUri;
+		private int timeout = -1;
+		private int asynctimeout = -1;
 
 		private CommandHandler commandHandler;
 		private ExceptionHandler exceptionHandler;
@@ -310,6 +312,26 @@ namespace Apache.NMS.ActiveMQ.Transport.
 
 		// Implementation methods
 
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending synchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int Timeout
+		{
+			get { return this.timeout; }
+			set { this.timeout = value; }
+		}
+
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending asynchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int AsyncTimeout
+		{
+			get { return this.asynctimeout; }
+			set { this.asynctimeout = value; }
+		}
+
 		public CommandHandler Command
 		{
 			get { return commandHandler; }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs?rev=1135831&r1=1135830&r2=1135831&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
Tue Jun 14 22:31:54 2011
@@ -205,8 +205,28 @@ namespace Apache.NMS.ActiveMQ.Transport
         
             return null;
         }
-        
-        public bool IsFaultTolerant
+
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending synchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int Timeout
+		{
+			get { return next.Timeout; }
+			set { next.Timeout = value; }
+		}
+
+		/// <summary>
+		/// Timeout in milliseconds to wait for sending asynchronous messages or commands.
+		/// Set to -1 for infinite timeout.
+		/// </summary>
+		public int AsyncTimeout
+		{
+			get { return next.AsyncTimeout; }
+			set { next.AsyncTimeout = value; }
+		}
+		
+		public bool IsFaultTolerant
         {
             get{ return next.IsFaultTolerant; }
         }



Mime
View raw message