activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1202759 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/src/main/csharp/ Apache.NMS.ActiveMQ/trunk/src/test/csharp/ Apache.NMS.EMS/trunk/src/main/csharp/ Apache.NMS.MSMQ/trunk/src/main/csharp/ Apache.NMS.Stomp/trunk/src/main/csha...
Date Wed, 16 Nov 2011 16:07:51 GMT
Author: tabish
Date: Wed Nov 16 16:07:51 2011
New Revision: 1202759

URL: http://svn.apache.org/viewvc?rev=1202759&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQNET-348

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/TransactionContext.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/AMQTransactionTestSupport.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
    activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/TransactionContext.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/StompTransactionTestSupport.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Session.cs Wed Nov
16 16:07:51 2011
@@ -104,6 +104,31 @@ namespace Apache.NMS.ActiveMQ
 
         #region Property Accessors
 
+        #region Session Transaction Events
+
+        // We delegate the events to the TransactionContext since it knows
+        // what the state is for both Local and DTC transactions.
+
+        public event SessionTxEventDelegate TransactionStartedListener
+        {
+            add { this.transactionContext.TransactionStartedListener += value; }
+            remove { this.transactionContext.TransactionStartedListener += value; }
+        }
+
+        public event SessionTxEventDelegate TransactionCommittedListener
+        {
+            add { this.transactionContext.TransactionCommittedListener += value; }
+            remove { this.transactionContext.TransactionCommittedListener += value; }
+        }
+
+        public event SessionTxEventDelegate TransactionRolledBackListener
+        {
+            add { this.transactionContext.TransactionRolledBackListener += value; }
+            remove { this.transactionContext.TransactionRolledBackListener += value; }
+        }
+
+        #endregion
+
         /// <summary>
         /// Sets the maximum number of messages to keep around per consumer
         /// in addition to the prefetch window for non-durable topics until messages
@@ -756,7 +781,7 @@ namespace Apache.NMS.ActiveMQ
         /// </summary>
         internal virtual void DoStartTransaction()
         {
-            if(IsTransacted)
+            if(IsTransacted && !TransactionContext.InTransaction)
             {
                 this.TransactionContext.Begin();
             }

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=1202759&r1=1202758&r2=1202759&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
Wed Nov 16 16:07:51 2011
@@ -93,6 +93,11 @@ namespace Apache.NMS.ActiveMQ
                 
                 this.session.Connection.Oneway(info);
 
+                if(this.TransactionStartedListener != null)
+                {
+                    this.TransactionStartedListener(this.session);
+                }
+
                 if(Tracer.IsDebugEnabled)
                 {
                     Tracer.Debug("Begin:" + this.transactionId.ToString());
@@ -171,6 +176,11 @@ namespace Apache.NMS.ActiveMQ
                     {
                         synchronization.AfterCommit();
                     }
+
+                    if(this.TransactionCommittedListener != null)
+                    {
+                        this.TransactionCommittedListener(this.session);
+                    }
                 }
             }
             finally
@@ -189,6 +199,11 @@ namespace Apache.NMS.ActiveMQ
                     {
                         synchronization.AfterRollback();
                     }
+
+                    if(this.TransactionRolledBackListener != null)
+                    {
+                        this.TransactionRolledBackListener(this.session);
+                    }
                 }
             }
             finally
@@ -197,6 +212,14 @@ namespace Apache.NMS.ActiveMQ
             }
         }
 
+        #region Transaction State Events
+
+        public event SessionTxEventDelegate TransactionStartedListener;
+        public event SessionTxEventDelegate TransactionCommittedListener;
+        public event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
         #region Transaction Members used when dealing with .NET System Transactions.
 
         // When DTC calls prepare we must then wait for either the TX to commit, rollback
or
@@ -286,6 +309,11 @@ namespace Apache.NMS.ActiveMQ
 
                     this.session.Connection.Oneway(info);
 
+                    if (this.TransactionStartedListener != null)
+                    {
+                        this.TransactionStartedListener(this.session);
+                    }
+
                     if (Tracer.IsDebugEnabled)
                     {
                         Tracer.Debug("Began XA'ish Transaction:" + xaId.GlobalTransactionId.ToString());

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/AMQTransactionTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/AMQTransactionTestSupport.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/AMQTransactionTestSupport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/AMQTransactionTestSupport.cs
Wed Nov 16 16:07:51 2011
@@ -540,6 +540,133 @@ namespace Apache.NMS.ActiveMQ.Test
         }
 
         [Test]
+        public void TestTransactionEventsFired()
+        {
+            IMessage[] outbound = new IMessage[]
+            {session.CreateTextMessage("First IMessage"), session.CreateTextMessage("Second
IMessage")};
+
+            session.TransactionStartedListener += TransactionStarted;
+            session.TransactionCommittedListener += TransactionCommitted;
+            session.TransactionRolledBackListener += TransactionRolledBack;
+
+            // sends a message
+            BeginTx();
+            producer.Send(outbound[0]);
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            // sends a message that gets rollbacked
+            BeginTx();
+            producer.Send(session.CreateTextMessage("I'm going to get rolled back."));
+            Assert.IsTrue(this.transactionStarted);
+            RollbackTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionRolledBack);
+
+            // sends a message
+            BeginTx();
+            producer.Send(outbound[1]);
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            // receives the first message
+            BeginTx();
+            LinkedList<IMessage> messages = new LinkedList<IMessage>();
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            messages.AddLast(message);
+
+            // receives the second message
+            message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+            Assert.IsTrue(this.transactionStarted);
+            messages.AddLast(message);
+
+            // validates that the rollbacked was not consumed
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound, 0);
+            AssertTextMessagesEqual(outbound, inbound, "Rollback did not work.");
+        }
+
+        [Test]
+        public void TestMessageListenerGeneratesTxEvents()
+        {
+            messageReceived = false;
+
+            session.TransactionStartedListener += TransactionStarted;
+            session.TransactionCommittedListener += TransactionCommitted;
+            session.TransactionRolledBackListener += TransactionRolledBack;
+
+            // Send messages
+            for(int i = 0; i < MESSAGE_COUNT; i++)
+            {
+                producer.Send(session.CreateTextMessage(MESSAGE_TEXT + i));
+            }
+
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            consumer.Listener += new MessageListener(OnAsyncTxMessage);
+
+            // wait receive
+            WaitForMessageToBeReceived();
+            Assert.IsTrue(this.transactionStarted);
+
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+        }
+
+        private bool transactionStarted = false;
+        private bool transactionCommitted = false;
+        private bool transactionRolledBack = false;
+        private bool messageReceived = false;
+
+        public void OnAsyncTxMessage(IMessage message)
+        {
+            messageReceived = true;
+        }
+
+        private void WaitForMessageToBeReceived()
+        {
+            for(int i = 0; i < 100 && !messageReceived; i++)
+            {
+                Thread.Sleep(100);
+            }
+
+            Assert.IsTrue(messageReceived);
+        }
+
+        private void TransactionStarted(ISession session)
+        {
+            transactionStarted = true;
+            transactionCommitted = false;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionCommitted(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = true;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionRolledBack(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = false;
+            transactionRolledBack = true;
+        }
+
+        [Test]
         public void TestMessageListener()
         {
             // Send messages

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NetTxTransactionTest.cs
Wed Nov 16 16:07:51 2011
@@ -223,39 +223,61 @@ namespace Apache.NMS.ActiveMQ.Test
 
                 using(INetTxSession session = connection.CreateNetTxSession())
                 {
+                    session.TransactionStartedListener += TransactionStarted;
+                    session.TransactionCommittedListener += TransactionCommitted;
+                    session.TransactionRolledBackListener += TransactionRolledBack;
+
                     destination = session.CreateTemporaryQueue();
                     using(IMessageProducer producer = session.CreateProducer(destination))
                     {
                         using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
                         {
+                            Assert.IsFalse(this.transactionStarted);
+
                             Assert.IsNotNull(Transaction.Current);
                             for(int i = 0; i < MSG_COUNT; ++i)
                             {
                                 producer.Send(session.CreateTextMessage("Hello World"));
                             }
 
+                            Assert.IsTrue(this.transactionStarted, "A TX should have been
started by producing");
+
                             scoped.Complete();
                         }
 
+                        Assert.IsFalse(this.transactionStarted, "TX Should have Committed
and cleared Started");
+                        Assert.IsTrue(this.transactionCommitted, "TX Should have Committed");
+
                         session.Close();
                     }
                 }
 
                 using(INetTxSession session = connection.CreateNetTxSession())
                 {
+                    session.TransactionStartedListener += TransactionStarted;
+                    session.TransactionCommittedListener += TransactionCommitted;
+                    session.TransactionRolledBackListener += TransactionRolledBack;
+
                     using(IMessageConsumer consumer = session.CreateConsumer(destination))
                     {
                         using(TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew))
                         {
+                            Assert.IsFalse(this.transactionStarted);
+
                             for(int i = 0; i < MSG_COUNT; ++i)
                             {
                                 IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
                                 Assert.IsNotNull(msg, "Message was null for index: " + i);
                             }
 
+                            Assert.IsTrue(this.transactionStarted, "A TX should have been
started by consuming");
+
                             scoped.Complete();
                         }
 
+                        Assert.IsFalse(this.transactionStarted, "TX Should have Committed
and cleared Started");
+                        Assert.IsTrue(this.transactionCommitted, "TX Should have Committed");
+
                         session.Close();
                     }
                 }
@@ -278,6 +300,31 @@ namespace Apache.NMS.ActiveMQ.Test
             }
         }
 
+        private bool transactionStarted = false;
+        private bool transactionCommitted = false;
+        private bool transactionRolledBack = false;
+
+        private void TransactionStarted(ISession session)
+        {
+            transactionStarted = true;
+            transactionCommitted = false;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionCommitted(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = true;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionRolledBack(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = false;
+            transactionRolledBack = true;
+        }
+
     }
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/Session.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.EMS/trunk/src/main/csharp/Session.cs Wed Nov 16 16:07:51
2011
@@ -405,6 +405,14 @@ namespace Apache.NMS.EMS
             set { this.producerTransformer = value; }
         }
 
+        #region Transaction State Events
+
+        public event SessionTxEventDelegate TransactionStartedListener;
+        public event SessionTxEventDelegate TransactionCommittedListener;
+        public event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
         // Properties
 
         /// <summary>

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs Wed Nov 16 16:07:51
2011
@@ -262,5 +262,14 @@ namespace Apache.NMS.MSMQ
         {
             Dispose();
         }
+
+        #region Transaction State Events
+
+        public event SessionTxEventDelegate TransactionStartedListener;
+        public event SessionTxEventDelegate TransactionCommittedListener;
+        public event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
     }
 }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Session.cs Wed Nov 16
16:07:51 2011
@@ -82,6 +82,31 @@ namespace Apache.NMS.Stomp
             Dispose(false);
         }
 
+        #region Session Transaction Events
+
+        // We delegate the events to the TransactionContext since it knows
+        // what the state is at all times.
+
+        public event SessionTxEventDelegate TransactionStartedListener
+        {
+            add { this.transactionContext.TransactionStartedListener += value; }
+            remove { this.transactionContext.TransactionStartedListener += value; }
+        }
+
+        public event SessionTxEventDelegate TransactionCommittedListener
+        {
+            add { this.transactionContext.TransactionCommittedListener += value; }
+            remove { this.transactionContext.TransactionCommittedListener += value; }
+        }
+
+        public event SessionTxEventDelegate TransactionRolledBackListener
+        {
+            add { this.transactionContext.TransactionRolledBackListener += value; }
+            remove { this.transactionContext.TransactionRolledBackListener += value; }
+        }
+
+        #endregion
+
         #region Property Accessors
 
         /// <summary>

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/TransactionContext.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/TransactionContext.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/TransactionContext.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/TransactionContext.cs
Wed Nov 16 16:07:51 2011
@@ -71,6 +71,14 @@ namespace Apache.NMS.Stomp
             }
         }
 
+        #region Transaction State Events
+
+        public event SessionTxEventDelegate TransactionStartedListener;
+        public event SessionTxEventDelegate TransactionCommittedListener;
+        public event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
         public void Begin()
         {
             if(!InTransaction)
@@ -83,6 +91,11 @@ namespace Apache.NMS.Stomp
                 info.Type = (int) TransactionType.Begin;
 
                 this.session.Connection.Oneway(info);
+
+                if(this.TransactionStartedListener != null)
+                {
+                    this.TransactionStartedListener(this.session);
+                }
             }
         }
 
@@ -147,6 +160,11 @@ namespace Apache.NMS.Stomp
                 {
                     synchronization.AfterCommit();
                 }
+
+                if(this.TransactionCommittedListener != null)
+                {
+                    this.TransactionCommittedListener(this.session);
+                }
             }
         }
 
@@ -158,6 +176,11 @@ namespace Apache.NMS.Stomp
                 {
                     synchronization.AfterRollback();
                 }
+
+                if(this.TransactionRolledBackListener != null)
+                {
+                    this.TransactionRolledBackListener(this.session);
+                }
             }
         }
     }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/StompTransactionTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/StompTransactionTestSupport.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/StompTransactionTestSupport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/StompTransactionTestSupport.cs
Wed Nov 16 16:07:51 2011
@@ -627,5 +627,131 @@ namespace Apache.NMS.Stomp.Test
             Assert.IsFalse(ackMessages.Count < MESSAGE_COUNT);
         }
 
+        [Test]
+        public void TestTransactionEventsFired()
+        {
+            IMessage[] outbound = new IMessage[]
+            {session.CreateTextMessage("First IMessage"), session.CreateTextMessage("Second
IMessage")};
+
+            session.TransactionStartedListener += TransactionStarted;
+            session.TransactionCommittedListener += TransactionCommitted;
+            session.TransactionRolledBackListener += TransactionRolledBack;
+
+            // sends a message
+            BeginTx();
+            producer.Send(outbound[0]);
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            // sends a message that gets rollbacked
+            BeginTx();
+            producer.Send(session.CreateTextMessage("I'm going to get rolled back."));
+            Assert.IsTrue(this.transactionStarted);
+            RollbackTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionRolledBack);
+
+            // sends a message
+            BeginTx();
+            producer.Send(outbound[1]);
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            // receives the first message
+            BeginTx();
+            LinkedList<IMessage> messages = new LinkedList<IMessage>();
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            messages.AddLast(message);
+
+            // receives the second message
+            message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+            Assert.IsTrue(this.transactionStarted);
+            messages.AddLast(message);
+
+            // validates that the rollbacked was not consumed
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound, 0);
+            AssertTextMessagesEqual(outbound, inbound, "Rollback did not work.");
+        }
+
+        [Test]
+        public void TestMessageListenerGeneratesTxEvents()
+        {
+            messageReceived = false;
+
+            session.TransactionStartedListener += TransactionStarted;
+            session.TransactionCommittedListener += TransactionCommitted;
+            session.TransactionRolledBackListener += TransactionRolledBack;
+
+            // Send messages
+            for(int i = 0; i < MESSAGE_COUNT; i++)
+            {
+                producer.Send(session.CreateTextMessage(MESSAGE_TEXT + i));
+            }
+
+            Assert.IsTrue(this.transactionStarted);
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+
+            consumer.Listener += new MessageListener(OnAsyncTxMessage);
+
+            // wait receive
+            WaitForMessageToBeReceived();
+            Assert.IsTrue(this.transactionStarted);
+
+            CommitTx();
+            Assert.IsFalse(this.transactionStarted);
+            Assert.IsTrue(this.transactionCommitted);
+        }
+
+        private bool transactionStarted = false;
+        private bool transactionCommitted = false;
+        private bool transactionRolledBack = false;
+        private bool messageReceived = false;
+
+        public void OnAsyncTxMessage(IMessage message)
+        {
+            messageReceived = true;
+        }
+
+        private void WaitForMessageToBeReceived()
+        {
+            for(int i = 0; i < 100 && !messageReceived; i++)
+            {
+                Thread.Sleep(100);
+            }
+
+            Assert.IsTrue(messageReceived);
+        }
+
+        private void TransactionStarted(ISession session)
+        {
+            transactionStarted = true;
+            transactionCommitted = false;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionCommitted(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = true;
+            transactionRolledBack = false;
+        }
+
+        private void TransactionRolledBack(ISession session)
+        {
+            transactionStarted = false;
+            transactionCommitted = false;
+            transactionRolledBack = true;
+        }
     }
 }

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs Wed Nov 16 16:07:51
2011
@@ -193,6 +193,14 @@ namespace Apache.NMS.ZMQ
             messageQueueTransaction.Abort();
         }
 
+        #region Transaction State Events
+
+        public event SessionTxEventDelegate TransactionStartedListener;
+        public event SessionTxEventDelegate TransactionCommittedListener;
+        public event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
         public void Recover()
         {
             throw new NotSupportedException();

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs?rev=1202759&r1=1202758&r2=1202759&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/ISession.cs Wed Nov 16 16:07:51
2011
@@ -18,6 +18,12 @@ using System;
 
 namespace Apache.NMS
 {
+    /// <summary>
+    /// A delegate that is notified whenever a Transational evemt occurs for
+    /// the specified session such as TX started, committed or rolled back.
+    /// </summary>
+    public delegate void SessionTxEventDelegate(ISession session);
+
 	/// <summary>
 	/// Represents a single unit of work on an IConnection.
 	/// So the ISession can be used to perform transactional receive and sends
@@ -206,6 +212,14 @@ namespace Apache.NMS
 
 		#endregion
 
+        #region Session Events
+
+        event SessionTxEventDelegate TransactionStartedListener;
+        event SessionTxEventDelegate TransactionCommittedListener;
+        event SessionTxEventDelegate TransactionRolledBackListener;
+
+        #endregion
+
 		#region Attributes
 
 		TimeSpan RequestTimeout { get; set; }



Mime
View raw message