activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r1135832 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x: ./ src/main/csharp/Transport/ src/main/csharp/Transport/Failover/ src/main/csharp/Transport/Tcp/
Date Tue, 14 Jun 2011 22:36:38 GMT
Author: jgomes
Date: Tue Jun 14 22:36:38 2011
New Revision: 1135832

URL: http://svn.apache.org/viewvc?rev=1135832&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.Stomp/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/vs2008-stomp-test.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Failover/FailoverTransport.cs
Tue Jun 14 22:36:38 2011
@@ -55,6 +55,7 @@ namespace Apache.NMS.Stomp.Transport.Fai
         private bool started;
 
         private int timeout = -1;
+		private int asyncTimeout = 45000;
         private int initialReconnectDelay = 10;
         private int maxReconnectDelay = 1000 * 30;
         private int backOffMultiplier = 2;
@@ -217,7 +218,17 @@ namespace Apache.NMS.Stomp.Transport.Fai
 
         #endregion
 
-        public bool IsFaultTolerant
+		/// <summary>
+		/// If doing an asynchronous connect, the milliseconds before timing out if no connection
can be made
+		/// </summary>
+		/// <value>The async timeout.</value>
+		public int AsyncTimeout
+		{
+			get { return asyncTimeout; }
+			set { asyncTimeout = value; }
+		}
+
+		public bool IsFaultTolerant
         {
             get { return true; }
         }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/ITransport.cs?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/ITransport.cs
Tue Jun 14 22:36:38 2011
@@ -70,6 +70,26 @@ namespace Apache.NMS.Stomp.Transport
         /// </summary>
         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.Stomp/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/MutexTransport.cs
Tue Jun 14 22:36:38 2011
@@ -14,44 +14,86 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-using Apache.NMS.Stomp.Commands;
 using System;
+using System.Threading;
+using Apache.NMS.Stomp.Commands;
 
 namespace Apache.NMS.Stomp.Transport
 {
-	/// <summary>
 	/// A Transport which guards access to the next transport using a mutex.
 	/// </summary>
 	public class MutexTransport : TransportFilter
 	{
 		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.Stomp/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/Tcp/TcpTransport.cs
Tue Jun 14 22:36:38 2011
@@ -40,6 +40,8 @@ namespace Apache.NMS.Stomp.Transport.Tcp
         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;
@@ -314,7 +316,27 @@ namespace Apache.NMS.Stomp.Transport.Tcp
 
         // Implementation methods
 
-        public CommandHandler Command
+		/// <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; }
             set { this.commandHandler = value; }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/src/main/csharp/Transport/TransportFilter.cs
Tue Jun 14 22:36:38 2011
@@ -206,6 +206,26 @@ namespace Apache.NMS.Stomp.Transport
             return null;
         }
         
+		/// <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; }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/vs2008-stomp-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/vs2008-stomp-test.csproj?rev=1135832&r1=1135831&r2=1135832&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/vs2008-stomp-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/branches/1.5.x/vs2008-stomp-test.csproj Tue
Jun 14 22:36:38 2011
@@ -3,7 +3,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.21022</ProductVersion>
+    <ProductVersion>9.0.30729</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{E8C995C3-FF81-491B-A3B7-9D7C753BDDC3}</ProjectGuid>
     <OutputType>Library</OutputType>
@@ -55,16 +55,20 @@
     <NoWarn>3016</NoWarn>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Apache.NMS, Version=1.5.1.2341, Culture=neutral, PublicKeyToken=82756feee3957618,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\Apache.NMS\net-2.0\Apache.NMS.dll</HintPath>
+    </Reference>
+    <Reference Include="Apache.NMS.Test, Version=1.5.1.2341, Culture=neutral, PublicKeyToken=82756feee3957618,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\Apache.NMS\net-2.0\Apache.NMS.Test.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Xml" />
     <Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>lib\NUnit\mono-2.0\nunit.framework.dll</HintPath>
     </Reference>
-    <Reference Include="Apache.NMS.Test, Version=1.4.0.2071, Culture=neutral, PublicKeyToken=82756feee3957618">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>lib\Apache.NMS\mono-2.0\Apache.NMS.Test.dll</HintPath>
-    </Reference>
   </ItemGroup>
   <ItemGroup>
     <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">



Mime
View raw message