[jboss-cvs] JBossAS SVN: r68295 - branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 14 11:50:19 EST 2007


Author: adrian at jboss.org
Date: 2007-12-14 11:50:19 -0500 (Fri, 14 Dec 2007)
New Revision: 68295

Added:
   branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/JTATransactionChecker.java
Modified:
   branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/BaseConnectionManager2.java
   branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/TxConnectionManager.java
Log:
[JBAS-5082] - Add a mechanism to check whether the thread associated transaction is no longer in a runnable state

Modified: branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/BaseConnectionManager2.java
===================================================================
--- branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/BaseConnectionManager2.java	2007-12-14 16:48:31 UTC (rev 68294)
+++ branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/BaseConnectionManager2.java	2007-12-14 16:50:19 UTC (rev 68295)
@@ -88,7 +88,8 @@
          BaseConnectionManager2MBean,
          ConnectionCacheListener,
          ConnectionListenerFactory,
-         TransactionTimeoutConfiguration
+         TransactionTimeoutConfiguration,
+         JTATransactionChecker
 {
    /**
     * Note that this copy has a trailing / unlike the original in
@@ -232,6 +233,11 @@
       throw new NotImplementedException("NYI: getTransactionTimeout()");
    }
 
+   public void checkTransactionActive() throws RollbackException, SystemException
+   {
+      // Nothing
+   }
+
    //ServiceMBeanSupport
 
    protected void startService() throws Exception
@@ -820,7 +826,8 @@
          implements
             ConnectionManager,
             Serializable,
-            TransactionTimeoutConfiguration
+            TransactionTimeoutConfiguration,
+            JTATransactionChecker
    {
       static final long serialVersionUID = -528322728929261214L;
 
@@ -866,6 +873,18 @@
          }
       }
 
+      public void checkTransactionActive() throws RollbackException, SystemException
+      {
+         try
+         {
+            getCM().checkTransactionActive();
+         }
+         catch (ResourceException e)
+         {
+            throw new NestedRuntimeException("Unable to retrieve connection manager", e);
+         }
+      }
+
       private BaseConnectionManager2 getCM() throws ResourceException
       {
          if (realCm == null)

Added: branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/JTATransactionChecker.java
===================================================================
--- branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/JTATransactionChecker.java	                        (rev 0)
+++ branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/JTATransactionChecker.java	2007-12-14 16:50:19 UTC (rev 68295)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY 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 along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.resource.connectionmanager;
+
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+/**
+ * JTATransactionChecker.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface JTATransactionChecker
+{
+   /**
+    * Check whether a tranasction is active
+    * 
+    * @throws RollbackException if the transaction is not active, preparing, prepared or committing
+    * @throws SystemException for any error in the transaction manager
+    */
+   void checkTransactionActive() throws RollbackException, SystemException;
+}

Modified: branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/TxConnectionManager.java
===================================================================
--- branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/TxConnectionManager.java	2007-12-14 16:48:31 UTC (rev 68294)
+++ branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/TxConnectionManager.java	2007-12-14 16:50:19 UTC (rev 68295)
@@ -268,6 +268,21 @@
       return -1;
    }
 
+   @Override
+   public void checkTransactionActive() throws RollbackException, SystemException
+   {
+      if (tm == null)
+         throw new IllegalStateException("No transaction manager: " + ccmName);
+      Transaction tx = tm.getTransaction();
+      if (tx != null)
+      {
+         int status = tx.getStatus();
+         // Only allow states that will actually succeed
+         if (status != Status.STATUS_ACTIVE && status != Status.STATUS_PREPARING && status != Status.STATUS_PREPARED && status != Status.STATUS_COMMITTING)
+            throw new RollbackException("Transaction " + tx + " cannot proceed " + TxUtils.getStatusAsString(status));
+      }
+   }
+
    protected void startService() throws Exception
    {
       if (transactionManagerService != null)




More information about the jboss-cvs-commits mailing list