geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r468719 - in /geronimo/server/trunk/modules/geronimo-connector/src: main/java/org/apache/geronimo/connector/ main/java/org/apache/geronimo/connector/outbound/ test/java/org/apache/geronimo/connector/outbound/
Date Sat, 28 Oct 2006 18:37:55 GMT
Author: djencks
Date: Sat Oct 28 11:37:55 2006
New Revision: 468719

URL: http://svn.apache.org/viewvc?view=rev&rev=468719
Log:
GERONIMO-2529 track connections closed in afterCompletion better

Modified:
    geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/ConnectorTransactionContext.java
    geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
    geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java

Modified: geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/ConnectorTransactionContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/ConnectorTransactionContext.java?view=diff&rev=468719&r1=468718&r2=468719
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/ConnectorTransactionContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/ConnectorTransactionContext.java
Sat Oct 28 11:37:55 2006
@@ -26,6 +26,7 @@
 import javax.transaction.SystemException;
 
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import org.apache.geronimo.connector.outbound.TransactionCachingInterceptor;
 
 /**
  * @version $Rev$ $Date$
@@ -59,20 +60,30 @@
         return ctx;
     }
 
+    public static TransactionCachingInterceptor.ManagedConnectionInfos get(Transaction transaction,
ConnectionReleaser key) {
+        ConnectorTransactionContext ctx = get(transaction);
+        TransactionCachingInterceptor.ManagedConnectionInfos infos = ctx.getManagedConnectionInfo(key);
+        if (infos == null) {
+            infos = new TransactionCachingInterceptor.ManagedConnectionInfos();
+            ctx.setManagedConnectionInfo(key, infos);
+        }
+        return infos;
+    }
+
     private static void remove(Transaction transaction) {
         DATA_INDEX.remove(transaction);
     }
 
     private Map managedConnections;
 
-    public synchronized Object getManagedConnectionInfo(ConnectionReleaser key) {
+    private synchronized TransactionCachingInterceptor.ManagedConnectionInfos getManagedConnectionInfo(ConnectionReleaser
key) {
         if (managedConnections == null) {
             return null;
         }
-        return managedConnections.get(key);
+        return (TransactionCachingInterceptor.ManagedConnectionInfos) managedConnections.get(key);
     }
 
-    public synchronized void setManagedConnectionInfo(ConnectionReleaser key, Object info)
{
+    private synchronized void setManagedConnectionInfo(ConnectionReleaser key, TransactionCachingInterceptor.ManagedConnectionInfos
info) {
         if (managedConnections == null) {
             managedConnections = new HashMap();
         }

Modified: geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java?view=diff&rev=468719&r1=468718&r2=468719
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java
Sat Oct 28 11:37:55 2006
@@ -24,6 +24,7 @@
 import javax.resource.ResourceException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import javax.transaction.SystemException;
 
 import org.apache.geronimo.connector.ConnectorTransactionContext;
 import org.apache.geronimo.connector.ConnectionReleaser;
@@ -65,12 +66,7 @@
         // get the current transation and status... if there is a problem just assume there
is no transaction present
         Transaction transaction = TxUtil.getTransactionIfActive(transactionManager);
         if (transaction != null) {
-            ConnectorTransactionContext connectorTransactionContext = ConnectorTransactionContext.get(transaction);
-            ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) connectorTransactionContext.getManagedConnectionInfo(this);
-            if (managedConnectionInfos == null) {
-                managedConnectionInfos = new ManagedConnectionInfos();
-                connectorTransactionContext.setManagedConnectionInfo(this, managedConnectionInfos);
-            }
+            ManagedConnectionInfos managedConnectionInfos = ConnectorTransactionContext.get(transaction,
this);
             if (connectionInfo.isUnshareable()) {
                 if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo()))
{
                     next.getConnection(connectionInfo);
@@ -80,7 +76,7 @@
                 ManagedConnectionInfo managedConnectionInfo = managedConnectionInfos.getShared();
                 if (managedConnectionInfo != null) {
                     connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
-                    return;
+                    //return;
                 } else {
                     next.getConnection(connectionInfo);
                     managedConnectionInfos.setShared(connectionInfo.getManagedConnectionInfo());
@@ -97,9 +93,20 @@
             next.returnConnection(connectionInfo, connectionReturnAction);
             return;
         }
-
-        if (TxUtil.isTransactionActive(transactionManager)) {
-            return;
+        Transaction transaction;
+        try {
+            transaction = transactionManager.getTransaction();
+            if (transaction != null) {
+                if (TxUtil.isActive(transaction)) {
+                    return;
+                }
+                //We are called from an afterCompletion synchronization.  Remove the MCI
from the ManagedConnectionInfos
+                //so we don't close it twice
+                ManagedConnectionInfos managedConnectionInfos = ConnectorTransactionContext.get(transaction,
this);
+                managedConnectionInfos.remove(connectionInfo.getManagedConnectionInfo());
+            }
+        } catch (SystemException e) {
+            //ignore
         }
         internalReturn(connectionInfo, connectionReturnAction);
     }
@@ -134,7 +141,7 @@
         internalReturn(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
     }
 
-    static class ManagedConnectionInfos {
+    public static class ManagedConnectionInfos {
         private ManagedConnectionInfo shared;
         private Set unshared = Collections.EMPTY_SET;
 
@@ -159,6 +166,14 @@
 
         public boolean containsUnshared(ManagedConnectionInfo unsharedMCI) {
             return this.unshared.contains(unsharedMCI);
+        }
+
+        public void remove(ManagedConnectionInfo managedConnectionInfo) {
+            if (shared == managedConnectionInfo) {
+                shared = null;
+            } else {
+                unshared.remove(managedConnectionInfo);
+            }
         }
     }
 

Modified: geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java?view=diff&rev=468719&r1=468718&r2=468719
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
Sat Oct 28 11:37:55 2006
@@ -110,8 +110,7 @@
 
     private ManagedConnectionInfo getSharedManagedConnectionInfo(Transaction transaction)
{
         if (transaction == null) return null;
-        ConnectorTransactionContext connectorTransactionContext = ConnectorTransactionContext.get(transaction);
-        return ((TransactionCachingInterceptor.ManagedConnectionInfos)connectorTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor)).getShared();
+        return ConnectorTransactionContext.get(transaction, transactionCachingInterceptor).getShared();
     }
 
     public void testGetConnectionOutsideTransaction() throws Exception {



Mime
View raw message