activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [24/50] [abbrv] activemq-nms-stomp git commit: Add support for transport timeout while waiting for mutex lock. Fixes [AMQNET-330]. (See https://issues.apache.org/activemq/browse/AMQNET-330)
Date Mon, 06 Mar 2017 23:29:48 GMT
Add support for transport timeout while waiting for mutex lock.
Fixes [AMQNET-330]. (See https://issues.apache.org/activemq/browse/AMQNET-330)



Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/commit/67916c24
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/tree/67916c24
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/diff/67916c24

Branch: refs/heads/1.5.x
Commit: 67916c249ec3dff2ed1da77849e70d8d9a9fe55e
Parents: 1f46042
Author: Jim Gomes <jgomes@apache.org>
Authored: Tue Jun 14 22:36:38 2011 +0000
Committer: Jim Gomes <jgomes@apache.org>
Committed: Tue Jun 14 22:36:38 2011 +0000

----------------------------------------------------------------------
 .../Transport/Failover/FailoverTransport.cs     | 13 ++++-
 src/main/csharp/Transport/ITransport.cs         | 20 ++++++++
 src/main/csharp/Transport/MutexTransport.cs     | 54 +++++++++++++++++---
 src/main/csharp/Transport/Tcp/TcpTransport.cs   | 24 ++++++++-
 src/main/csharp/Transport/TransportFilter.cs    | 20 ++++++++
 vs2008-stomp-test.csproj                        | 14 +++--
 6 files changed, 132 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/src/main/csharp/Transport/Failover/FailoverTransport.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Transport/Failover/FailoverTransport.cs b/src/main/csharp/Transport/Failover/FailoverTransport.cs
index 4d4d0ff..12c23af 100644
--- a/src/main/csharp/Transport/Failover/FailoverTransport.cs
+++ b/src/main/csharp/Transport/Failover/FailoverTransport.cs
@@ -55,6 +55,7 @@ namespace Apache.NMS.Stomp.Transport.Failover
         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.Failover
 
         #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; }
         }

http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/src/main/csharp/Transport/ITransport.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Transport/ITransport.cs b/src/main/csharp/Transport/ITransport.cs
index 2d7f7a7..1e60307 100755
--- a/src/main/csharp/Transport/ITransport.cs
+++ b/src/main/csharp/Transport/ITransport.cs
@@ -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;

http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/src/main/csharp/Transport/MutexTransport.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Transport/MutexTransport.cs b/src/main/csharp/Transport/MutexTransport.cs
index 7fe6134..c5cbc31 100644
--- a/src/main/csharp/Transport/MutexTransport.cs
+++ b/src/main/csharp/Transport/MutexTransport.cs
@@ -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);
+			}
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/src/main/csharp/Transport/Tcp/TcpTransport.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Transport/Tcp/TcpTransport.cs b/src/main/csharp/Transport/Tcp/TcpTransport.cs
index cc955dc..0c9b6bc 100644
--- a/src/main/csharp/Transport/Tcp/TcpTransport.cs
+++ b/src/main/csharp/Transport/Tcp/TcpTransport.cs
@@ -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; }

http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/src/main/csharp/Transport/TransportFilter.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Transport/TransportFilter.cs b/src/main/csharp/Transport/TransportFilter.cs
index 9c4bdbd..0c5c01c 100644
--- a/src/main/csharp/Transport/TransportFilter.cs
+++ b/src/main/csharp/Transport/TransportFilter.cs
@@ -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; }

http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/67916c24/vs2008-stomp-test.csproj
----------------------------------------------------------------------
diff --git a/vs2008-stomp-test.csproj b/vs2008-stomp-test.csproj
index ffb03ae..ec42a91 100644
--- a/vs2008-stomp-test.csproj
+++ b/vs2008-stomp-test.csproj
@@ -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