[jboss-svn-commits] JBL Code SVN: r20264 - in labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/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
Tue Jun 3 07:07:57 EDT 2008


Author: jhalliday
Date: 2008-06-03 07:07:57 -0400 (Tue, 03 Jun 2008)
New Revision: 20264

Modified:
   labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java
   labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java
Log:
Improvements to getTimeLeftBeforeTransactionTimeout implementation. JBTM-371 (JBAS-5081)


Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java	2008-06-03 09:22:44 UTC (rev 20263)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerDelegate.java	2008-06-03 11:07:57 UTC (rev 20264)
@@ -76,19 +76,41 @@
      * 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
+                case Status.STATUS_NO_TRANSACTION:
+                default:
+                    break;
+            }
     	}
     	catch (final SystemException se)
     	{

Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java	2008-06-03 09:22:44 UTC (rev 20263)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerDelegate.java	2008-06-03 11:07:57 UTC (rev 20264)
@@ -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(new TransactionManagerImple());
     }
-    
+
     /**
      * 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