geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: rev 56866 - in geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction: . context manager
Date Sun, 07 Nov 2004 21:41:19 GMT
Author: djencks
Date: Sun Nov  7 13:41:18 2004
New Revision: 56866

Modified:
   geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/OnlineUserTransaction.java
   geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContextManager.java
   geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
Log:
final solution for GERONIMO-378.  Make the setTransactionTimeout on UserTransaction and TransactionManager
thread local.  Make everything else work more sensibly

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/OnlineUserTransaction.java
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/OnlineUserTransaction.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/OnlineUserTransaction.java
Sun Nov  7 13:41:18 2004
@@ -19,7 +19,6 @@
 public final class OnlineUserTransaction implements UserTransaction, Serializable {
     private transient TransactionContextManager transactionContextManager;
     private transient TrackedConnectionAssociator trackedConnectionAssociator;
-    private long transactionTimeoutMilliseconds = 0L;
 
     boolean isActive() {
         return transactionContextManager != null;
@@ -43,11 +42,11 @@
         if (seconds < 0) {
             throw new SystemException("transaction timeout must be positive or 0, not " +
seconds);
         }
-        transactionTimeoutMilliseconds = seconds * 1000;
+        transactionContextManager.setTransactionTimeout(seconds);
     }
 
     public void begin() throws NotSupportedException, SystemException {
-        transactionContextManager.newBeanTransactionContext(transactionTimeoutMilliseconds);
+        transactionContextManager.newBeanTransactionContext(0L);
 
         if(trackedConnectionAssociator != null) {
             try {

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContextManager.java
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContextManager.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/context/TransactionContextManager.java
Sun Nov  7 13:41:18 2004
@@ -69,7 +69,11 @@
     public TransactionManager getTransactionManager() {
         return transactionManager;
     }
-    
+
+    public void setTransactionTimeout(int timeoutSeconds) throws SystemException {
+        transactionManager.setTransactionTimeout(timeoutSeconds);
+    }
+
     public TransactionContext getContext() {
         return TransactionContext.getContext();
     }
@@ -121,8 +125,6 @@
 
 
     /**
-     * TODO write and use ImportedTransactionContext for this!
-     *
      * @see javax.resource.spi.XATerminator#commit(javax.transaction.xa.Xid, boolean)
      */
     public void commit(Xid xid, boolean onePhase) throws XAException {

Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
==============================================================================
--- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
(original)
+++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
Sun Nov  7 13:41:18 2004
@@ -26,16 +26,14 @@
 import javax.transaction.Status;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.Xid;
 
-import org.apache.geronimo.transaction.log.UnrecoverableLog;
 import org.apache.geronimo.transaction.ExtendedTransactionManager;
+import org.apache.geronimo.transaction.log.UnrecoverableLog;
 
 /**
  * Simple implementation of a transaction manager.
- * TODO transactionTimeoutMilliseconds functionality
  * TODO shut down timer gracefully
  *
  * @version $Rev$ $Date$
@@ -44,23 +42,21 @@
     private final TransactionLog txnLog;
     private final XidFactory xidFactory;
     private final int defaultTransactionTimeoutMilliseconds;
-    private volatile int transactionTimeoutMilliseconds;
+    private final ThreadLocal transactionTimeoutMilliseconds = new ThreadLocal();
     private final ThreadLocal threadTx = new ThreadLocal();
     private final Timer timeoutTimer = new Timer(true);
 
     public TransactionManagerImpl() {
         defaultTransactionTimeoutMilliseconds = 10 * 1000;
-        transactionTimeoutMilliseconds = defaultTransactionTimeoutMilliseconds;
         txnLog = new UnrecoverableLog();
         xidFactory = new XidFactoryImpl();
     }
 
-    public TransactionManagerImpl(int defaultTransactionTimeoutSeconds, TransactionLog txnLog,
XidFactory xidFactory) throws SystemException {
+    public TransactionManagerImpl(int defaultTransactionTimeoutSeconds, TransactionLog txnLog,
XidFactory xidFactory) {
         if (defaultTransactionTimeoutSeconds <= 0) {
             throw new IllegalArgumentException("defaultTransactionTimeoutSeconds must be
positive: attempted value: " + defaultTransactionTimeoutSeconds);
         }
         this.defaultTransactionTimeoutMilliseconds = defaultTransactionTimeoutSeconds * 1000;
-        setTransactionTimeout(defaultTransactionTimeoutSeconds);
         this.txnLog = txnLog;
         this.xidFactory = xidFactory;
     }
@@ -74,9 +70,9 @@
             throw new SystemException("transaction timeout must be positive or 0 to reset
to default");
         }
         if (seconds == 0) {
-            transactionTimeoutMilliseconds = defaultTransactionTimeoutMilliseconds;
+            transactionTimeoutMilliseconds.set(null);
         } else {
-            transactionTimeoutMilliseconds = seconds * 1000;
+            transactionTimeoutMilliseconds.set(new Long(seconds * 1000));
         }
     }
 
@@ -86,7 +82,7 @@
     }
 
     public void begin() throws NotSupportedException, SystemException {
-        begin(transactionTimeoutMilliseconds);
+        begin(getTransactionTimeoutMilliseconds(0L));
     }
 
     public Transaction begin(long transactionTimeoutMilliseconds) throws NotSupportedException,
SystemException {
@@ -94,7 +90,7 @@
             throw new NotSupportedException("Nested Transactions are not supported");
         }
         TransactionImpl tx = new TransactionImpl(xidFactory, txnLog);
-        timeoutTimer.schedule(tx, transactionTimeoutMilliseconds == 0? this.transactionTimeoutMilliseconds:
transactionTimeoutMilliseconds);
+        timeoutTimer.schedule(tx, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds));
         threadTx.set(tx);
         ((TransactionImpl)tx).setCurrentThread(Thread.currentThread());
         return tx;
@@ -156,11 +152,11 @@
 
     //XidImporter implementation
     public Transaction importXid(Xid xid, long transactionTimeoutMilliseconds) throws XAException,
SystemException {
-        TransactionImpl tx = new TransactionImpl(xid, xidFactory, txnLog);
-        if (transactionTimeoutMilliseconds == 0) {
-            transactionTimeoutMilliseconds = this.transactionTimeoutMilliseconds;
+        if (transactionTimeoutMilliseconds < 0) {
+            throw new SystemException("transaction timeout must be positive or 0 to reset
to default");
         }
-        timeoutTimer.schedule(tx, transactionTimeoutMilliseconds);
+        TransactionImpl tx = new TransactionImpl(xid, xidFactory, txnLog);
+        timeoutTimer.schedule(tx, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds));
         return tx;
     }
 
@@ -210,6 +206,17 @@
         } catch (SystemException e) {
             throw (XAException) new XAException().initCause(e);
         }
+    }
+
+    private long getTransactionTimeoutMilliseconds(long transactionTimeoutMilliseconds) {
+        if (transactionTimeoutMilliseconds != 0) {
+            return transactionTimeoutMilliseconds;
+        }
+        Long timeout = (Long) this.transactionTimeoutMilliseconds.get();
+        if (timeout != null) {
+            return timeout.longValue();
+        }
+        return defaultTransactionTimeoutMilliseconds;
     }
 
 }

Mime
View raw message