[jboss-cvs] JBossAS SVN: r83734 - 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
Sat Jan 31 18:34:16 EST 2009


Author: jhowell at redhat.com
Date: 2009-01-31 18:34:16 -0500 (Sat, 31 Jan 2009)
New Revision: 83734

Modified:
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
Log:
[JBPAPP-1530] - Fixed regression that was introduced that stopped BMT from handling transactions.

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-31 23:08:41 UTC (rev 83733)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java	2009-01-31 23:34:16 UTC (rev 83734)
@@ -291,11 +291,21 @@
 
          try
 		 {
-				if (activation.isDeliveryTransacted() && xaSession != null)
+				//If we have a transacted delivery
+        	    if (activation.isDeliveryTransacted() )
 				{
-					current = new XATransactionDemarcationStrategy();
+					//if we have an XASession
+        	    	if(xaSession != null)
+					{
+						current = new XATransactionDemarcationStrategy();
+					}
+					else  //if we don't have an XASession, simulate it with a transacted session
+					{
+						current = new SimulatedXATransactionDemarcationStrategy();
+					}
+					
 				}
-				else
+        	    else
 				{
 					current = new LocalDemarcationStrategy();
 				}
@@ -316,35 +326,27 @@
       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
    {
-
-      boolean trace = log.isTraceEnabled();
-
-      Transaction trans = null;
-
-      TransactionManager tm = pool.getActivation().getTransactionManager();;
-
-      public LocalDemarcationStrategy() throws Throwable
+      public void end()
       {
+         final JmsActivationSpec spec = pool.getActivation().getActivationSpec();
 
-         final int timeout = pool.getActivation().getActivationSpec().getTransactionTimeout();
-
-         if (timeout > 0)
+         if (spec.isSessionTransacted())
          {
-            log.trace("Setting transactionTimeout for JMSSessionPool to " + timeout);
-            tm.setTransactionTimeout(timeout);
+            if (session != null)
+            {
+               try
+               {
+                  session.commit();
+               }
+               catch (JMSException e)
+               {
+                  log.error("Failed to commit session transaction", e);
+               }
+            }
          }
-         //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()
@@ -357,11 +359,10 @@
 
                try
                {
-                  
-            	   /*
+                  /*
                    * Looks strange, but this basically means
                    * 
-                   * JBAS-6343 - If the underlying connection was non-XA and the transaction attribute is REQUIRED
+                   * 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.
@@ -369,8 +370,7 @@
                    */
                   if (pool.getActivation().isDeliveryTransacted() || spec.getRedeliverUnspecified())
                   {
-                	  log.debug(JmsServerSession.this +"Rolling transacted session back due to an error");
-                	  session.rollback();
+                     session.rollback();
                   }
 
                }
@@ -382,6 +382,82 @@
          }
       }
 
+   }
+   
+   /**
+    * 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 SimulatedXATransactionDemarcationStrategy implements TransactionDemarcationStrategy
+   {
+
+      boolean trace = log.isTraceEnabled();
+
+      Transaction trans = null;
+
+      TransactionManager tm = pool.getActivation().getTransactionManager();;
+
+      public SimulatedXATransactionDemarcationStrategy() throws Throwable
+      {
+
+         final int timeout = pool.getActivation().getActivationSpec().getTransactionTimeout();
+
+         if (timeout > 0)
+         {
+            log.trace("Setting transactionTimeout for JMSSessionPool to " + timeout);
+            tm.setTransactionTimeout(timeout);
+
+         }
+
+         tm.begin();
+
+         try
+         {
+            trans = tm.getTransaction();
+
+            if (trace)
+               log.trace(JmsServerSession.this + " using tx=" + trans);
+          
+         }
+         catch (Throwable t)
+         {
+            try
+            {
+               tm.rollback();
+            }
+            catch (Throwable ignored)
+            {
+               log.trace(JmsServerSession.this + " ignored error rolling back after failed enlist", ignored);
+            }
+            throw t;
+         }
+
+      }
+
+      public void error()
+      {
+         // Mark for tollback TX via TM
+         try
+         {
+
+            if (trace)
+            {
+               log.trace(JmsServerSession.this + " using TM to mark TX for rollback tx=" + trans);
+               
+            }
+            session.rollback();
+            trans.setRollbackOnly();
+         }
+         catch (Throwable t)
+         {
+            log.error(JmsServerSession.this + " failed to set rollback only", t);
+         }
+
+      }
+
       public void end()
       {
          try
@@ -395,9 +471,11 @@
             // 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();
+               if (trace)
+                  log.trace(JmsServerSession.this + " rolling back JMS transaction tx=" + trans);
+               // actually roll it back
+               tm.rollback();
+               session.rollback();
             }
 
             else if (trans.getStatus() == Status.STATUS_ACTIVE)
@@ -409,27 +487,14 @@
                if (trace)
                   log.trace(JmsServerSession.this + " commiting the JMS transaction tx=" + trans);
                tm.commit();
+               session.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();
-               }
-
+               session.rollback();
             }
-
          }
          catch (Throwable t)
          {
@@ -439,7 +504,7 @@
       }
 
    }
-
+   
    private class XATransactionDemarcationStrategy implements TransactionDemarcationStrategy
    {
 




More information about the jboss-cvs-commits mailing list