activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r807840 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport: ./ Discovery/ Failover/ Mock/ Tcp/
Date Tue, 25 Aug 2009 22:27:30 GMT
Author: jgomes
Date: Tue Aug 25 22:27:29 2009
New Revision: 807840

URL: http://svn.apache.org/viewvc?rev=807840&view=rev
Log:
Applied patch from Mark Gellings.  Hope I merged everything correctly.  Thanks, Mark!
Fixes [AMQNET-159]. (See https://issues.apache.org/activemq/browse/AMQNET-159)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
    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/Failover/FailoverTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFactory.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -40,7 +40,7 @@
 			agent.OnNewServiceFound += agent_OnNewServiceFound;
 			agent.OnServiceRemoved += agent_OnServiceRemoved;
 		}
-		
+
 		public DiscoveryTransportFactory()
 		{
 			lock(uriLock)
@@ -48,7 +48,7 @@
 				currentServiceName = String.Empty;
 			}
 		}
-		
+
 		public static Uri DiscoveredUri
 		{
 			get { lock(uriLock) { return discoveredUri; } }
@@ -92,7 +92,7 @@
 			}
 
 			Uri hostUri = DiscoveredUri;
-			
+
 			if(null == hostUri)
 			{
 				// If a new broker is found the agent will fire an event which will result in discoveredUri
being set.
@@ -113,6 +113,12 @@
 			throw new NMSConnectionException("Composite connection not supported with MulticastDiscovery
transport.");
 		}
 
+
+		public ITransport CompositeConnect(Uri location, SetTransport setTransport)
+		{
+			throw new NMSConnectionException("Composite connection not supported with Discovery transport.");
+		}
+
 		#endregion
 	}
 }

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=807840&r1=807839&r2=807840&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 Aug 25 22:27:29 2009
@@ -79,6 +79,25 @@
 		private bool _trackMessages = false;
 		private int _maxCacheSize = 256;
 		private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
+		private volatile Exception _failure;
+		private readonly object _syncLock = new object();
+
+		internal Exception Failure
+		{
+			get
+			{
+				return _failure;
+			}
+
+			set
+			{
+				lock(_syncLock)
+				{
+					_failure = value;
+				}
+
+			}
+		}
 
 		public TimeSpan RequestTimeout
 		{
@@ -258,10 +277,10 @@
 					reconnectMutex.ReleaseMutex();
 				}
 
-                if( this.Interrupted != null )
-                {
-                    this.Interrupted( transport );
-                }
+				if(this.Interrupted != null)
+				{
+					this.Interrupted(transport);
+				}
 			}
 		}
 
@@ -714,7 +733,7 @@
 			cc.FaultTolerant = true;
 			t.Oneway(cc);
 			stateTracker.DoRestore(t);
-			
+
 			Tracer.Info("Sending queued commands...");
 			Dictionary<int, Command> tmpMap = null;
 			lock(((ICollection) requestMap).SyncRoot)
@@ -751,28 +770,55 @@
 			}
 		}
 
-        public Object Narrow(Type type)
-        {
-            if(this.GetType().Equals(type))
-            {
-                return this;
-            }
-            else if(ConnectedTransport != null)
-            {
-                return ConnectedTransport.Narrow(type);
-            }
+		public Object Narrow(Type type)
+		{
+			if(this.GetType().Equals(type))
+			{
+				return this;
+			}
+			else if(ConnectedTransport != null)
+			{
+				return ConnectedTransport.Narrow(type);
+			}
 
-            return null;
-        }
+			return null;
+		}
 
 		public bool IsFaultTolerant
 		{
 			get { return true; }
 		}
 
+		private bool _asyncConnect = false;
+
+		/// <summary>
+		/// Gets or sets a value indicating whether to asynchronously connect to sockets
+		/// </summary>
+		/// <value><c>true</c> if [async connect]; otherwise, <c>false</c>.</value>
+		public bool AsyncConnect
+		{
+			set
+			{
+				_asyncConnect = value;
+			}
+		}
+
+		private int _asyncTimeout = 45000;
+
+		/// <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
+		{
+			set
+			{
+				_asyncTimeout = value;
+			}
+		}
+
 		private bool doConnect()
 		{
-			Exception failure = null;
 			try
 			{
 				reconnectMutex.WaitOne();
@@ -786,7 +832,7 @@
 					List<Uri> connectList = ConnectList;
 					if(connectList.Count == 0)
 					{
-						failure = new NMSConnectionException("No URIs available for connection.");
+						Failure = new NMSConnectionException("No URIs available for connection.");
 					}
 					else
 					{
@@ -794,6 +840,7 @@
 						{
 							ReconnectDelay = InitialReconnectDelay;
 						}
+
 						try
 						{
 							backupMutex.WaitOne();
@@ -817,11 +864,11 @@
 									ConnectedTransport = t;
 									connectFailures = 0;
 									connected = true;
-                                    if( this.Resumed != null )
-                                    {
-                                        this.Resumed( t );
-                                    }
-                                    Tracer.InfoFormat("Successfully reconnected to backup
{0}", uri.ToString());
+									if(this.Resumed != null)
+									{
+										this.Resumed(t);
+									}
+									Tracer.InfoFormat("Successfully reconnected to backup {0}", uri.ToString());
 									return false;
 								}
 								catch(Exception e)
@@ -836,65 +883,128 @@
 							backupMutex.ReleaseMutex();
 						}
 
-						foreach(Uri uri in connectList)
+						ManualResetEvent allDone = new ManualResetEvent(false);
+						ITransport transport = null;
+						Uri chosenUri = null;
+						object syncLock = new object();
+
+						try
 						{
-							if(ConnectedTransport != null || disposed)
+							foreach(Uri uri in connectList)
 							{
-								break;
+								if(ConnectedTransport != null || disposed)
+								{
+									break;
+								}
+
+								Tracer.DebugFormat("Attempting connect to: {0}", uri);
+
+								if(_asyncConnect)
+								{
+									// set connector up
+									Connector connector = new Connector(
+										delegate(ITransport transportToUse, Uri uriToUse) {
+											if(transport == null)
+											{
+												lock(syncLock)
+												{
+													if(transport == null)
+													{
+														//the transport has not yet been set asynchronously so set it
+														transport = transportToUse;
+														chosenUri = uriToUse;
+													}
+													//notify issuing thread to move on
+													allDone.Set();
+												}
+											}
+										}, uri, this);
+
+									// initiate a thread to try connecting to broker
+									Thread thread = new Thread(connector.DoConnect);
+									thread.Name = uri.ToString();
+									thread.Start();
+								}
+								else
+								{
+									// synchronous connect
+									try
+									{
+										Tracer.DebugFormat("Attempting connect to: {0}", uri.ToString());
+										transport = TransportFactory.CompositeConnect(uri);
+										chosenUri = uri;
+										break;
+									}
+									catch(Exception e)
+									{
+										Failure = e;
+										Tracer.DebugFormat("Connect fail to: {0}, reason: {1}", uri, e.Message);
+									}
+								}
 							}
 
-							try
+							if(_asyncConnect)
 							{
-								Tracer.DebugFormat("Attempting connect to: {0}", uri.ToString());
-								ITransport t = TransportFactory.CompositeConnect(uri);
-								t.Command = new CommandHandler(onCommand);
-								t.Exception = new ExceptionHandler(onException);
-								t.Start();
+								// now wait for transport to be populated, but timeout eventually
+								allDone.WaitOne(_asyncTimeout, false);
+							}
+
+							if(transport != null)
+							{
+								transport.Command = new CommandHandler(onCommand);
+								transport.Exception = new ExceptionHandler(onException);
+								transport.Start();
 
 								if(started)
 								{
-									restoreTransport(t);
+									restoreTransport(transport);
+								}
+
+								if(this.Resumed != null)
+								{
+									this.Resumed(transport);
 								}
 
-                                if( this.Resumed != null )
-                                {
-                                    this.Resumed( t );
-                                }
-                                
 								Tracer.Debug("Connection established");
 								ReconnectDelay = InitialReconnectDelay;
-								ConnectedTransportURI = uri;
-								ConnectedTransport = t;
+								ConnectedTransportURI = chosenUri;
+								ConnectedTransport = transport;
 								connectFailures = 0;
 								connected = true;
 
 								if(firstConnection)
 								{
 									firstConnection = false;
-									Tracer.InfoFormat("Successfully connected to: {0}", uri.ToString());
+									Tracer.InfoFormat("Successfully connected to: {0}", chosenUri.ToString());
 								}
 								else
 								{
-									Tracer.InfoFormat("Successfully reconnected to: {0}", uri.ToString());
+									Tracer.InfoFormat("Successfully reconnected to: {0}", chosenUri.ToString());
 								}
 
 								return false;
 							}
-							catch(Exception e)
+
+							if(_asyncConnect)
 							{
-								failure = e;
-								Tracer.ErrorFormat("Connect fail to '{0}': {1}", uri.ToString(), e.Message);
+								Tracer.DebugFormat("Connect failed after waiting for asynchronous callback.");
 							}
+
+						}
+						catch(Exception e)
+						{
+							Failure = e;
+							Tracer.DebugFormat("Connect attempt failed.  Reason: {1}", e.Message);
 						}
 					}
-				}
 
-				if(MaxReconnectAttempts > 0 && ++connectFailures >= MaxReconnectAttempts)
-				{
-					Tracer.ErrorFormat("Failed to connect to transport after {0} attempt(s)", connectFailures);
-					connectionFailure = failure;
-					this.Exception(this, connectionFailure);
-					return false;
+					if(MaxReconnectAttempts > 0 && ++connectFailures >= MaxReconnectAttempts)
+					{
+						Tracer.ErrorFormat("Failed to connect to transport after {0} attempt(s)", connectFailures);
+						connectionFailure = Failure;
+						this.Exception(this, connectionFailure);
+						return false;
+					}
 				}
 			}
 			finally
@@ -934,6 +1044,57 @@
 			return !disposed;
 		}
 
+		/// <summary>
+		/// This class is a helper for the asynchronous connect option
+		/// </summary>
+		public class Connector
+		{
+			/// <summary>
+			/// callback to properly set chosen transport
+			/// </summary>
+			SetTransport _setTransport;
+
+			/// <summary>
+			/// Uri to try connecting to
+			/// </summary>
+			Uri _uri;
+
+			/// <summary>
+			/// Failover transport issuing the connection attempt
+			/// </summary>
+			private FailoverTransport _transport;
+
+			/// <summary>
+			/// Initializes a new instance of the <see cref="Connector"/> class.
+			/// </summary>
+			/// <param name="setTransport">The set transport.</param>
+			/// <param name="uri">The URI.</param>
+			/// <param name="transport">The transport.</param>
+			public Connector(SetTransport setTransport, Uri uri, FailoverTransport transport)
+			{
+				_uri = uri;
+				_setTransport = setTransport;
+				_transport = transport;
+			}
+
+			/// <summary>
+			/// Does the connect.
+			/// </summary>
+			public void DoConnect()
+			{
+				try
+				{
+					TransportFactory.AsyncCompositeConnect(_uri, _setTransport);
+				}
+				catch(Exception e)
+				{
+					_transport.Failure = e;
+					Tracer.DebugFormat("Connect fail to: {0}, reason: {1}", _uri, e.Message);
+				}
+
+			}
+		}
+
 		private bool buildBackups()
 		{
 			try
@@ -989,6 +1150,7 @@
 			return false;
 		}
 
+
 		public bool IsDisposed
 		{
 			get { return disposed; }
@@ -1036,13 +1198,13 @@
 			get { return interruptedHandler; }
 			set { this.interruptedHandler = value; }
 		}
-		
+
 		public ResumedHandler Resumed
 		{
 			get { return resumedHandler; }
 			set { this.resumedHandler = value; }
 		}
-		
+
 		public bool IsStarted
 		{
 			get { return started; }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -36,6 +36,11 @@
 			return CreateTransport(URISupport.parseComposite(location));
 		}
 
+		public ITransport CompositeConnect(Uri location, SetTransport setTransport)
+		{
+			throw new NMSConnectionException("Asynchronous composite connection not supported with
Failover transport.");
+		}
+
 		public ITransport CreateTransport(Uri location)
 		{
 			return doConnect(location);

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/ITransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -19,9 +19,12 @@
 
 namespace Apache.NMS.ActiveMQ.Transport
 {
+	public delegate void SetTransport(ITransport transport, Uri uri);
+
 	public interface ITransportFactory
 	{
 		ITransport CreateTransport(Uri location);
 		ITransport CompositeConnect(Uri location);
+		ITransport CompositeConnect(Uri location, SetTransport setTransport);
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/MockTransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -16,11 +16,8 @@
  */
 
 using System;
-using System.Collections.Generic;
 using System.Collections.Specialized;
 using Apache.NMS.Util;
-using Apache.NMS.ActiveMQ.Commands;
-using Apache.NMS.ActiveMQ.Transport;
 
 namespace Apache.NMS.ActiveMQ.Transport.Mock
 {
@@ -28,72 +25,72 @@
 	/// Factory class to create the MockTransport when given on a URI as mock://XXX
 	/// </summary>
 	public class MockTransportFactory : ITransportFactory
-	{		
+	{
 		public MockTransportFactory()
 		{
 		}
 
-        #region Properties
-        
-        private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
-        public int RequestTimeout
-        {
-            get { return (int) requestTimeout.TotalMilliseconds; }
-            set { requestTimeout = TimeSpan.FromMilliseconds(value); }
-        }
-        
-        private bool useLogging = false;
-        public bool UseLogging
-        {
-            get { return useLogging; }
-            set { useLogging = value; }
-        }
-
-        private string wireFormat = "OpenWire";
-        public string WireFormat
-        {
-            get { return wireFormat; }
-            set { wireFormat = value; }
-        }
-        
-        private bool failOnReceiveMessage = false;
-        public bool FailOnReceiveMessage
-        {
-            get { return failOnReceiveMessage; }
-            set { failOnReceiveMessage = value; }
-        }
-
-        private int numReceivedMessagesBeforeFail = 0;
-        public int NumReceivedMessagesBeforeFail
-        {
-            get { return numReceivedMessagesBeforeFail; }
-            set { numReceivedMessagesBeforeFail = value; }           
-        }
-        
-        private bool failOnSendMessage = false;
-        public bool FailOnSendMessage
-        {
-            get{ return failOnSendMessage; }
-            set{ this.failOnSendMessage = value; }          
-        }
-        
-        private int numSentMessagesBeforeFail = 0;
-        public int NumSentMessagesBeforeFail
-        {
-            get { return numSentMessagesBeforeFail ; }
-            set { numSentMessagesBeforeFail = value; }
-        }
-
-        private bool failOnCreate = false;
-        public bool FailOnCreate
-        {
-            get{ return failOnCreate; }
-            set{ this.failOnCreate = value; }          
-        }
-        
-        #endregion
-        
-		public ITransport CreateTransport(Uri location) 
+		#region Properties
+
+		private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
+		public int RequestTimeout
+		{
+			get { return (int) requestTimeout.TotalMilliseconds; }
+			set { requestTimeout = TimeSpan.FromMilliseconds(value); }
+		}
+
+		private bool useLogging = false;
+		public bool UseLogging
+		{
+			get { return useLogging; }
+			set { useLogging = value; }
+		}
+
+		private string wireFormat = "OpenWire";
+		public string WireFormat
+		{
+			get { return wireFormat; }
+			set { wireFormat = value; }
+		}
+
+		private bool failOnReceiveMessage = false;
+		public bool FailOnReceiveMessage
+		{
+			get { return failOnReceiveMessage; }
+			set { failOnReceiveMessage = value; }
+		}
+
+		private int numReceivedMessagesBeforeFail = 0;
+		public int NumReceivedMessagesBeforeFail
+		{
+			get { return numReceivedMessagesBeforeFail; }
+			set { numReceivedMessagesBeforeFail = value; }
+		}
+
+		private bool failOnSendMessage = false;
+		public bool FailOnSendMessage
+		{
+			get { return failOnSendMessage; }
+			set { this.failOnSendMessage = value; }
+		}
+
+		private int numSentMessagesBeforeFail = 0;
+		public int NumSentMessagesBeforeFail
+		{
+			get { return numSentMessagesBeforeFail; }
+			set { numSentMessagesBeforeFail = value; }
+		}
+
+		private bool failOnCreate = false;
+		public bool FailOnCreate
+		{
+			get { return failOnCreate; }
+			set { this.failOnCreate = value; }
+		}
+
+		#endregion
+
+		public ITransport CreateTransport(Uri location)
 		{
 			ITransport transport = CompositeConnect(location);
 
@@ -101,40 +98,44 @@
 			transport = new ResponseCorrelator(transport);
 			transport.RequestTimeout = this.requestTimeout;
 
-			return transport;			
+			return transport;
 		}
-		
+
 		public ITransport CompositeConnect(Uri location)
 		{
-            Tracer.Debug("MockTransportFactory: Create new Transport with options: " + location.Query);
-            
+			Tracer.Debug("MockTransportFactory: Create new Transport with options: " + location.Query);
+
 			// Extract query parameters from broker Uri
 			StringDictionary map = URISupport.ParseQuery(location.Query);
 
-            // Set transport. properties on this (the factory)
-            URISupport.SetProperties(this, map, "transport.");
-         
-            if(String.Compare(this.wireFormat, "stomp", true) != 0 &&
-               String.Compare(this.wireFormat, "openwire", true) != 0)
-            {
-                throw new IOException("Unsupported WireFormat Supplied for MockTransport");
-            }
-
-            if(this.FailOnCreate == true)
-            {
-                throw new IOException("Failed to Create new MockTransport.");
-            }                
-            
-            // Create the Mock Transport
-            MockTransport transport = new MockTransport();
-            
-            transport.FailOnReceiveMessage = this.FailOnReceiveMessage;
-            transport.NumReceivedMessagesBeforeFail = this.NumReceivedMessagesBeforeFail;
-            transport.FailOnSendMessage = this.FailOnSendMessage;
-            transport.NumSentMessagesBeforeFail = this.NumSentMessagesBeforeFail;
+			// Set transport. properties on this (the factory)
+			URISupport.SetProperties(this, map, "transport.");
 
-            return transport;
+			if(String.Compare(this.wireFormat, "stomp", true) != 0 &&
+			   String.Compare(this.wireFormat, "openwire", true) != 0)
+			{
+				throw new IOException("Unsupported WireFormat Supplied for MockTransport");
+			}
+
+			if(this.FailOnCreate == true)
+			{
+				throw new IOException("Failed to Create new MockTransport.");
+			}
+
+			// Create the Mock Transport
+			MockTransport transport = new MockTransport();
+
+			transport.FailOnReceiveMessage = this.FailOnReceiveMessage;
+			transport.NumReceivedMessagesBeforeFail = this.NumReceivedMessagesBeforeFail;
+			transport.FailOnSendMessage = this.FailOnSendMessage;
+			transport.NumSentMessagesBeforeFail = this.NumSentMessagesBeforeFail;
+
+			return transport;
+		}
+
+		public ITransport CompositeConnect(Uri location, SetTransport setTransport)
+		{
+			throw new NMSConnectionException("Asynchronous composite connection not supported with
Mock transport.");
 		}
-		
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -16,7 +16,6 @@
  */
 
 using System;
-using System.Collections.Generic;
 using System.Collections.Specialized;
 using System.Net;
 using System.Net.Sockets;
@@ -104,6 +103,11 @@
 
 		public ITransport CompositeConnect(Uri location)
 		{
+			return CompositeConnect(location, null);
+		}
+
+		public ITransport CompositeConnect(Uri location, SetTransport setTransport)
+		{
 			// Extract query parameters from broker Uri
 			StringDictionary map = URISupport.ParseQuery(location.Query);
 
@@ -137,6 +141,11 @@
 
 			transport.RequestTimeout = this.requestTimeout;
 
+			if(setTransport != null)
+			{
+				setTransport(transport, location);
+			}
+
 			return transport;
 		}
 
@@ -160,6 +169,7 @@
 		// the new hostname IP.
 #if CACHE_HOSTENTRIES
 		private static IDictionary<string, IPHostEntry> CachedIPHostEntries = new Dictionary<string,
IPHostEntry>();
+		private static readonly object _syncLock = new object();
 #endif
 		public static IPHostEntry GetIPHostEntry(string host)
 		{
@@ -168,16 +178,19 @@
 #if CACHE_HOSTENTRIES
 			string hostUpperName = host.ToUpper();
 
-			if(!CachedIPHostEntries.TryGetValue(hostUpperName, out ipEntry))
+			lock (_syncLock)
 			{
-				try
+				if (!CachedIPHostEntries.TryGetValue(hostUpperName, out ipEntry))
 				{
-					ipEntry = Dns.GetHostEntry(hostUpperName);
-					CachedIPHostEntries.Add(hostUpperName, ipEntry);
-				}
-				catch
-				{
-					ipEntry = null;
+					try
+					{
+						ipEntry = Dns.GetHostEntry(hostUpperName);
+						CachedIPHostEntries.Add(hostUpperName, ipEntry);
+					}
+					catch
+					{
+						ipEntry = null;
+					}
 				}
 			}
 #else

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFactory.cs?rev=807840&r1=807839&r2=807840&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFactory.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/TransportFactory.cs
Tue Aug 25 22:27:29 2009
@@ -16,12 +16,10 @@
  */
 
 using System;
-using System.Collections.Generic;
-
 using Apache.NMS.ActiveMQ.Transport.Discovery;
 using Apache.NMS.ActiveMQ.Transport.Failover;
-using Apache.NMS.ActiveMQ.Transport.Tcp;
 using Apache.NMS.ActiveMQ.Transport.Mock;
+using Apache.NMS.ActiveMQ.Transport.Tcp;
 
 namespace Apache.NMS.ActiveMQ.Transport
 {
@@ -54,6 +52,12 @@
 			return tf.CompositeConnect(location);
 		}
 
+		public static ITransport AsyncCompositeConnect(Uri location, SetTransport setTransport)
+		{
+			ITransportFactory tf = TransportFactory.CreateTransportFactory(location);
+			return tf.CompositeConnect(location, setTransport);
+		}
+
 		/// <summary>
 		/// Create a transport factory for the scheme.  If we do not support the transport protocol,
 		/// an NMSConnectionException will be thrown.
@@ -75,20 +79,20 @@
 			{
 				switch(scheme.ToLower())
 				{
-					case "tcp":
-						factory = new TcpTransportFactory();
-						break;
-					case "discovery":
-						factory = new DiscoveryTransportFactory();
-						break;
-					case "failover":
-						factory = new FailoverTransportFactory();
-						break;
-					case "mock":
-						factory = new MockTransportFactory();
-						break;
-				    default:
-						throw new NMSConnectionException(String.Format("The transport {0} is not supported.",
scheme));
+				case "tcp":
+					factory = new TcpTransportFactory();
+					break;
+				case "discovery":
+					factory = new DiscoveryTransportFactory();
+					break;
+				case "failover":
+					factory = new FailoverTransportFactory();
+					break;
+				case "mock":
+					factory = new MockTransportFactory();
+					break;
+				default:
+					throw new NMSConnectionException(String.Format("The transport {0} is not supported.",
scheme));
 				}
 			}
 			catch(NMSConnectionException)



Mime
View raw message