User: fleury  
  Date: 00/09/07 22:22:30

  Modified:    src/main/org/jboss/tm TxManager.java TransactionImpl.java
  Log:
  Fixed behaviour for inVM thread passing
  
  Revision  Changes    Path
  1.14      +260 -260  jboss/src/main/org/jboss/tm/TxManager.java
  
  Index: TxManager.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/tm/TxManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TxManager.java    2000/09/08 02:25:00     1.13
  +++ TxManager.java    2000/09/08 05:22:29     1.14
  @@ -1,9 +1,9 @@
  - /*
  - * jBoss, the OpenSource EJB server
  - *
  - * Distributable under GPL license.
  - * See terms of license at gnu.org.
  - */
  +/*
  +* jBoss, the OpenSource EJB server
  +*
  +* Distributable under GPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.tm;
   
   import java.util.Hashtable;
  @@ -26,261 +26,261 @@
   import org.jboss.logging.Logger;
   
   /**
  - *   <description>
  - *
  - *   @see <related>
  - *   @author Rickard �berg ([EMAIL PROTECTED])
  - *  @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *   @version $Revision: 1.13 $
  - */
  +*    <description>
  +*
  +*    @see <related>
  +*    @author Rickard �berg ([EMAIL PROTECTED])
  +*  @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  +*    @version $Revision: 1.14 $
  +*/
   public class TxManager
  -   implements TransactionManager
  +implements TransactionManager
   {
  -   // Constants -----------------------------------------------------
  -
  -   // Attributes ----------------------------------------------------
  -   // threadTx keeps track of a thread local association of tx
  -   ThreadLocal threadTx = new ThreadLocal();
  -   // transactions maps
  -   Hashtable txCapsules = new Hashtable();
  -
  -   int timeOut = 60*1000; // Timeout in milliseconds
  -
  -   // Static --------------------------------------------------------
  -
  -   // Constructors --------------------------------------------------
  -
  -   // Public --------------------------------------------------------
  -   public void begin()
  -      throws NotSupportedException,
  -             SystemException
  -   {
  -try {
  -//      Logger.log("begin tx");
  -
  -      // create tx capsule
  -      TxCapsule txCap = new TxCapsule(this, timeOut);
  -
  -      // Store it
  -      txCapsules.put(txCap.getTransaction(), txCap);
  -
  -      // Associate it with the Thread
  -      threadTx.set(txCap.getTransaction());
  -} catch (RuntimeException ex) {
  -  System.err.println("Exception: " + ex);
  -  ex.printStackTrace();
  -  throw ex;
  -}
  -   }
  -
  -   public void commit()
  -      throws RollbackException,
  -             HeuristicMixedException,
  -             HeuristicRollbackException,
  -             java.lang.SecurityException,
  -             java.lang.IllegalStateException,
  -             SystemException
  -   {
  -//      Logger.log("commit tx");
  -
  -      getTransaction().commit();
  -   }
  -
  -   public int getStatus()
  -      throws SystemException
  -   {
  -      // Get the txCapsule running now with the thread
  -      Object current = threadTx.get();
  -      if (current != null) {
  -      TxCapsule txCap = (TxCapsule) txCapsules.get(current);
  -
  -      if (txCap == null)
  +    // Constants -----------------------------------------------------
  +    
  +    // Attributes ----------------------------------------------------
  +    // threadTx keeps track of a thread local association of tx
  +    ThreadLocal threadTx = new ThreadLocal();
  +    // transactions maps
  +    Hashtable txCapsules = new Hashtable();
  +    
  +    int timeOut = 60*1000; // Timeout in milliseconds
  +    
  +    // Static --------------------------------------------------------
  +    
  +    // Constructors --------------------------------------------------
  +    
  +    // Public --------------------------------------------------------
  +    public void begin()
  +    throws NotSupportedException,
  +    SystemException
  +    {
  +        try {
  +            Logger.log("begin tx");
  +            
  +            // create tx capsule
  +            TxCapsule txCap = new TxCapsule(this, timeOut);
  +            
  +            // Store it
  +            txCapsules.put(txCap.getTransaction(), txCap);
  +            
  +            // Associate it with the Thread
  +            threadTx.set(txCap.getTransaction());
  +        } catch (RuntimeException ex) {
  +            System.err.println("Exception: " + ex);
  +            ex.printStackTrace();
  +            throw ex;
  +        }
  +    }
  +    
  +    public void commit()
  +    throws RollbackException,
  +    HeuristicMixedException,
  +    HeuristicRollbackException,
  +    java.lang.SecurityException,
  +    java.lang.IllegalStateException,
  +    SystemException
  +    {   
  +        getTransaction().commit();
  +    }
  +    
  +    public int getStatus()
  +    throws SystemException
  +    {
  +        // Get the txCapsule running now with the thread
  +        Object current = threadTx.get();
  +        if (current != null) {
  +            TxCapsule txCap = (TxCapsule) txCapsules.get(current);
  +            
  +            if (txCap == null)
  +                return Status.STATUS_NO_TRANSACTION;
  +            else
  +                return txCap.getStatus();
  +        } else {
               return Status.STATUS_NO_TRANSACTION;
  -         else
  -            return txCap.getStatus();
  -      } else {
  -         return Status.STATUS_NO_TRANSACTION;
  -      }
  -   }
  -
  -   public Transaction getTransaction()
  -     throws SystemException
  -   {
  -      return (Transaction)threadTx.get();
  -   }
  -
  -   public void resume(Transaction tobj)
  -      throws InvalidTransactionException,
  -             java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      //Useless
  -
  -      //throw new Exception("txMan.resume() NYI");
  -   }
  -
  -
  -   public Transaction suspend()
  -      throws SystemException
  -   {
  -//      Logger.log("suspend tx");
  -
  -      // Useless
  -
  -      return null;
  -      //throw new Exception("txMan.suspend() NYI");
  -   }
  -
  -
  -   public void rollback()
  -      throws java.lang.IllegalStateException,
  -             java.lang.SecurityException,
  -             SystemException
  -   {
  -//      Logger.log("rollback tx");
  -      getTransaction().rollback();
  -   }
  -
  -   public void setRollbackOnly()
  -      throws java.lang.IllegalStateException,
  -             SystemException
  -   {
  -//      Logger.log("set rollback only tx");
  -      getTransaction().setRollbackOnly();
  -   }
  -
  -   public void setTransactionTimeout(int seconds)
  -      throws SystemException
  -   {
  -      timeOut = seconds;
  -   }
  -
  -   /*
  -   * The following 2 methods are here to provide association and disassociation of 
the thread
  -   */
  -   public Transaction disassociateThread() {
  -      Transaction current = (Transaction) threadTx.get();
  -
  -      threadTx.set(null);
  -
  -      return current;
  -   }
  -
  -   public void associateThread(Transaction transaction) {
  -      // If the tx has traveled it needs the TxManager
  -      ((TransactionImpl) transaction).setTxManager(this);
  -             
  -      // Associate with the thread
  -      threadTx.set(transaction);
  -   }
  -
  -
  -   // Package protected ---------------------------------------------
  -
  -   // There has got to be something better :)
  -   static TxManager getTransactionManager() {
  -      try {
  -
  -         javax.naming.InitialContext context = new javax.naming.InitialContext();
  -
  -         //One tx in naming
  -         Logger.log("Calling get manager from JNDI");
  -         TxManager manager = (TxManager) context.lookup("TransactionManager");
  -         Logger.log("Returning TM "+manager.hashCode());
  -
  -         return manager;
  -
  -      } catch (Exception e ) { return null;}
  -   }
  -
  -   int getTransactionTimeout()
  -   {
  -      return timeOut;
  -   }
  -
  -
  -   // Public --------------------------------------------------------
  -
  -   public void commit(Transaction tx)
  -      throws RollbackException,
  -             HeuristicMixedException,
  -             HeuristicRollbackException,
  -             java.lang.SecurityException,
  -             java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      try {
  -         // Look up the txCapsule and delegate
  -         ((TxCapsule) txCapsules.get(tx)).commit();
  -      }
  -      finally {
  -         // Disassociation
  -         threadTx.set(null);
  -      }
  -   }
  -     
  -   public boolean delistResource(Transaction tx, XAResource xaRes, int flag)
  -      throws java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      // Look up the txCapsule and delegate
  -      return ((TxCapsule) txCapsules.get(tx)).delistResource(xaRes, flag);
  -   }
  -
  -   public boolean enlistResource(Transaction tx, XAResource xaRes)
  -      throws RollbackException,
  -             java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      // Look up the txCapsule and delegate
  -      return ((TxCapsule) txCapsules.get(tx)).enlistResource(xaRes);
  -   }
  -
  -   public int getStatus(Transaction tx)
  -      throws SystemException
  -   {
  -      // Look up the txCapsule and delegate
  -      TxCapsule txCap = ((TxCapsule) txCapsules.get(tx));
  -      return txCap == null ? Status.STATUS_NO_TRANSACTION : txCap.getStatus();
  -   }
  -
  -   public void registerSynchronization(Transaction tx, Synchronization s)
  -      throws RollbackException,
  -             java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      // Look up the txCapsule and delegate
  -      ((TxCapsule) txCapsules.get(tx)).registerSynchronization(s);
  -   }
  -
  -   public void rollback(Transaction tx)
  -      throws java.lang.IllegalStateException,
  -             java.lang.SecurityException,
  -             SystemException
  -   {
  -      try {
  -         // Look up the txCapsule and delegate
  -         ((TxCapsule) txCapsules.get(tx)).rollback();
  -      }
  -      finally {
  -         // Disassociation
  -         threadTx.set(null);
  -      }
  -   }
  -     
  -   public void setRollbackOnly(Transaction tx)
  -      throws java.lang.IllegalStateException,
  -             SystemException
  -   {
  -      // Look up the txCapsule and delegate
  -      ((TxCapsule) txCapsules.get(tx)).setRollbackOnly();
  -   }
  -
  -
  -
  -   // Protected -----------------------------------------------------
  -
  -   // Private -------------------------------------------------------
  -
  -   // Inner classes -------------------------------------------------
  +        }
  +    }
  +    
  +    public Transaction getTransaction()
  +    throws SystemException
  +    {
  +        return (Transaction)threadTx.get();
  +    }
  +    
  +    public void resume(Transaction tobj)
  +    throws InvalidTransactionException,
  +    java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        //Useless
  +        
  +        //throw new Exception("txMan.resume() NYI");
  +    }
  +    
  +    
  +    public Transaction suspend()
  +    throws SystemException
  +    {
  +        //      Logger.log("suspend tx");
  +        
  +        // Useless
  +        
  +        return null;
  +        //throw new Exception("txMan.suspend() NYI");
  +    }
  +    
  +    
  +    public void rollback()
  +    throws java.lang.IllegalStateException,
  +    java.lang.SecurityException,
  +    SystemException
  +    { 
  +    getTransaction().rollback();
  +    }
  +    
  +    public void setRollbackOnly()
  +    throws java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        //      Logger.log("set rollback only tx");
  +        getTransaction().setRollbackOnly();
  +    }
  +    
  +    public void setTransactionTimeout(int seconds)
  +    throws SystemException
  +    {
  +        timeOut = seconds;
  +    }
  +    
  +    /*
  +    * The following 2 methods are here to provide association and disassociation of 
the thread
  +    */
  +    public Transaction disassociateThread() {
  +        Transaction current = (Transaction) threadTx.get();
  +        
  +        threadTx.set(null);
  +        
  +        return current;
  +    }
  +    
  +    public void associateThread(Transaction transaction) {
  +        // If the tx has traveled it needs the TxManager
  +        ((TransactionImpl) transaction).setTxManager(this);
  +        
  +        // Associate with the thread
  +        threadTx.set(transaction);
  +    }
  +    
  +    
  +    // Package protected ---------------------------------------------
  +    
  +    // There has got to be something better :)
  +    static TxManager getTransactionManager() {
  +        try {
  +            
  +            javax.naming.InitialContext context = new javax.naming.InitialContext();
  +            
  +            //One tx in naming
  +            Logger.log("Calling get manager from JNDI");
  +            TxManager manager = (TxManager) context.lookup("TransactionManager");
  +            Logger.log("Returning TM "+manager.hashCode());
  +            
  +            return manager;
  +        
  +        } catch (Exception e ) { return null;}
  +    }
  +    
  +    int getTransactionTimeout()
  +    {
  +        return timeOut;
  +    }
  +    
  +    
  +    // Public --------------------------------------------------------
  +    
  +    public void commit(Transaction tx)
  +    throws RollbackException,
  +    HeuristicMixedException,
  +    HeuristicRollbackException,
  +    java.lang.SecurityException,
  +    java.lang.IllegalStateException,
  +    SystemException
  +    {
  +         Logger.log("commit tx "+tx.hashCode());
  +        try {
  +            // Look up the txCapsule and delegate
  +            ((TxCapsule) txCapsules.get(tx)).commit();
  +        }
  +        finally {
  +            // Disassociation
  +            threadTx.set(null);
  +        }
  +    }
  +    
  +    public boolean delistResource(Transaction tx, XAResource xaRes, int flag)
  +    throws java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        // Look up the txCapsule and delegate
  +        return ((TxCapsule) txCapsules.get(tx)).delistResource(xaRes, flag);
  +    }
  +    
  +    public boolean enlistResource(Transaction tx, XAResource xaRes)
  +    throws RollbackException,
  +    java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        // Look up the txCapsule and delegate
  +        return ((TxCapsule) txCapsules.get(tx)).enlistResource(xaRes);
  +    }
  +    
  +    public int getStatus(Transaction tx)
  +    throws SystemException
  +    {
  +        // Look up the txCapsule and delegate
  +        TxCapsule txCap = ((TxCapsule) txCapsules.get(tx));
  +        return txCap == null ? Status.STATUS_NO_TRANSACTION : txCap.getStatus();
  +    }
  +    
  +    public void registerSynchronization(Transaction tx, Synchronization s)
  +    throws RollbackException,
  +    java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        // Look up the txCapsule and delegate
  +        ((TxCapsule) txCapsules.get(tx)).registerSynchronization(s);
  +    }
  +    
  +    public void rollback(Transaction tx)
  +    throws java.lang.IllegalStateException,
  +    java.lang.SecurityException,
  +    SystemException
  +    {
  +          Logger.log("rollback tx "+tx.hashCode());
  +     
  +        try {
  +            // Look up the txCapsule and delegate
  +            ((TxCapsule) txCapsules.get(tx)).rollback();
  +        }
  +        finally {
  +            // Disassociation
  +            threadTx.set(null);
  +        }
  +    }
  +    
  +    public void setRollbackOnly(Transaction tx)
  +    throws java.lang.IllegalStateException,
  +    SystemException
  +    {
  +        // Look up the txCapsule and delegate
  +        ((TxCapsule) txCapsules.get(tx)).setRollbackOnly();
  +    }
  +    
  +    
  +    
  +    // Protected -----------------------------------------------------
  +    
  +    // Private -------------------------------------------------------
  +    
  +    // Inner classes -------------------------------------------------
   }
  
  
  
  1.8       +3 -1      jboss/src/main/org/jboss/tm/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/tm/TransactionImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TransactionImpl.java      2000/09/08 02:25:01     1.7
  +++ TransactionImpl.java      2000/09/08 05:22:29     1.8
  @@ -33,7 +33,7 @@
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
    *  @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *   @version $Revision: 1.7 $
  + *   @version $Revision: 1.8 $
    */
   public class TransactionImpl
      implements Transaction, Serializable
  @@ -80,6 +80,7 @@
                      java.lang.IllegalStateException,
                      SystemException
      {
  +       
         tm.commit(this);
      }
   
  @@ -117,6 +118,7 @@
                        java.lang.SecurityException,
                        SystemException
      {
  +      
          tm.rollback(this);
      }
   
  
  
  

Reply via email to