activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [17/50] [abbrv] activemq-nms-openwire git commit: Apply patch from Jose Alvarado. Thanks, Jose! Fixes [AMQNET-503]. (See https://issues.apache.org/jira/browse/AMQNET-503)
Date Wed, 08 Mar 2017 23:12:19 GMT
Apply patch from Jose Alvarado. Thanks, Jose!
Fixes [AMQNET-503]. (See https://issues.apache.org/jira/browse/AMQNET-503)



Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/commit/19306fb5
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/tree/19306fb5
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/diff/19306fb5

Branch: refs/heads/master
Commit: 19306fb56a2fd041402df27cf154989f4a298a4e
Parents: b20dde9
Author: Jim Gomes <jgomes@apache.org>
Authored: Mon Jul 6 22:41:41 2015 +0000
Committer: Jim Gomes <jgomes@apache.org>
Committed: Mon Jul 6 22:41:41 2015 +0000

----------------------------------------------------------------------
 src/main/csharp/NetTxConnection.cs            | 15 ++++++++++++
 src/main/csharp/NetTxMessageConsumer.cs       | 27 +++++++++++++++++++---
 src/main/csharp/NetTxSession.cs               | 10 ++++++++
 src/test/csharp/DtcTransactionsTestSupport.cs | 11 +++++----
 4 files changed, 55 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/19306fb5/src/main/csharp/NetTxConnection.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/NetTxConnection.cs b/src/main/csharp/NetTxConnection.cs
index bc174b7..8f1976c 100644
--- a/src/main/csharp/NetTxConnection.cs
+++ b/src/main/csharp/NetTxConnection.cs
@@ -51,6 +51,21 @@ namespace Apache.NMS.ActiveMQ
             return session;
         }
 
+        public INetTxSession CreateNetTxSession(Transaction tx, bool enlistNativeMsDtcResource)
+        {
+            NetTxSession session = (NetTxSession)CreateSession(AcknowledgementMode.Transactional);
+            session.Enlist(tx);
+            session.EnlistsMsDtcNativeResource = enlistNativeMsDtcResource;
+            return session;
+        }
+
+        public INetTxSession CreateNetTxSession(bool enlistNativeMsDtcResource)
+        {
+            NetTxSession session = (NetTxSession)CreateSession(AcknowledgementMode.Transactional);
+            session.EnlistsMsDtcNativeResource = enlistNativeMsDtcResource;
+            return session;
+        }
+
         protected override Session CreateActiveMQSession(AcknowledgementMode ackMode)
         {
             CheckConnected();

http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/19306fb5/src/main/csharp/NetTxMessageConsumer.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/NetTxMessageConsumer.cs b/src/main/csharp/NetTxMessageConsumer.cs
index 6a9a65c..f4ef109 100644
--- a/src/main/csharp/NetTxMessageConsumer.cs
+++ b/src/main/csharp/NetTxMessageConsumer.cs
@@ -18,6 +18,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Transactions;
 using Apache.NMS.ActiveMQ.Commands;
 
 namespace Apache.NMS.ActiveMQ
@@ -75,9 +76,29 @@ namespace Apache.NMS.ActiveMQ
                         // distributed TX manager we need to wait whenever the TX is being
                         // controlled by the DTC as it completes all operations async and
                         // we cannot start consumption again until all its tasks have completed.)
-                        waitForDtcWaitHandle = this.transactionContext.InNetTransaction &&
-                                               this.transactionContext.NetTxState ==
-                                               NetTxTransactionContext.TxState.Pending;
+                        var currentTransactionId = transactionContext.TransactionId as XATransactionId;
+                        string currentLocalTxId = currentTransactionId != null
+                            ? UTF8Encoding.UTF8.GetString(currentTransactionId.GlobalTransactionId)
+                            : "NONE";
+
+                        if (Transaction.Current != null)
+                        {
+                            waitForDtcWaitHandle = this.transactionContext.InNetTransaction
&&
+                                               this.transactionContext.NetTxState == NetTxTransactionContext.TxState.Pending
||
+                                               currentLocalTxId != Transaction.Current.TransactionInformation.LocalIdentifier;
+                        }
+                        else
+                        {
+                            waitForDtcWaitHandle = this.transactionContext.InNetTransaction
&&
+                                               this.transactionContext.NetTxState == NetTxTransactionContext.TxState.Pending;
+                        }
+                        
+                    }
+
+                    //if session EnlistMsDtcNativeResource the transaction does not need
to wait
+                    if (this.session.EnlistsMsDtcNativeResource)
+                    {
+                        waitForDtcWaitHandle = false;
                     }
 
                     if (waitForDtcWaitHandle)

http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/19306fb5/src/main/csharp/NetTxSession.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/NetTxSession.cs b/src/main/csharp/NetTxSession.cs
index 8da035b..f7e754b 100644
--- a/src/main/csharp/NetTxSession.cs
+++ b/src/main/csharp/NetTxSession.cs
@@ -32,6 +32,7 @@ namespace Apache.NMS.ActiveMQ
         {
             this.transactionContext = TransactionContext as NetTxTransactionContext;
             this.transactionContext.InitializeDtcTxContext();
+            this.enlistMsDtcNativeResources = false;
         }
 
         /// <summary>
@@ -51,6 +52,14 @@ namespace Apache.NMS.ActiveMQ
             this.EnrollInSpecifiedTransaction(tx);
         }
 
+        private bool enlistMsDtcNativeResources;
+
+        public bool EnlistsMsDtcNativeResource
+        {
+            get { return enlistMsDtcNativeResources; }
+            set { enlistMsDtcNativeResources = value; }
+        }
+
         /// <summary>
         /// Reports Transacted whenever there is an Ambient Transaction or the internal
         /// TransactionContext is still involed in a .NET Transaction beyond the lifetime
@@ -173,6 +182,7 @@ namespace Apache.NMS.ActiveMQ
             this.currentTransactionId = tx.TransactionInformation.LocalIdentifier; 
             transactionContext.Begin(tx);
         }
+        
     }
 }
 

http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/19306fb5/src/test/csharp/DtcTransactionsTestSupport.cs
----------------------------------------------------------------------
diff --git a/src/test/csharp/DtcTransactionsTestSupport.cs b/src/test/csharp/DtcTransactionsTestSupport.cs
index 2ce121f..030a9d3 100644
--- a/src/test/csharp/DtcTransactionsTestSupport.cs
+++ b/src/test/csharp/DtcTransactionsTestSupport.cs
@@ -53,7 +53,8 @@ namespace Apache.NMS.ActiveMQ.Test
         private ITrace oldTracer;
 
         protected const string sqlConnectionString =
-            "Data Source=localhost;Initial Catalog=TestDB;User ID=user;Password=password";
+            // "Data Source=localhost;Initial Catalog=TestDB;User ID=user;Password=password";
+            "Data Source=.\\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security = true";
         protected const string testTable = "TestTable";
         protected const string testColumn = "TestID";
         protected const string testQueueName = "TestQueue";
@@ -484,7 +485,7 @@ namespace Apache.NMS.ActiveMQ.Test
         {
             IList entries = ExtractDataSet();
 
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -531,7 +532,7 @@ namespace Apache.NMS.ActiveMQ.Test
         {
             IList entries = ExtractDataSet();
 
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -578,7 +579,7 @@ namespace Apache.NMS.ActiveMQ.Test
 
         protected static void ReadFromQueueAndInsertIntoDbWithCommit(INetTxConnection connection)
         {
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -619,7 +620,7 @@ namespace Apache.NMS.ActiveMQ.Test
 
         protected static void ReadFromQueueAndInsertIntoDbWithScopeAborted(INetTxConnection
connection)
         {
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 


Mime
View raw message