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 2009/04/01 00:34:42 UTC
svn commit: r760698 - in
/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport:
Failover/FailoverTransport.cs Tcp/TcpTransportFactory.cs
Author: jgomes
Date: Tue Mar 31 22:34:41 2009
New Revision: 760698
URL: http://svn.apache.org/viewvc?rev=760698&view=rev
Log:
Added IP optimizations to avoid DNS look up if a raw IP address is specified for the connection host. This will support both IPv4 and IPv6 addresses.
Fixed several Tracer debug messages to include the exception error message.
Fixes [AMQNET-155]. (See https://issues.apache.org/activemq/browse/AMQNET-155)
Modified:
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/Tcp/TcpTransportFactory.cs
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=760698&r1=760697&r2=760698&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 Mar 31 22:34:41 2009
@@ -237,8 +237,7 @@
bool reconnectOk = false;
if(started)
{
- Tracer.Warn("Transport failed to " + ConnectedTransportURI + " , attempting to automatically reconnect due to: " + e.Message);
- Tracer.Debug("Transport failed with the following exception:" + e.Message);
+ Tracer.WarnFormat("Transport failed to {0}, attempting to automatically reconnect due to: {1}", ConnectedTransportURI, e.Message);
reconnectOk = true;
}
@@ -462,7 +461,7 @@
}
catch(ThreadInterruptedException e)
{
- Tracer.Debug("Interupted: " + e);
+ Tracer.DebugFormat("Interupted: {0}", e.Message);
}
}
finally
@@ -544,7 +543,7 @@
}
catch(Exception e)
{
- Tracer.Debug("Send Oneway attempt: " + i + " failed.");
+ Tracer.DebugFormat("Send Oneway attempt: {0} failed.", i);
handleTransportFailure(e);
}
}
@@ -625,7 +624,7 @@
}
catch(Exception e)
{
- Tracer.Error("Failed to parse URI: " + u + " because " + e.Message);
+ Tracer.ErrorFormat("Failed to parse URI: {0} because {1}", u, e.Message);
}
}
@@ -796,7 +795,7 @@
ConnectedTransportURI = uri;
ConnectedTransport = t;
connectFailures = 0;
- Tracer.Info("Successfully reconnected to backup " + uri);
+ Tracer.InfoFormat("Successfully reconnected to backup {0}", uri);
return false;
}
catch(Exception e)
@@ -820,7 +819,7 @@
try
{
- Tracer.Debug("Attempting connect to: " + uri);
+ Tracer.DebugFormat("Attempting connect to: {0}", uri);
ITransport t = TransportFactory.CompositeConnect(uri);
t.Command = new CommandHandler(onCommand);
t.Exception = new ExceptionHandler(onException);
@@ -840,11 +839,11 @@
if(firstConnection)
{
firstConnection = false;
- Tracer.Info("Successfully connected to " + uri);
+ Tracer.InfoFormat("Successfully connected to: {0}", uri);
}
else
{
- Tracer.Info("Successfully reconnected to " + uri);
+ Tracer.InfoFormat("Successfully reconnected to: {0}", uri);
}
connected = true;
@@ -853,7 +852,7 @@
catch(Exception e)
{
failure = e;
- Tracer.Debug("Connect fail to: " + uri + ", reason: " + e);
+ Tracer.DebugFormat("Connect fail to: (0}, reason: {1}", uri, e.Message);
}
}
}
@@ -861,7 +860,7 @@
if(MaxReconnectAttempts > 0 && ++connectFailures >= MaxReconnectAttempts)
{
- Tracer.Error("Failed to connect to transport after: " + connectFailures + " attempt(s)");
+ Tracer.ErrorFormat("Failed to connect to transport after: {0} attempt(s)", connectFailures);
connectionFailure = failure;
onException(this, connectionFailure);
return false;
@@ -875,7 +874,7 @@
if(!disposed)
{
- Tracer.Debug("Waiting " + ReconnectDelay + " ms before attempting connection. ");
+ Tracer.DebugFormat("Waiting {0}ms before attempting connection.", ReconnectDelay);
try
{
sleepMutex.WaitOne();
@@ -942,8 +941,7 @@
}
catch(Exception e)
{
- e.GetType();
- Tracer.Debug("Failed to build backup ");
+ Tracer.DebugFormat("Failed to build backup: {0}", e.Message);
}
}
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=760698&r1=760697&r2=760698&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 Mar 31 22:34:41 2009
@@ -16,6 +16,7 @@
*/
using System;
+using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Net.Sockets;
@@ -152,22 +153,99 @@
#endregion
- protected Socket Connect(string host, int port)
+ private static IDictionary<string, IPHostEntry> CachedIPHostEntries = new Dictionary<string, IPHostEntry>();
+ public static IPHostEntry GetIPHostEntry(string host)
{
- // Looping through the AddressList allows different type of connections to be tried
- // (IPv4, IPv6 and whatever else may be available).
- IPHostEntry hostEntry = Dns.GetHostEntry(host);
+ IPHostEntry ipEntry;
+ string hostUpperName = host.ToUpper();
- foreach(IPAddress address in hostEntry.AddressList)
+ if(!CachedIPHostEntries.TryGetValue(hostUpperName, out ipEntry))
+ {
+ try
+ {
+ ipEntry = Dns.GetHostEntry(hostUpperName);
+ CachedIPHostEntries.Add(hostUpperName, ipEntry);
+ }
+ catch
+ {
+ ipEntry = null;
+ }
+ }
+
+ return ipEntry;
+ }
+
+ private Socket ConnectSocket(IPAddress address, int port)
+ {
+ try
{
Socket socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
- socket.Connect(new IPEndPoint(address, port));
- if(socket.Connected)
+
+ if(null != socket)
+ {
+ socket.Connect(new IPEndPoint(address, port));
+ if(socket.Connected)
+ {
+ return socket;
+ }
+ }
+ }
+ catch
+ {
+ }
+
+ return null;
+ }
+
+ private static bool TryParseIPAddress(string host, out IPAddress ipaddress)
+ {
+#if !NETCF
+ return IPAddress.TryParse(host, out ipaddress);
+#else
+ try
+ {
+ ipaddress = IPAddress.Parse(host);
+ }
+ catch
+ {
+ ipaddress = null;
+ }
+
+ return (null != ipaddress);
+#endif
+ }
+
+ protected Socket Connect(string host, int port)
+ {
+ Socket socket = null;
+ IPAddress ipaddress;
+
+ if(TryParseIPAddress(host, out ipaddress))
+ {
+ socket = ConnectSocket(ipaddress, port);
+ }
+ else
+ {
+ // Looping through the AddressList allows different type of connections to be tried
+ // (IPv4, IPv6 and whatever else may be available).
+ IPHostEntry hostEntry = GetIPHostEntry(host);
+
+ foreach(IPAddress address in hostEntry.AddressList)
{
- return socket;
+ socket = ConnectSocket(address, port);
+ if(null != socket)
+ {
+ break;
+ }
}
}
- throw new SocketException();
+
+ if(null == socket)
+ {
+ throw new SocketException();
+ }
+
+ return socket;
}
protected IWireFormat CreateWireFormat(Uri location, StringDictionary map)