User: sparre  
  Date: 01/04/27 09:41:06

  Modified:    src/main/org/jboss/tm TransactionManagerService.java
                        TxManager.java
  Log:
  Fixed TM.setTransactionTimeout() bug
  Bugs item #419192
  
  Revision  Changes    Path
  1.9       +10 -7     jboss/src/main/org/jboss/tm/TransactionManagerService.java
  
  Index: TransactionManagerService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/tm/TransactionManagerService.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TransactionManagerService.java    2001/02/20 15:25:15     1.8
  +++ TransactionManagerService.java    2001/04/27 16:41:06     1.9
  @@ -37,7 +37,7 @@
    *  @see TxManager
    *  @author Rickard �berg ([EMAIL PROTECTED])
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Ole Husgaard</a>
  - *  @version $Revision: 1.8 $
  + *  @version $Revision: 1.9 $
    */
   public class TransactionManagerService
      extends ServiceMBeanSupport
  @@ -51,9 +51,9 @@
      // Attributes ----------------------------------------------------
   
      MBeanServer server;
  +
  +   int timeout = 300; // default tx timeout, dupl. in TM when it exists.
       
  -   int timeout;
  -   
      // Static --------------------------------------------------------
   
      static TxManager tm;
  @@ -77,10 +77,9 @@
      {
         // Get a reference to the TxManager singleton.
         tm = TxManager.getInstance();
  -       
  -      // Set timeout
  -      tm.setTransactionTimeout(timeout);
  -        
  +      // Set its default timeout.
  +      tm.setDefaultTransactionTimeout(timeout);
  +
         // Bind reference to TM in JNDI
         // Our TM also implement the tx importer and exporter
         // interfaces, so we bind it under those names too.
  @@ -106,11 +105,15 @@
      }
       
      public int getTransactionTimeout() {
  +      if (tm != null) // Get timeout value from TM (in case it was changed).
  +         timeout = tm.getDefaultTransactionTimeout();
         return timeout;
      }
   
      public void setTransactionTimeout(int timeout) {
         this.timeout = timeout;
  +      if (tm != null) // Update TM default timeout
  +         tm.setDefaultTransactionTimeout(timeout);
      }
   
   
  
  
  
  1.28      +91 -25    jboss/src/main/org/jboss/tm/TxManager.java
  
  Index: TxManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/tm/TxManager.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- TxManager.java    2001/02/09 18:56:18     1.27
  +++ TxManager.java    2001/04/27 16:41:06     1.28
  @@ -36,7 +36,7 @@
    *  @author Rickard �berg ([EMAIL PROTECTED])
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Ole Husgaard</a>
  - *  @version $Revision: 1.27 $
  + *  @version $Revision: 1.28 $
    */
   public class TxManager
      implements TransactionManager,
  @@ -88,15 +88,18 @@
         throws NotSupportedException,
                SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
   
  +      TransactionImpl current = ti.tx;
  +
         if (current != null && !current.isDone())
            throw new NotSupportedException("Transaction already active, " +
                                            "cannot nest transactions.");
   
  -      TxCapsule txCapsule = TxCapsule.getInstance(timeOut);
  +      long timeout = (ti.timeout == 0) ? timeOut : ti.timeout;
  +      TxCapsule txCapsule = TxCapsule.getInstance(timeout);
         TransactionImpl tx = txCapsule.getTransactionImpl();
  -      threadTx.set(tx);
  +      ti.tx = tx;
         globalIdTx.put(tx.getGlobalId(), tx);
      }
   
  @@ -111,11 +114,12 @@
                IllegalStateException,
                SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
  +      TransactionImpl current = ti.tx;
   
         if (current != null) {
            current.commit();
  -         threadTx.set(null);
  +         ti.tx = null;
         } else
            throw new IllegalStateException("No transaction.");
      }
  @@ -128,7 +132,7 @@
      public int getStatus()
         throws SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      TransactionImpl current = getTxImpl();
   
         if (current != null)
            return current.getStatus();
  @@ -143,10 +147,11 @@
      public Transaction getTransaction()
         throws SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
  +      TransactionImpl current = ti.tx;
   
         if (current != null && current.isDone()) {
  -         threadTx.set(null);
  +         ti.tx = null;
            return null;
         }
         return current;
  @@ -168,13 +173,14 @@
            throw new RuntimeException("Not a TransactionImpl, but a " +
                                       transaction.getClass().getName() + ".");
   
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
  +      TransactionImpl current = ti.tx;
           
         if (current != null)
            throw new IllegalStateException("Already associated with a tx");
   
         if (current != transaction)
  -         threadTx.set(transaction);
  +         ti.tx = (TransactionImpl)transaction;
      }
   
      /**
  @@ -188,10 +194,11 @@
      public Transaction suspend()
         throws SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
  +      TransactionImpl current = ti.tx;
           
         if (current != null)
  -         threadTx.set(null);
  +         ti.tx = null;
           
         return current;
      }
  @@ -204,11 +211,12 @@
                java.lang.SecurityException,
                SystemException
      { 
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      ThreadInfo ti = getThreadInfo();
  +      TransactionImpl current = ti.tx;
   
         if (current != null) {
            current.rollback();
  -         threadTx.set(null);
  +         ti.tx = null;
         } else
            throw new IllegalStateException("No transaction.");
      }
  @@ -221,7 +229,7 @@
         throws IllegalStateException,
                SystemException
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      TransactionImpl current = getTxImpl();
   
         if (current != null)
            current.setRollbackOnly();
  @@ -230,20 +238,31 @@
      }
   
      /**
  -    *  Set the transaction timeout for new transactions started here.
  +    *  Set the transaction timeout for new transactions started by the
  +    *  calling thread.
       */
      public void setTransactionTimeout(int seconds)
         throws SystemException
      {
  +      getThreadInfo().timeout = 1000 * seconds;
  +   }
  +    
  +   /**
  +    *  Set the default transaction timeout for new transactions.
  +    *  This default value is used if <code>setTransactionTimeout()</code>
  +    *  was never called, or if it was called with a value of <code>0</code>.
  +    */
  +   public void setDefaultTransactionTimeout(int seconds)
  +   {
         timeOut = 1000 * seconds;
      }
       
      /**
  -    *  Get the transaction timeout for new transactions started here.
  +    *  Get the default transaction timeout.
       *
  -    *  @return Transaction timeout in seconds.
  +    *  @return Default transaction timeout in seconds.
       */
  -   public int getTransactionTimeout()
  +   public int getDefaultTransactionTimeout()
      {
         return (int)(timeOut / 1000);
      }
  @@ -254,9 +273,9 @@
       */
      public Transaction disassociateThread()
      {
  -      TransactionImpl current = (TransactionImpl)threadTx.get();
  +      TransactionImpl current = getTxImpl();
           
  -      threadTx.set(null);
  +      setTxImpl(null);
           
         return current;
      }
  @@ -268,7 +287,7 @@
                                       transaction.getClass().getName() + ".");
   
         // Associate with the thread
  -      threadTx.set(transaction);
  +      setTxImpl((TransactionImpl)transaction);
      }
   
   
  @@ -309,7 +328,7 @@
       */
      public Object getTransactionPropagationContext()
      {
  -      return getTransactionPropagationContext((Transaction)threadTx.get());
  +      return getTransactionPropagationContext(getTxImpl());
      }
    
      /**
  @@ -340,7 +359,8 @@
      // Private -------------------------------------------------------
    
      /**
  -    *  This keeps track of the transaction association with threads.
  +    *  This keeps track of the thread association with transactions
  +    *  and timeout values.
       *  In some cases terminated transactions may not be cleared here.
       */
      private ThreadLocal threadTx = new ThreadLocal();
  @@ -351,5 +371,51 @@
       */
      private Map globalIdTx = Collections.synchronizedMap(new HashMap());
   
  +
  +   /**
  +    *  Return the ThreadInfo for the calling thread, and create if not
  +    *  found.
  +    */
  +   private ThreadInfo getThreadInfo()
  +   {
  +      ThreadInfo ret = (ThreadInfo)threadTx.get();
  +
  +      if (ret == null) {
  +         ret = new ThreadInfo();
  +         ret.timeout = timeOut;
  +         threadTx.set(ret);
  +      }
  +
  +      return ret;
  +   }
  +
  +   /**
  +    *  Return the TransactionImpl associated with the calling thread.
  +    */
  +   private TransactionImpl getTxImpl()
  +   {
  +      return getThreadInfo().tx;
  +   }
  +
  +   /**
  +    *  Set the TransactionImpl associated with the calling thread.
  +    */
  +   private void setTxImpl(TransactionImpl tx)
  +   {
  +      getThreadInfo().tx = tx;
  +   }
  +
  +
      // Inner classes -------------------------------------------------
  +
  +   /**
  +    *  A simple aggregate of a thread-associated timeout value
  +    *  and a thread-associated transaction.
  +    */
  +   static class ThreadInfo
  +   {
  +      long timeout = 0;
  +      TransactionImpl tx = null;
  +   }
  +
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to