You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2011/06/15 00:41:41 UTC
svn commit: r1135833 - in
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk: ./
src/main/csharp/Transport/ src/main/csharp/Transport/Failover/
src/main/csharp/Transport/Mock/ src/main/csharp/Transport/Tcp/
Author: jgomes
Date: Tue Jun 14 22:41:40 2011
New Revision: 1135833
URL: http://svn.apache.org/viewvc?rev=1135833&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/trunk/ (props changed)
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nant-common.xml (props changed)
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/MutexTransport.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransport.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj (props changed)
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj (props changed)
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.sln (props changed)
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 14 22:41:40 2011
@@ -1,3 +1,3 @@
-/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x:1082291
+/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x:1082291,1135831
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.0.0:692591,693525
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.1.0:788230,788233,790183
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/nant-common.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 14 22:41:40 2011
@@ -1,2 +1,2 @@
-/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/nant-common.xml:1082291
+/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/nant-common.xml:1082291,1135831
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.1.0/nant-common.xml:788230,788233,790183
Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs?rev=1135833&r1=1135832&r2=1135833&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransport.cs Tue Jun 14 22:41:40 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/trunk/src/main/csharp/Transport/ITransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs?rev=1135833&r1=1135832&r2=1135833&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransport.cs Tue Jun 14 22:41:40 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/trunk/src/main/csharp/Transport/Mock/MockTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs?rev=1135833&r1=1135832&r2=1135833&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransport.cs Tue Jun 14 22:41:40 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/trunk/src/main/csharp/Transport/MutexTransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/MutexTransport.cs?rev=1135833&r1=1135832&r2=1135833&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/MutexTransport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/MutexTransport.cs Tue Jun 14 22:41:40 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/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=1135833&r1=1135832&r2=1135833&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 Jun 14 22:41:40 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/trunk/src/main/csharp/Transport/TransportFilter.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs?rev=1135833&r1=1135832&r2=1135833&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFilter.cs Tue Jun 14 22:41:40 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; }
}
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 14 22:41:40 2011
@@ -1,2 +1,2 @@
-/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq-test.csproj:1082291
+/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq-test.csproj:1082291,1135831
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.1.0/vs2008-activemq-test.csproj:788230,788233,790183
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 14 22:41:40 2011
@@ -1,2 +1,2 @@
-/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq.csproj:1082291
+/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq.csproj:1082291,1135831
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.1.0/vs2008-activemq.csproj:788230,788233,790183
Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.sln
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 14 22:41:40 2011
@@ -1,2 +1,2 @@
-/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq.sln:1082291
+/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/vs2008-activemq.sln:1082291,1135831
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/tags/1.1.0/vs2008-activemq.sln:788230,788233,790183