[jboss-svn-commits] JBL Code SVN: r20296 - in labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx: jts and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 4 08:26:06 EDT 2008


Author: jhalliday
Date: 2008-06-04 08:26:06 -0400 (Wed, 04 Jun 2008)
New Revision: 20296

Modified:
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java
Log:
Ported improvements to getTimeLeftBeforeTransactionTimeout implementation to trunk from the 4.2.3.SP branch. JBTM-371 (JBAS-5081)


Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java	2008-06-04 12:19:08 UTC (rev 20295)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java	2008-06-04 12:26:06 UTC (rev 20296)
@@ -30,8 +30,12 @@
 import javax.transaction.SystemException;
 
 import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+import com.arjuna.ats.internal.arjuna.thread.ThreadActionData;
 import com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate;
 import com.arjuna.ats.jbossatx.logging.jbossatxLogger;
+import com.arjuna.ats.arjuna.coordinator.BasicAction;
+import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
 
 public class TransactionManagerDelegate extends BaseTransactionManagerDelegate implements ObjectFactory
 {
@@ -70,19 +74,55 @@
      * errorRollback is true
      *
      * @message com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1
-     * 		[com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1] - Transaction rolledback
+     * 		[com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1] - Transaction has or will rollback.
      * @message com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_2
      * 		[com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_2] - Unexpected error retrieving transaction status
      */
     public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
         throws RollbackException
     {
-    	try
+        // see JBAS-5081 and http://www.jboss.com/index.html?module=bb&op=viewtopic&t=132128
+
+        try
     	{
-	    	if (getStatus() == Status.STATUS_MARKED_ROLLBACK)
-	    	{
-	    		throw new RollbackException(jbossatxLogger.logMesg.getString("com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1")) ;
-			}
+            switch(getStatus())
+            {
+                case Status.STATUS_MARKED_ROLLBACK:
+                case Status.STATUS_ROLLEDBACK:
+                case Status.STATUS_ROLLING_BACK:
+                    if(errorRollback) {
+                        throw new RollbackException(jbossatxLogger.logMesg.getString("com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1"));
+                    }
+                    break;
+                case Status.STATUS_COMMITTED:
+                case Status.STATUS_COMMITTING:
+                case Status.STATUS_UNKNOWN:
+                    throw new IllegalStateException();  // would be better to use a checked exception,
+                    // but RollbackException does not make sense and the API does not allow any other.
+                    // also need to clarify if we should throw an exception at all if !errorRollback?
+                case Status.STATUS_ACTIVE:
+                case Status.STATUS_PREPARED:
+                case Status.STATUS_PREPARING:
+                    // TODO this should attempt to return an actual value (in millisecs), but we need transactionReaper
+                    // changes to do that so it will be in 4.4+ only, not 4.2.3.SP.
+                    // For AS 5.0, something along the lines of the block below will probably work, but we should
+                    // push the code down into the JTA/JTS rather than having it here. Talking direct to ArjunaCore
+                    // seems like a bit of a hack...
+                    /*
+                    try {
+                        BasicAction basicAction = ThreadActionData.currentAction();
+                        int remainingSeconds = TransactionReaper.transactionReaper(true).getRemainingTimeout(basicAction);
+                        if(remainingSeconds != 0) {
+                            return 1000*remainingSeconds;
+                        }
+                    } catch(Exception e) {
+                        e.printStackTrace();
+                    }
+                    */
+                case Status.STATUS_NO_TRANSACTION:
+                default:
+                    break;
+            }
     	}
     	catch (final SystemException se)
     	{

Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java	2008-06-04 12:19:08 UTC (rev 20295)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java	2008-06-04 12:26:06 UTC (rev 20296)
@@ -1,20 +1,20 @@
 /*
  * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
- * as indicated by the @author tags. 
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
  * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
+ * full listing of individual contributors.
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
  * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
- * 
+ *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
@@ -39,7 +39,7 @@
      * The transaction manager.
      */
     private static final TransactionManagerImple TRANSACTION_MANAGER = new TransactionManagerImple() ;
-    
+
     /**
      * Construct the delegate with the appropriate transaction manager
      */
@@ -47,10 +47,10 @@
     {
         super(getTransactionManager());
     }
-    
+
     /**
      * Get the transaction timeout.
-     * 
+     *
      * @return the timeout in seconds associated with this thread
      * @throws SystemException for any error
      */
@@ -62,35 +62,57 @@
 
     /**
      * Get the time left before transaction timeout
-     * 
+     *
      * @param errorRollback throw an error if the transaction is marked for rollback
      * @return the remaining in the current transaction or -1
      * if there is no transaction
      * @throws RollbackException if the transaction is marked for rollback and
      * errorRollback is true
-     * 
+     *
      * @message com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1
-     * 		[com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1] - Transaction rolledback
+     * 		[com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1] - Transaction has or will rollback.
      * @message com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_2
      * 		[com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_2] - Unexpected error retrieving transaction status
      */
     public long getTimeLeftBeforeTransactionTimeout(boolean errorRollback)
         throws RollbackException
     {
-    	try
+        // see JBAS-5081 and http://www.jboss.com/index.html?module=bb&op=viewtopic&t=132128
+        
+        try
     	{
-	    	if (getStatus() == Status.STATUS_MARKED_ROLLBACK)
-	    	{
-	    		throw new RollbackException(jbossatxLogger.logMesg.getString("com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1")) ;
-			}
-		}
+            switch(getStatus())
+            {
+                case Status.STATUS_MARKED_ROLLBACK:
+                case Status.STATUS_ROLLEDBACK:
+                case Status.STATUS_ROLLING_BACK:
+                    if(errorRollback) {
+                        throw new RollbackException(jbossatxLogger.logMesg.getString("com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_1"));
+                    }
+                    break;
+                case Status.STATUS_COMMITTED:
+                case Status.STATUS_COMMITTING:
+                case Status.STATUS_UNKNOWN:
+                    throw new IllegalStateException();  // would be better to use a checked exception,
+                    // but RollbackException does not make sense and the API does not allow any other.
+                    // also need to clarify if we should throw an exception at all if !errorRollback?
+                case Status.STATUS_ACTIVE:
+                case Status.STATUS_PREPARED:
+                case Status.STATUS_PREPARING:
+                    // TODO this should attempt to return an actual value (in millisecs), but we need transactionReaper
+                    // changes to do that so it will be in 4.4+ only, not 4.2.3.SP
+                case Status.STATUS_NO_TRANSACTION:
+                default:
+                    break;
+            }
+    	}
     	catch (final SystemException se)
     	{
     		throw new RollbackException(jbossatxLogger.logMesg.getString("com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.getTimeLeftBeforeTransactionTimeout_2")) ;
     	}
         return -1 ;
     }
-    
+
     /**
      * Get the transaction manager from the factory.
      * @param initObj The initialisation object.
@@ -105,7 +127,7 @@
     {
         return this ;
     }
-    
+
     /**
      * Get the transaction manager.
      * @return The transaction manager.




More information about the jboss-svn-commits mailing list