[Jboss-cvs] JBossAS SVN: r57069 - branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 22 09:51:13 EDT 2006


Author: kabir.khan at jboss.com
Date: 2006-09-22 09:51:09 -0400 (Fri, 22 Sep 2006)
New Revision: 57069

Added:
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
Modified:
   branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java
Log:
[JBAS-3685] Remove all references to org.jboss.tm.TxManager - I've left a reference in place in TxManagerTimeOutReader.java so that we can work in older versions of JBoss

Added: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -0,0 +1,14 @@
+package org.jboss.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * When we don't know where we are
+ */
+class NullTransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      return 0;
+   }
+}
\ No newline at end of file

Added: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.TransactionTimeoutConfiguration;
+
+/**
+ * For use with newer versions of JBoss supporting the TransactionTimeoutConfiguration interface
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class TransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm) throws Exception
+   {
+      if (tm instanceof TransactionTimeoutConfiguration)
+      {
+         return ((TransactionTimeoutConfiguration)tm).getTransactionTimeout();
+      }
+      return 0;
+   }
+}
\ No newline at end of file

Modified: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -37,6 +37,7 @@
 public class TxInterceptor
 {
    private static final Logger log = Logger.getLogger(TxInterceptor.class);
+   private static final TxTimeoutReader txTimeoutReader = TxTimeoutReaderFactory.getTxTimeoutReader();
 
    public static class Never implements Interceptor
    {
@@ -174,20 +175,13 @@
 
       public Object invoke(Invocation invocation) throws Throwable
       {
-         org.jboss.tm.TxManager txManager = (org.jboss.tm.TxManager)tm;
-         int oldTimeout = 0;
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);
          
-         if (tm instanceof org.jboss.tm.TxManager)
-         {
-            txManager = (org.jboss.tm.TxManager)tm;
-            oldTimeout = txManager.getTransactionTimeout();
-         }
-         
          try 
          {
-            if (timeout != -1 && txManager != null)
+            if (timeout != -1 && tm != null)
             {
-               txManager.setTransactionTimeout(timeout);
+               tm.setTransactionTimeout(timeout);
             }
                
             Transaction tx = tm.getTransaction();
@@ -203,9 +197,9 @@
          }
          finally
          {
-            if (txManager != null)
+            if (tm != null)
             {
-               txManager.setTransactionTimeout(oldTimeout);
+               tm.setTransactionTimeout(oldTimeout);
             }
          }
       }
@@ -241,20 +235,13 @@
 
       public Object invoke(Invocation invocation) throws Throwable
       {
-         org.jboss.tm.TxManager txManager = (org.jboss.tm.TxManager)tm;
-         int oldTimeout = 0;
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);
          
-         if (tm instanceof org.jboss.tm.TxManager)
-         {
-            txManager = (org.jboss.tm.TxManager)tm;
-            oldTimeout = txManager.getTransactionTimeout();
-         }
-         
          try 
          {
-            if (timeout != -1 && txManager != null)
+            if (timeout != -1 && tm != null)
             {
-               txManager.setTransactionTimeout(timeout);
+               tm.setTransactionTimeout(timeout);
             }
                
             Transaction tx = tm.getTransaction();
@@ -277,9 +264,9 @@
          }
          finally
          {
-            if (txManager != null)
+            if (tm != null)
             {
-               txManager.setTransactionTimeout(oldTimeout);
+               tm.setTransactionTimeout(oldTimeout);
             }
          }
       }
@@ -317,6 +304,5 @@
          }
          return policy.invokeInCallerTx(invocation, tx);
       }
-
    }
 }

Added: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TxManagerTimeOutReader implements TxTimeoutReader 
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      if (tm instanceof org.jboss.tm.TxManager)
+      {
+         return ((org.jboss.tm.TxManager)tm).getTransactionTimeout();
+      }
+      return 0;
+   }
+}
\ No newline at end of file

Added: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TxTimeoutReader
+{
+   int getTransactionTimeOut(TransactionManager tm) throws Exception;
+   
+}

Added: branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
===================================================================
--- branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	2006-09-22 12:44:35 UTC (rev 57068)
+++ branches/Branch_4_0/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	2006-09-22 13:51:09 UTC (rev 57069)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.aspects.tx;
+
+/**
+ * Obtains the correct mechanism to get hold of a transaction timeout.
+ * Newer versions of JBoss should use the TransactionTimeoutConfiguration interfsce.
+ * For older versions we need to access the TxManager directly
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TxTimeoutReaderFactory
+{
+   public static TxTimeoutReader getTxTimeoutReader()
+   {
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TransactionTimeoutConfiguration");
+         return new TransactionTimeoutConfigurationReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+      
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TxManager");
+         return new TransactionTimeoutConfigurationReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+      
+      return new NullTransactionTimeoutConfigurationReader();
+   }
+}




More information about the jboss-cvs-commits mailing list