activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1056375 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs
Date Fri, 07 Jan 2011 16:23:45 GMT
Author: tabish
Date: Fri Jan  7 16:23:45 2011
New Revision: 1056375

URL: http://svn.apache.org/viewvc?rev=1056375&view=rev
Log:
https://issues.apache.org/jira/browse/AMQNET-290

Inherit from ISinglePhaseEnlistment so that local transactions that don't hit the MSDTC can
be optimized to perform a single commit operation as opposed to the two phase prepare / commit
model.  This allows durable enlistments to operate from Mono builds as well.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs?rev=1056375&r1=1056374&r2=1056375&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs
Fri Jan  7 16:23:45 2011
@@ -32,7 +32,7 @@ namespace Apache.NMS.ActiveMQ
 
 namespace Apache.NMS.ActiveMQ
 {
-	public class TransactionContext : IEnlistmentNotification
+	public class TransactionContext : ISinglePhaseNotification
     {
         private const int XA_OK = 0;
         private const int XA_READONLY = 3;
@@ -301,11 +301,11 @@ namespace Apache.NMS.ActiveMQ
             {
                 if(this.transactionId != null)
                 {
-                    // Now notify the broker that a new XA'ish transaction has started.
+                    // Now notify the broker that a new XA'ish transaction has completed.
                     TransactionInfo info = new TransactionInfo();
                     info.ConnectionId = this.session.Connection.ConnectionId;
                     info.TransactionId = this.transactionId;
-                    info.Type = (int) TransactionType.CommitOnePhase;
+                    info.Type = (int) TransactionType.CommitTwoPhase;
 
                     this.connection.CheckConnected();
                     this.connection.SyncRequest(info);
@@ -332,6 +332,47 @@ namespace Apache.NMS.ActiveMQ
             }
         }
 
+        public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
+        {
+            Tracer.Debug("Single Phase Commit notification received");
+
+            try
+            {
+                if(this.transactionId != null)
+                {
+                	BeforeEnd();
+
+					// Now notify the broker that a new XA'ish transaction has completed.
+                    TransactionInfo info = new TransactionInfo();
+                    info.ConnectionId = this.session.Connection.ConnectionId;
+                    info.TransactionId = this.transactionId;
+                    info.Type = (int) TransactionType.CommitOnePhase;
+
+                    this.connection.CheckConnected();
+                    this.connection.SyncRequest(info);
+
+                    Tracer.Debug("Transaction Single Phase Commit Reports Done: ");
+
+                    // if server responds that nothing needs to be done, then reply done.
+                    enlistment.Done();
+
+                    AfterCommit();
+                }
+            }
+            catch(Exception ex)
+            {
+                Tracer.Debug("Transaction Single Phase Commit failed with error: " + ex.Message);
+                AfterRollback();
+                enlistment.Done();
+                throw;
+            }
+            finally
+            {
+                this.currentEnlistment = null;
+                this.transactionId = null;
+            }
+        }
+		
         public void Rollback(Enlistment enlistment)
         {
             Tracer.Debug("Rollback notification received");



Mime
View raw message