[jboss-cvs] JBossAS SVN: r82951 - branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 15 18:15:31 EST 2009


Author: jhowell at redhat.com
Date: 2009-01-15 18:15:31 -0500 (Thu, 15 Jan 2009)
New Revision: 82951

Modified:
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
Log:
JBPAPP-1530 - Added logic to the Local transaction demarcation strategy so that it would roll back non-xa sessions  using transacted sessions..

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java	2009-01-15 23:14:05 UTC (rev 82950)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java	2009-01-15 23:15:31 UTC (rev 82951)
@@ -289,26 +289,22 @@
          final JmsActivationSpec spec = pool.getActivation().getActivationSpec();
          final JmsActivation activation = pool.getActivation();
 
-         if (activation.isDeliveryTransacted() && xaSession != null)
-         {
-            try
-            {
-               current = new XATransactionDemarcationStrategy();
-            }
-            catch (Throwable t)
-            {
-               log.error(this + " error creating transaction demarcation ", t);
-            }
-
-         }
-         else
-         {
-
-            return new LocalDemarcationStrategy();
-
-         }
-
-         return current;
+         try
+		 {
+				if (activation.isDeliveryTransacted() && xaSession != null)
+				{
+					current = new XATransactionDemarcationStrategy();
+				}
+				else
+				{
+					current = new LocalDemarcationStrategy();
+				}
+		}
+		catch (Throwable t)
+		{
+			log.error(this + " error creating transaction demarcation ", t);
+		}
+        return current;
       }
 
    }
@@ -320,27 +316,35 @@
       void end();
 
    }
-
+   /**
+    * JBAS-6343 - This class is exactly like the XADemarcationStrategy, but it uses a transacted session under the covers.
+    * Unfortuneately we have to start a transaction the for local, because we need to be able to get a handle to any failed
+    * transactions.  
+    * @author jhowell
+    *
+    */
    private class LocalDemarcationStrategy implements TransactionDemarcationStrategy
    {
-      public void end()
+
+      boolean trace = log.isTraceEnabled();
+
+      Transaction trans = null;
+
+      TransactionManager tm = pool.getActivation().getTransactionManager();;
+
+      public LocalDemarcationStrategy() throws Throwable
       {
-         final JmsActivationSpec spec = pool.getActivation().getActivationSpec();
 
-         if (spec.isSessionTransacted())
+         final int timeout = pool.getActivation().getActivationSpec().getTransactionTimeout();
+
+         if (timeout > 0)
          {
-            if (session != null)
-            {
-               try
-               {
-                  session.commit();
-               }
-               catch (JMSException e)
-               {
-                  log.error("Failed to commit session transaction", e);
-               }
-            }
+            log.trace("Setting transactionTimeout for JMSSessionPool to " + timeout);
+            tm.setTransactionTimeout(timeout);
          }
+         //we need to begin a tx so that we can get a handle to the tx in end.  In end we will roll back the session.
+         tm.begin();
+         trans=tm.getTransaction();
       }
 
       public void error()
@@ -353,10 +357,11 @@
 
                try
                {
-                  /*
+                  
+            	   /*
                    * Looks strange, but this basically means
                    * 
-                   * If the underlying connection was non-XA and the transaction attribute is REQUIRED
+                   * JBAS-6343 - If the underlying connection was non-XA and the transaction attribute is REQUIRED
                    * we rollback. Also, if the underlying connection was non-XA and the transaction
                    * attribute is NOT_SUPPORT and the non standard redelivery behavior is enabled 
                    * we rollback to force redelivery.
@@ -364,7 +369,8 @@
                    */
                   if (pool.getActivation().isDeliveryTransacted() || spec.getRedeliverUnspecified())
                   {
-                     session.rollback();
+                	  log.debug(JmsServerSession.this +"Rolling transacted session back due to an error");
+                	  session.rollback();
                   }
 
                }
@@ -376,6 +382,62 @@
          }
       }
 
+      public void end()
+      {
+         try
+         {
+
+            // Use the TM to commit the Tx (assert the correct association) 
+            Transaction currentTx = tm.getTransaction();
+            if (trans.equals(currentTx) == false)
+               throw new IllegalStateException("Wrong tx association: expected " + trans + " was " + currentTx);
+
+            // Marked rollback
+            if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+            {
+                log.trace(JmsServerSession.this + " rolling Transacted session back due to Transaction Rollback");
+            	//call to error, if we are rolled back
+            	error();
+            }
+
+            else if (trans.getStatus() == Status.STATUS_ACTIVE)
+            {
+               // Commit tx
+               // This will happen if
+               // a) everything goes well
+               // b) app. exception was thrown
+               if (trace)
+                  log.trace(JmsServerSession.this + " commiting the JMS transaction tx=" + trans);
+               tm.commit();
+
+               // NO XASession? then manually commit.  This is not so good but
+               // it's the best we can do if we have no XASession.
+               if (xaSession == null && pool.getActivation().isDeliveryTransacted())
+               {
+            	   log.trace(JmsServerSession.this + " commiting Transacted session");
+            	   session.commit();
+               }
+
+            }
+            else
+            {
+               tm.suspend();
+
+               if (xaSession == null && pool.getActivation().isDeliveryTransacted())
+               {
+                  session.rollback();
+               }
+
+            }
+
+         }
+         catch (Throwable t)
+         {
+            log.error(JmsServerSession.this + " failed to commit/rollback", t);
+         }
+
+      }
+
    }
 
    private class XATransactionDemarcationStrategy implements TransactionDemarcationStrategy




More information about the jboss-cvs-commits mailing list