[jboss-svn-commits] JBL Code SVN: r25687 - labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 17 08:19:08 EDT 2009


Author: jhalliday
Date: 2009-03-17 08:19:08 -0400 (Tue, 17 Mar 2009)
New Revision: 25687

Modified:
   labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/SubordinationManager.java
Log:
Added better implementation selection to the SubordinationManager. JBTM-514


Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/SubordinationManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/SubordinationManager.java	2009-03-17 12:15:11 UTC (rev 25686)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/SubordinationManager.java	2009-03-17 12:19:08 UTC (rev 25687)
@@ -21,6 +21,8 @@
 package com.arjuna.ats.internal.jta.transaction.arjunacore.jca;
 
 import com.arjuna.ats.jta.logging.jtaLogger;
+import com.arjuna.common.util.logging.DebugLevel;
+import com.arjuna.common.util.logging.VisibilityLevel;
 
 import javax.transaction.TransactionManager;
 import javax.resource.spi.XATerminator;
@@ -33,8 +35,11 @@
  */
 public class SubordinationManager
 {
+    public enum TxType { JTA, JTS }    
+    
     private static TransactionImporter transactionImporter = null;
     private static XATerminator xaTerminator = null;
+    private static TxType txType;
 
     public static TransactionImporter getTransactionImporter()
     {
@@ -56,14 +61,36 @@
         return xaTerminator;
     }
 
+    public static TxType getTxType()
+    {
+        return txType;
+    }
+
+    public static void setTxType(TxType txType)
+    {
+		if (jtaLogger.logger.isDebugEnabled())
+		{
+			jtaLogger.logger.debug(DebugLevel.FUNCTIONS, VisibilityLevel.VIS_PUBLIC, com.arjuna.ats.jta.logging.FacilityCode.FAC_JTA, "SubordinationManager.setTxType("+txType+")");
+		}
+        
+        if(SubordinationManager.txType != null && SubordinationManager.txType != txType)
+        {
+            throw new IllegalStateException("SubordinationManager can't change txType once it has been set.");
+        }
+        
+        SubordinationManager.txType = txType;
+    }
+
     /**
      * @message com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinationManager.importerfailure Failed to create instance of TransactionImporter
      */
     private static void initTransactionImporter()
     {
-        TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
+        if(txType == null) {
+            setTxType( guessTxType() );
+        }
         
-        if(tm instanceof com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)
+        if(txType == TxType.JTA)
         {
             // we are running in JTA mode
             transactionImporter = new TransactionImporterImple();
@@ -89,9 +116,13 @@
      */
     private static void initXATerminator()
     {
+        if(txType == null) {
+            setTxType( guessTxType() );
+        }
+
         TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
         
-        if(tm instanceof com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)
+        if(txType == TxType.JTA)
         {
             // we are running in JTA mode
             xaTerminator = new XATerminatorImple();
@@ -111,4 +142,24 @@
             }
         }
     }
+
+    /**
+     * Its rather tricky to figure out if we are running in JTA or JTAX(JTS) mode. We can make a resonable guess
+     * based on the transaction manager implementation that is running, but it's going to break if some unknown
+     * or derived impl comes along. It's therefore safer to use setTxType explicitly in such cases.
+     * 
+     * @return best guess at the currently configured TxType.
+     */
+    private static TxType guessTxType() {
+        TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
+        
+        if(tm instanceof com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)
+        {
+            return TxType.JTA;
+        } else if (tm.getClass().getName().contains(".jts.") || tm.getClass().getName().contains(".jtax.")) {
+            return TxType.JTS;
+        } else {
+            return TxType.JTA;
+        }
+    }
 }




More information about the jboss-svn-commits mailing list