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 2010/02/22 19:25:31 UTC
svn commit: r915006 - in /activemq/activemq-dotnet:
Apache.NMS.ActiveMQ/trunk/
Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/
Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/
Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Mock/ Apache.NMS...
Author: jgomes
Date: Mon Feb 22 18:25:31 2010
New Revision: 915006
URL: http://svn.apache.org/viewvc?rev=915006&view=rev
Log:
Remove Stomp wire format from NMS.ActiveMQ. The Stomp format is now supported by the stand-alone provider NMS.Stomp.
Fixes [AMQNET-238]. (See https://issues.apache.org/activemq/browse/AMQNET-238)
Removed:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Stomp/
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/StompHelperTest.cs
Modified:
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.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/WireFormatNegotiator.cs
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs?rev=915006&r1=915005&r2=915006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs Mon Feb 22 18:25:31 2010
@@ -45,22 +45,22 @@
private int cacheSize = 0;
private int minimumVersion = 1;
- private WireFormatInfo preferedWireFormatInfo = new WireFormatInfo();
+ private WireFormatInfo preferredWireFormatInfo = new WireFormatInfo();
private ITransport transport;
public OpenWireFormat()
{
// See the following link for defaults: http://activemq.apache.org/configuring-wire-formats.html
// See also the following link for OpenWire format info: http://activemq.apache.org/openwire-version-2-specification.html
- PreferedWireFormatInfo.CacheEnabled = false;
- PreferedWireFormatInfo.StackTraceEnabled = false;
- PreferedWireFormatInfo.TcpNoDelayEnabled = true;
- PreferedWireFormatInfo.SizePrefixDisabled = false;
- PreferedWireFormatInfo.TightEncodingEnabled = false;
- PreferedWireFormatInfo.MaxInactivityDuration = 30000;
- PreferedWireFormatInfo.MaxInactivityDurationInitialDelay = 10000;
- PreferedWireFormatInfo.CacheSize = 0;
- PreferedWireFormatInfo.Version = 5;
+ PreferredWireFormatInfo.CacheEnabled = false;
+ PreferredWireFormatInfo.StackTraceEnabled = false;
+ PreferredWireFormatInfo.TcpNoDelayEnabled = true;
+ PreferredWireFormatInfo.SizePrefixDisabled = false;
+ PreferredWireFormatInfo.TightEncodingEnabled = false;
+ PreferredWireFormatInfo.MaxInactivityDuration = 30000;
+ PreferredWireFormatInfo.MaxInactivityDurationInitialDelay = 10000;
+ PreferredWireFormatInfo.CacheSize = 0;
+ PreferredWireFormatInfo.Version = 5;
dataMarshallers = new BaseDataStreamMarshaller[256];
Version = 1;
@@ -133,10 +133,10 @@
set { cacheSize = value; }
}
- public WireFormatInfo PreferedWireFormatInfo
+ public WireFormatInfo PreferredWireFormatInfo
{
- get { return preferedWireFormatInfo; }
- set { preferedWireFormatInfo = value; }
+ get { return preferredWireFormatInfo; }
+ set { preferredWireFormatInfo = value; }
}
public void clearMarshallers()
@@ -431,12 +431,12 @@
throw new IOException("Remote wire format (" + info.Version + ") is lower than the minimum version required (" + minimumVersion + ")");
}
- this.Version = Math.Min(PreferedWireFormatInfo.Version, info.Version);
- this.cacheEnabled = info.CacheEnabled && PreferedWireFormatInfo.CacheEnabled;
- this.stackTraceEnabled = info.StackTraceEnabled && PreferedWireFormatInfo.StackTraceEnabled;
- this.tcpNoDelayEnabled = info.TcpNoDelayEnabled && PreferedWireFormatInfo.TcpNoDelayEnabled;
- this.sizePrefixDisabled = info.SizePrefixDisabled && PreferedWireFormatInfo.SizePrefixDisabled;
- this.tightEncodingEnabled = info.TightEncodingEnabled && PreferedWireFormatInfo.TightEncodingEnabled;
+ this.Version = Math.Min(PreferredWireFormatInfo.Version, info.Version);
+ this.cacheEnabled = info.CacheEnabled && PreferredWireFormatInfo.CacheEnabled;
+ this.stackTraceEnabled = info.StackTraceEnabled && PreferredWireFormatInfo.StackTraceEnabled;
+ this.tcpNoDelayEnabled = info.TcpNoDelayEnabled && PreferredWireFormatInfo.TcpNoDelayEnabled;
+ this.sizePrefixDisabled = info.SizePrefixDisabled && PreferredWireFormatInfo.SizePrefixDisabled;
+ this.tightEncodingEnabled = info.TightEncodingEnabled && PreferredWireFormatInfo.TightEncodingEnabled;
this.maxInactivityDuration = info.MaxInactivityDuration;
this.maxInactivityDurationInitialDelay = info.MaxInactivityDurationInitialDelay;
this.cacheSize = info.CacheSize;
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=915006&r1=915005&r2=915006&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 Mon Feb 22 18:25:31 2010
@@ -46,13 +46,6 @@
set { useLogging = value; }
}
- private string wireFormat = "OpenWire";
- public string WireFormat
- {
- get { return wireFormat; }
- set { wireFormat = value; }
- }
-
private bool failOnReceiveMessage = false;
public bool FailOnReceiveMessage
{
@@ -111,12 +104,6 @@
// 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.");
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=915006&r1=915005&r2=915006&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 Mon Feb 22 18:25:31 2010
@@ -20,7 +20,6 @@
using System.Net;
using System.Net.Sockets;
using Apache.NMS.ActiveMQ.OpenWire;
-using Apache.NMS.ActiveMQ.Transport.Stomp;
using Apache.NMS.Util;
namespace Apache.NMS.ActiveMQ.Transport.Tcp
@@ -93,13 +92,6 @@
set { sendTimeout = value; }
}
- private string wireFormat = "OpenWire";
- public string WireFormat
- {
- get { return wireFormat; }
- set { wireFormat = value; }
- }
-
private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
public int RequestTimeout
{
@@ -134,7 +126,9 @@
socket.SendTimeout = SendTimeout;
#endif
- IWireFormat wireformat = CreateWireFormat(map);
+ OpenWireFormat wireformat = new OpenWireFormat();
+ // Set wireformat. properties on the wireformat owned by the tcpTransport
+ URISupport.SetProperties(wireformat.PreferredWireFormatInfo, map, "wireFormat.");
ITransport transport = new TcpTransport(location, socket, wireformat);
wireformat.Transport = transport;
@@ -149,13 +143,8 @@
transport = new InactivityMonitor(transport);
}
- if(wireformat is OpenWireFormat)
- {
- transport = new WireFormatNegotiator(transport, (OpenWireFormat) wireformat);
- }
-
+ transport = new WireFormatNegotiator(transport, wireformat);
transport.RequestTimeout = this.requestTimeout;
-
if(setTransport != null)
{
setTransport(transport, location);
@@ -358,32 +347,5 @@
Tracer.DebugFormat("Connected to {0}:{1} using {2} protocol.", host, port, ipaddress.AddressFamily.ToString());
return socket;
}
-
- protected IWireFormat CreateWireFormat(StringDictionary map)
- {
- object properties = null;
- IWireFormat wireFormatItf = null;
-
- if(String.Compare(this.wireFormat, "stomp", true) == 0)
- {
- wireFormatItf = new StompWireFormat();
- properties = wireFormatItf;
- }
- else
- {
- OpenWireFormat openwireFormat = new OpenWireFormat();
-
- wireFormatItf = openwireFormat;
- properties = openwireFormat.PreferedWireFormatInfo;
- }
-
- if(null != properties)
- {
- // Set wireformat. properties on the wireformat owned by the tcpTransport
- URISupport.SetProperties(properties, map, "wireFormat.");
- }
-
- return wireFormatItf;
- }
}
}
Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/WireFormatNegotiator.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/WireFormatNegotiator.cs?rev=915006&r1=915005&r2=915006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/WireFormatNegotiator.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/WireFormatNegotiator.cs Mon Feb 22 18:25:31 2010
@@ -46,7 +46,7 @@
{
try
{
- next.Oneway(wireFormat.PreferedWireFormatInfo);
+ next.Oneway(wireFormat.PreferredWireFormatInfo);
}
finally
{
Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj?rev=915006&r1=915005&r2=915006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj Mon Feb 22 18:25:31 2010
@@ -85,7 +85,6 @@
<Compile Include="src\test\csharp\OpenWire\MaxInactivityDurationTest.cs" />
<Compile Include="src\test\csharp\OpenWire\PrefetchSizeZeroTest.cs" />
<Compile Include="src\test\csharp\RollbackRedeliveryTest.cs" />
- <Compile Include="src\test\csharp\StompHelperTest.cs" />
<Compile Include="src\test\csharp\Threads\CompositeTaskRunnerTest.cs" />
<Compile Include="src\test\csharp\Threads\DedicatedTaskRunnerTest.cs" />
<Compile Include="src\test\csharp\Transport\failover\FailoverTransportTest.cs" />
Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj?rev=915006&r1=915005&r2=915006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq.csproj Mon Feb 22 18:25:31 2010
@@ -921,9 +921,6 @@
<Compile Include="src\main\csharp\Transport\ResponseCorrelator.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="src\main\csharp\Transport\Stomp\StompFrameStream.cs" />
- <Compile Include="src\main\csharp\Transport\Stomp\StompHelper.cs" />
- <Compile Include="src\main\csharp\Transport\Stomp\StompWireFormat.cs" />
<Compile Include="src\main\csharp\Transport\Tcp\TcpTransport.cs">
<SubType>Code</SubType>
</Compile>
Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs?rev=915006&r1=915005&r2=915006&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Tcp/TcpTransportFactory.cs Mon Feb 22 18:25:31 2010
@@ -19,341 +19,318 @@
using System.Collections.Specialized;
using System.Net;
using System.Net.Sockets;
-using Apache.NMS.Stomp.Transport;
using Apache.NMS.Stomp.Protocol;
using Apache.NMS.Util;
namespace Apache.NMS.Stomp.Transport.Tcp
{
- public class TcpTransportFactory : ITransportFactory
- {
- public TcpTransportFactory()
- {
- }
-
- #region Properties
-
- private bool useLogging = false;
- public bool UseLogging
- {
- get { return useLogging; }
- set { useLogging = value; }
- }
-
- /// <summary>
- /// Size in bytes of the receive buffer.
- /// </summary>
- private int receiveBufferSize = 8192;
- public int ReceiveBufferSize
- {
- get { return receiveBufferSize; }
- set { receiveBufferSize = value; }
- }
-
- /// <summary>
- /// Size in bytes of send buffer.
- /// </summary>
- private int sendBufferSize = 8192;
- public int SendBufferSize
- {
- get { return sendBufferSize; }
- set { sendBufferSize = value; }
- }
-
- /// <summary>
- /// The time-out value, in milliseconds. The default value is 0, which indicates
- /// an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
- /// </summary>
- private int receiveTimeout = 0;
- public int ReceiveTimeout
- {
- get { return receiveTimeout; }
- set { receiveTimeout = value; }
- }
-
- /// <summary>
- /// The time-out value, in milliseconds. If you set the property with a value between 1 and 499,
- /// the value will be changed to 500. The default value is 0, which indicates an infinite
- /// time-out period. Specifying -1 also indicates an infinite time-out period.
- /// </summary>
- private int sendTimeout = 0;
- public int SendTimeout
- {
- get { return sendTimeout; }
- set { sendTimeout = value; }
- }
-
- private string wireFormat = "Stomp";
- public string WireFormat
- {
- get { return wireFormat; }
- set { wireFormat = value; }
- }
-
- private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
- public int RequestTimeout
- {
- get { return (int) requestTimeout.TotalMilliseconds; }
- set { requestTimeout = TimeSpan.FromMilliseconds(value); }
- }
-
- #endregion
-
- #region ITransportFactory Members
-
- 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);
+ public class TcpTransportFactory : ITransportFactory
+ {
+ public TcpTransportFactory()
+ {
+ }
+
+ #region Properties
+
+ private bool useLogging = false;
+ public bool UseLogging
+ {
+ get { return useLogging; }
+ set { useLogging = value; }
+ }
+
+ /// <summary>
+ /// Size in bytes of the receive buffer.
+ /// </summary>
+ private int receiveBufferSize = 8192;
+ public int ReceiveBufferSize
+ {
+ get { return receiveBufferSize; }
+ set { receiveBufferSize = value; }
+ }
+
+ /// <summary>
+ /// Size in bytes of send buffer.
+ /// </summary>
+ private int sendBufferSize = 8192;
+ public int SendBufferSize
+ {
+ get { return sendBufferSize; }
+ set { sendBufferSize = value; }
+ }
+
+ /// <summary>
+ /// The time-out value, in milliseconds. The default value is 0, which indicates
+ /// an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
+ /// </summary>
+ private int receiveTimeout = 0;
+ public int ReceiveTimeout
+ {
+ get { return receiveTimeout; }
+ set { receiveTimeout = value; }
+ }
+
+ /// <summary>
+ /// The time-out value, in milliseconds. If you set the property with a value between 1 and 499,
+ /// the value will be changed to 500. The default value is 0, which indicates an infinite
+ /// time-out period. Specifying -1 also indicates an infinite time-out period.
+ /// </summary>
+ private int sendTimeout = 0;
+ public int SendTimeout
+ {
+ get { return sendTimeout; }
+ set { sendTimeout = value; }
+ }
+
+ private TimeSpan requestTimeout = NMSConstants.defaultRequestTimeout;
+ public int RequestTimeout
+ {
+ get { return (int) requestTimeout.TotalMilliseconds; }
+ set { requestTimeout = TimeSpan.FromMilliseconds(value); }
+ }
+
+ #endregion
+
+ #region ITransportFactory Members
+
+ 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);
- // Set transport. properties on this (the factory)
- URISupport.SetProperties(this, map, "transport.");
+ // Set transport. properties on this (the factory)
+ URISupport.SetProperties(this, map, "transport.");
- Tracer.Debug("Opening socket to: " + location.Host + " on port: " + location.Port);
- Socket socket = Connect(location.Host, location.Port);
+ Tracer.Debug("Opening socket to: " + location.Host + " on port: " + location.Port);
+ Socket socket = Connect(location.Host, location.Port);
#if !NETCF
- socket.ReceiveBufferSize = ReceiveBufferSize;
- socket.SendBufferSize = SendBufferSize;
- socket.ReceiveTimeout = ReceiveTimeout;
- socket.SendTimeout = SendTimeout;
+ socket.ReceiveBufferSize = ReceiveBufferSize;
+ socket.SendBufferSize = SendBufferSize;
+ socket.ReceiveTimeout = ReceiveTimeout;
+ socket.SendTimeout = SendTimeout;
#endif
- IWireFormat wireformat = CreateWireFormat(map);
- ITransport transport = new TcpTransport(location, socket, wireformat);
-
- wireformat.Transport = transport;
-
- if(UseLogging)
- {
- transport = new LoggingTransport(transport);
- }
-
- transport.RequestTimeout = this.requestTimeout;
-
- if(setTransport != null)
- {
- setTransport(transport, location);
- }
-
- return transport;
- }
-
- public ITransport CreateTransport(Uri location)
- {
- ITransport transport = CompositeConnect(location);
-
- transport = new MutexTransport(transport);
- transport = new ResponseCorrelator(transport);
- transport.RequestTimeout = this.requestTimeout;
-
- return transport;
- }
-
- #endregion
-
- // DISCUSSION: Caching host entries may not be the best strategy when using the
- // failover protocol. The failover protocol needs to be very dynamic when looking
- // up hostnames at runtime. If old hostname->IP mappings are kept around, this may
- // lead to runtime failures that could have been avoided by dynamically looking up
- // the new hostname IP.
+ IWireFormat wireformat = new StompWireFormat();
+ // Set wireformat. properties on the wireformat owned by the tcpTransport
+ URISupport.SetProperties(wireformat, map, "wireFormat.");
+ ITransport transport = new TcpTransport(location, socket, wireformat);
+
+ wireformat.Transport = transport;
+
+ if(UseLogging)
+ {
+ transport = new LoggingTransport(transport);
+ }
+
+ transport.RequestTimeout = this.requestTimeout;
+
+ if(setTransport != null)
+ {
+ setTransport(transport, location);
+ }
+
+ return transport;
+ }
+
+ public ITransport CreateTransport(Uri location)
+ {
+ ITransport transport = CompositeConnect(location);
+
+ transport = new MutexTransport(transport);
+ transport = new ResponseCorrelator(transport);
+ transport.RequestTimeout = this.requestTimeout;
+
+ return transport;
+ }
+
+ #endregion
+
+ // DISCUSSION: Caching host entries may not be the best strategy when using the
+ // failover protocol. The failover protocol needs to be very dynamic when looking
+ // up hostnames at runtime. If old hostname->IP mappings are kept around, this may
+ // lead to runtime failures that could have been avoided by dynamically looking up
+ // the new hostname IP.
#if CACHE_HOSTENTRIES
- private static IDictionary<string, IPHostEntry> CachedIPHostEntries = new Dictionary<string, IPHostEntry>();
- private static readonly object _syncLock = new object();
+ private static IDictionary<string, IPHostEntry> CachedIPHostEntries = new Dictionary<string, IPHostEntry>();
+ private static readonly object _syncLock = new object();
#endif
- public static IPHostEntry GetIPHostEntry(string host)
- {
- IPHostEntry ipEntry;
+ public static IPHostEntry GetIPHostEntry(string host)
+ {
+ IPHostEntry ipEntry;
#if CACHE_HOSTENTRIES
- string hostUpperName = host.ToUpper();
+ string hostUpperName = host.ToUpper();
- lock (_syncLock)
- {
- if (!CachedIPHostEntries.TryGetValue(hostUpperName, out ipEntry))
- {
- try
- {
- ipEntry = Dns.GetHostEntry(hostUpperName);
- CachedIPHostEntries.Add(hostUpperName, ipEntry);
- }
- catch
- {
- ipEntry = null;
- }
- }
- }
+ lock (_syncLock)
+ {
+ if (!CachedIPHostEntries.TryGetValue(hostUpperName, out ipEntry))
+ {
+ try
+ {
+ ipEntry = Dns.GetHostEntry(hostUpperName);
+ CachedIPHostEntries.Add(hostUpperName, ipEntry);
+ }
+ catch
+ {
+ ipEntry = null;
+ }
+ }
+ }
#else
- try
- {
- ipEntry = Dns.GetHostEntry(host);
- }
- catch
- {
- ipEntry = null;
- }
+ try
+ {
+ ipEntry = Dns.GetHostEntry(host);
+ }
+ catch
+ {
+ ipEntry = null;
+ }
#endif
- return ipEntry;
- }
+ return ipEntry;
+ }
- private Socket ConnectSocket(IPAddress address, int port)
- {
- if(null != address)
- {
- try
- {
- Socket socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
-
- if(null != socket)
- {
- socket.Connect(new IPEndPoint(address, port));
- if(socket.Connected)
- {
- return socket;
- }
- }
- }
- catch
- {
- }
- }
+ private Socket ConnectSocket(IPAddress address, int port)
+ {
+ if(null != address)
+ {
+ try
+ {
+ Socket socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+
+ if(null != socket)
+ {
+ socket.Connect(new IPEndPoint(address, port));
+ if(socket.Connected)
+ {
+ return socket;
+ }
+ }
+ }
+ catch
+ {
+ }
+ }
- return null;
- }
+ return null;
+ }
- public static bool TryParseIPAddress(string host, out IPAddress ipaddress)
- {
+ public static bool TryParseIPAddress(string host, out IPAddress ipaddress)
+ {
#if !NETCF
- return IPAddress.TryParse(host, out ipaddress);
+ return IPAddress.TryParse(host, out ipaddress);
#else
- try
- {
- ipaddress = IPAddress.Parse(host);
- }
- catch
- {
- ipaddress = null;
- }
+ try
+ {
+ ipaddress = IPAddress.Parse(host);
+ }
+ catch
+ {
+ ipaddress = null;
+ }
- return (null != ipaddress);
+ return (null != ipaddress);
#endif
- }
+ }
- public static IPAddress GetIPAddress(string hostname, AddressFamily addressFamily)
- {
- IPAddress ipaddress = null;
- IPHostEntry hostEntry = GetIPHostEntry(hostname);
-
- if(null != hostEntry)
- {
- ipaddress = GetIPAddress(hostEntry, addressFamily);
- }
-
- return ipaddress;
- }
-
- public static IPAddress GetIPAddress(IPHostEntry hostEntry, AddressFamily addressFamily)
- {
- if(null != hostEntry)
- {
- foreach(IPAddress address in hostEntry.AddressList)
- {
- if(address.AddressFamily == addressFamily)
- {
- return address;
- }
- }
- }
-
- return null;
- }
-
- protected Socket Connect(string host, int port)
- {
- Socket socket = null;
- IPAddress ipaddress;
-
- try
- {
- if(TryParseIPAddress(host, out ipaddress))
- {
- socket = ConnectSocket(ipaddress, port);
- }
- else
- {
- // Looping through the AddressList allows different type of connections to be tried
- // (IPv6, IPv4 and whatever else may be available).
- IPHostEntry hostEntry = GetIPHostEntry(host);
-
- if(null != hostEntry)
- {
- // Prefer IPv6 first.
- ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetworkV6);
- socket = ConnectSocket(ipaddress, port);
- if(null == socket)
- {
- // Try IPv4 next.
- ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetwork);
- socket = ConnectSocket(ipaddress, port);
- if(null == socket)
- {
- // Try whatever else there is.
- foreach(IPAddress address in hostEntry.AddressList)
- {
- if(AddressFamily.InterNetworkV6 == address.AddressFamily
- || AddressFamily.InterNetwork == address.AddressFamily)
- {
- // Already tried these protocols.
- continue;
- }
-
- socket = ConnectSocket(address, port);
- if(null != socket)
- {
- ipaddress = address;
- break;
- }
- }
- }
- }
- }
- }
-
- if(null == socket)
- {
- throw new SocketException();
- }
- }
- catch(Exception ex)
- {
- throw new NMSConnectionException(String.Format("Error connecting to {0}:{1}.", host, port), ex);
- }
-
- Tracer.DebugFormat("Connected to {0}:{1} using {2} protocol.", host, port, ipaddress.AddressFamily.ToString());
- return socket;
- }
-
- protected IWireFormat CreateWireFormat(StringDictionary map)
- {
- object properties = null;
- IWireFormat wireFormatItf = null;
-
- wireFormatItf = new StompWireFormat();
- properties = wireFormatItf;
-
- if(null != properties)
- {
- // Set wireformat. properties on the wireformat owned by the tcpTransport
- URISupport.SetProperties(properties, map, "wireFormat.");
- }
-
- return wireFormatItf;
- }
- }
+ public static IPAddress GetIPAddress(string hostname, AddressFamily addressFamily)
+ {
+ IPAddress ipaddress = null;
+ IPHostEntry hostEntry = GetIPHostEntry(hostname);
+
+ if(null != hostEntry)
+ {
+ ipaddress = GetIPAddress(hostEntry, addressFamily);
+ }
+
+ return ipaddress;
+ }
+
+ public static IPAddress GetIPAddress(IPHostEntry hostEntry, AddressFamily addressFamily)
+ {
+ if(null != hostEntry)
+ {
+ foreach(IPAddress address in hostEntry.AddressList)
+ {
+ if(address.AddressFamily == addressFamily)
+ {
+ return address;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ protected Socket Connect(string host, int port)
+ {
+ Socket socket = null;
+ IPAddress ipaddress;
+
+ try
+ {
+ if(TryParseIPAddress(host, out ipaddress))
+ {
+ socket = ConnectSocket(ipaddress, port);
+ }
+ else
+ {
+ // Looping through the AddressList allows different type of connections to be tried
+ // (IPv6, IPv4 and whatever else may be available).
+ IPHostEntry hostEntry = GetIPHostEntry(host);
+
+ if(null != hostEntry)
+ {
+ // Prefer IPv6 first.
+ ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetworkV6);
+ socket = ConnectSocket(ipaddress, port);
+ if(null == socket)
+ {
+ // Try IPv4 next.
+ ipaddress = GetIPAddress(hostEntry, AddressFamily.InterNetwork);
+ socket = ConnectSocket(ipaddress, port);
+ if(null == socket)
+ {
+ // Try whatever else there is.
+ foreach(IPAddress address in hostEntry.AddressList)
+ {
+ if(AddressFamily.InterNetworkV6 == address.AddressFamily
+ || AddressFamily.InterNetwork == address.AddressFamily)
+ {
+ // Already tried these protocols.
+ continue;
+ }
+
+ socket = ConnectSocket(address, port);
+ if(null != socket)
+ {
+ ipaddress = address;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(null == socket)
+ {
+ throw new SocketException();
+ }
+ }
+ catch(Exception ex)
+ {
+ throw new NMSConnectionException(String.Format("Error connecting to {0}:{1}.", host, port), ex);
+ }
+
+ Tracer.DebugFormat("Connected to {0}:{1} using {2} protocol.", host, port, ipaddress.AddressFamily.ToString());
+ return socket;
+ }
+ }
}