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/07/09 01:11:25 UTC
svn commit: r1144543 - in /activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk: ./
src/main/csharp/ src/test/csharp/
Author: jgomes
Date: Fri Jul 8 23:11:24 2011
New Revision: 1144543
URL: http://svn.apache.org/viewvc?rev=1144543&view=rev
Log:
Refactor with intermediate connection factory that will instantiate the correct 32-bit or 64-bit version of the ZMQ provider library.
Fixes [AMQNET-333]. (See https://issues.apache.org/jira/browse/AMQNET-333)
Added:
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonConnectionFactory.cs
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj
- copied, changed from r1144507, activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj
Modified:
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonAssemblyInfo.cs
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ConnectionFactory.cs
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/test/csharp/ZMQTest.cs
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0-test.csproj
activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq.sln
Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonAssemblyInfo.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonAssemblyInfo.cs?rev=1144543&r1=1144542&r2=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonAssemblyInfo.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonAssemblyInfo.cs Fri Jul 8 23:11:24 2011
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfigurationAttribute("SNAPSHOT")]
[assembly: AssemblyCompanyAttribute("http://activemq.apache.org/nms")]
[assembly: AssemblyProductAttribute("Apache NMS for ZMQ Class Library")]
-[assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2011 Apache Software Foundation")]
+[assembly: AssemblyCopyrightAttribute("Copyright (C) 2011 Apache Software Foundation")]
[assembly: AssemblyTrademarkAttribute("")]
[assembly: AssemblyCultureAttribute("")]
[assembly: AssemblyVersionAttribute("1.0.0.1")]
Added: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonConnectionFactory.cs?rev=1144543&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonConnectionFactory.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/CommonConnectionFactory.cs Fri Jul 8 23:11:24 2011
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Reflection;
+
+namespace Apache.NMS.ZMQ
+{
+ /// <summary>
+ /// A Factory that will instantiate a 32-bit or 64-bit version of the provider
+ /// as determined by the runtime environment. This factory delegates instantiation responsibilities
+ /// to the real factory. This is only in place so that the correct bit-version can be loaded.
+ /// This factory indirection is necessary due to the low-level dependency on a 32-bit or 64-bit native DLL.
+ /// To avoid a DLL load failure, we have to ensure we dynamically link to the correct version.
+ /// </summary>
+ public class ConnectionFactory : IConnectionFactory
+ {
+ // Checking the runtime size of an IntPtr will tell us our runtime environment.
+ // 32-bit runtime's IntPtr size is 4.
+ // 64-bit runtimes' ItrPtr size is 8.
+ static private bool is32bit = (IntPtr.Size == 4);
+
+ private static Type factoryType = null;
+ private IConnectionFactory connFactory = null;
+
+ private const string DEFAULT_BROKER_URL = "tcp://localhost:5556";
+ private const string ENV_BROKER_URL = "ZMQ_BROKER_URL";
+
+ /// <summary>
+ /// Static class constructor that is executed only once before any normal object constructors.
+ /// This is the type constructor.
+ /// </summary>
+ static ConnectionFactory()
+ {
+ // Load the assembly and get the type.
+ string assemblyFileName = (is32bit ? "Apache.NMS.ZMQ32.dll" : "Apache.NMS.ZMQ64.dll");
+ Assembly assembly;
+
+ try
+ {
+ assembly = Assembly.Load(assemblyFileName);
+ if(null != assembly)
+ {
+ Tracer.DebugFormat("Succesfully loaded provider: {0}", assemblyFileName);
+ factoryType = assembly.GetType("Apache.NMS.ZMQ.ConnectionFactory", true, true);
+ }
+ }
+ catch(Exception ex)
+ {
+ Tracer.ErrorFormat("Exception loading assembly {0} failed: {1}", assemblyFileName, ex.Message);
+ factoryType = null;
+ }
+ }
+
+ private static string GetDefaultBrokerUrl()
+ {
+ string brokerUrl = Environment.GetEnvironmentVariable(ENV_BROKER_URL);
+
+ if(string.IsNullOrEmpty(brokerUrl))
+ {
+ brokerUrl = DEFAULT_BROKER_URL;
+ }
+
+ return brokerUrl;
+ }
+
+ public ConnectionFactory()
+ : this(GetDefaultBrokerUrl())
+ {
+ }
+
+ public ConnectionFactory(string brokerUri)
+ : this(brokerUri, null)
+ {
+ }
+
+ public ConnectionFactory(string brokerUri, string clientID)
+ : this(new Uri(brokerUri), clientID)
+ {
+ }
+
+ public ConnectionFactory(Uri brokerUri)
+ : this(brokerUri, null)
+ {
+ }
+
+ public ConnectionFactory(Uri brokerUri, string clientID)
+ {
+ if(null == factoryType)
+ {
+ throw new ApplicationException("Could not load the ZMQ connection factory assembly.");
+ }
+
+ connFactory = (IConnectionFactory) Activator.CreateInstance(factoryType, new object[] { brokerUri, clientID });
+ }
+
+ #region IConnectionFactory Members
+
+ public Uri BrokerUri
+ {
+ get { return connFactory.BrokerUri; }
+ set { connFactory.BrokerUri = value; }
+ }
+
+ public ConsumerTransformerDelegate ConsumerTransformer
+ {
+ get { return connFactory.ConsumerTransformer; }
+ set { connFactory.ConsumerTransformer = value; }
+ }
+
+ public IConnection CreateConnection(string userName, string password)
+ {
+ return connFactory.CreateConnection(userName, password);
+ }
+
+ public IConnection CreateConnection()
+ {
+ return connFactory.CreateConnection();
+ }
+
+ public ProducerTransformerDelegate ProducerTransformer
+ {
+ get { return connFactory.ProducerTransformer; }
+ set { connFactory.ProducerTransformer = value; }
+ }
+
+ public IRedeliveryPolicy RedeliveryPolicy
+ {
+ get { return connFactory.RedeliveryPolicy; }
+ set { connFactory.RedeliveryPolicy = value; }
+ }
+
+ #endregion
+ }
+}
Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ConnectionFactory.cs?rev=1144543&r1=1144542&r2=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ConnectionFactory.cs Fri Jul 8 23:11:24 2011
@@ -24,41 +24,9 @@ namespace Apache.NMS.ZMQ
/// </summary>
public class ConnectionFactory : IConnectionFactory
{
- public const string DEFAULT_BROKER_URL = "zmq://localhost";
- public const string ENV_BROKER_URL = "ZMQ_BROKER_URL";
private Uri brokerUri;
- private IRedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
private string clientID;
-
- public static string GetDefaultBrokerUrl()
- {
- string answer = Environment.GetEnvironmentVariable(ENV_BROKER_URL);
- if(answer == null)
- {
- answer = DEFAULT_BROKER_URL;
- }
- return answer;
- }
-
- public ConnectionFactory()
- : this(GetDefaultBrokerUrl())
- {
- }
-
- public ConnectionFactory(string brokerUri)
- : this(brokerUri, null)
- {
- }
-
- public ConnectionFactory(string brokerUri, string clientID)
- : this(new Uri(brokerUri), clientID)
- {
- }
-
- public ConnectionFactory(Uri brokerUri)
- : this(brokerUri, null)
- {
- }
+ private IRedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
public ConnectionFactory(Uri brokerUri, string clientID)
{
Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/test/csharp/ZMQTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/test/csharp/ZMQTest.cs?rev=1144543&r1=1144542&r2=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/test/csharp/ZMQTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/test/csharp/ZMQTest.cs Fri Jul 8 23:11:24 2011
@@ -69,8 +69,8 @@ namespace Apache.NMS.ZMQ
////////////////////////////
// Factory check
////////////////////////////
- Apache.NMS.ZMQ.ConnectionFactory factory = new Apache.NMS.ZMQ.ConnectionFactory("zmq:tcp://localhost:5556", "");
- Assert.IsNotNull(factory);
+ IConnectionFactory factory = new ConnectionFactory("tcp://localhost:5556", "");
+ Assert.IsNotNull(factory, "Error creating connection factory.");
////////////////////////////
// Connection check
@@ -96,7 +96,7 @@ namespace Apache.NMS.ZMQ
////////////////////////////
// Consumer check
////////////////////////////
- IQueue testQueue = new Queue("ZMQTestQueue");
+ IQueue testQueue = session.GetQueue("ZMQTestQueue");
Assert.IsNotNull(testQueue, "Error creating test queue.");
IMessageConsumer consumer = session.CreateConsumer(testQueue);
Assert.IsNotNull(consumer, "Error creating consumer.");
@@ -107,7 +107,7 @@ namespace Apache.NMS.ZMQ
// Producer check
////////////////////////////
IMessageProducer producer = session.CreateProducer(testQueue);
- Assert.IsNotNull(consumer);
+ Assert.IsNotNull(consumer, "Error creating producer.");
ITextMessage testMsg = producer.CreateTextMessage("Zero Message.");
Assert.IsNotNull(testMsg, "Error creating test message.");
Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0-test.csproj?rev=1144543&r1=1144542&r2=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0-test.csproj Fri Jul 8 23:11:24 2011
@@ -90,12 +90,6 @@
<Compile Include="src\test\csharp\ZMQTest.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="vs2010-zmq-net-4.0.csproj">
- <Project>{A5FCA129-991B-4CB2-987A-B25E43B0F5EC}</Project>
- <Name>vs2008-msmq</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
@@ -127,6 +121,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="vs2010-zmq-net-4.0.csproj">
+ <Project>{5AA5A595-FF56-444D-A7BD-988001619FDC}</Project>
+ <Name>vs2010-zmq-net-4.0</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>
<PostBuildEvent>
Added: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj?rev=1144543&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj (added)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj Fri Jul 8 23:11:24 2011
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{5AA5A595-FF56-444D-A7BD-988001619FDC}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Apache.NMS.ZMQ</RootNamespace>
+ <AssemblyName>Apache.NMS.ZMQ</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <BaseIntermediateOutputPath>obj\net-4.0</BaseIntermediateOutputPath>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\net-4.0\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\net-4.0\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Apache.NMS, Version=1.5.1.2378, Culture=neutral, PublicKeyToken=82756feee3957618, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>lib\Apache.NMS\net-4.0\Apache.NMS.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\main\csharp\CommonAssemblyInfo.cs" />
+ <Compile Include="src\main\csharp\CommonConnectionFactory.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
Copied: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj (from r1144507, activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj)
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj?p2=activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj&p1=activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj&r1=1144507&r2=1144543&rev=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj Fri Jul 8 23:11:24 2011
@@ -8,7 +8,7 @@
<ProjectGuid>{A5FCA129-991B-4CB2-987A-B25E43B0F5EC}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Apache.NMS.ZMQ</RootNamespace>
- <AssemblyName>Apache.NMS.ZMQ</AssemblyName>
+ <AssemblyName>Apache.NMS.ZMQ64</AssemblyName>
<WarningLevel>4</WarningLevel>
<StartupObject>
</StartupObject>
Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq.sln
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq.sln?rev=1144543&r1=1144542&r2=1144543&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq.sln (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq.sln Fri Jul 8 23:11:24 2011
@@ -1,11 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vs2010-zmq-net-4.0", "vs2010-zmq-net-4.0.csproj", "{A5FCA129-991B-4CB2-987A-B25E43B0F5EC}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vs2010-zmq-net-4.0x64", "vs2010-zmq-net-4.0x64.csproj", "{A5FCA129-991B-4CB2-987A-B25E43B0F5EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vs2010-zmq-net-4.0-test", "vs2010-zmq-net-4.0-test.csproj", "{2F31ED5C-44A2-464A-BD55-2B5B010654E8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vs2010-zmq-net-4.0", "vs2010-zmq-net-4.0.csproj", "{5AA5A595-FF56-444D-A7BD-988001619FDC}"
+EndProject
Global
+ GlobalSection(SubversionScc) = preSolution
+ Svn-Managed = True
+ Manager = AnkhSVN - Subversion Support for Visual Studio
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
@@ -19,12 +25,12 @@ Global
{2F31ED5C-44A2-464A-BD55-2B5B010654E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F31ED5C-44A2-464A-BD55-2B5B010654E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F31ED5C-44A2-464A-BD55-2B5B010654E8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5AA5A595-FF56-444D-A7BD-988001619FDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5AA5A595-FF56-444D-A7BD-988001619FDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5AA5A595-FF56-444D-A7BD-988001619FDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5AA5A595-FF56-444D-A7BD-988001619FDC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(SubversionScc) = preSolution
- Svn-Managed = True
- Manager = AnkhSVN - Subversion Support for Visual Studio
- EndGlobalSection
EndGlobal