geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r503969 - in /geronimo/server/trunk/modules/geronimo-connector/src: main/java/org/apache/geronimo/connector/outbound/connectiontracking/ test/java/org/apache/geronimo/connector/outbound/connectiontracking/
Date Tue, 06 Feb 2007 03:46:03 GMT
Author: dain
Date: Mon Feb  5 19:46:02 2007
New Revision: 503969

URL: http://svn.apache.org/viewvc?view=rev&rev=503969
Log:
Fix GERONIMO-2800 when connections are closed or destroyed do not reassociate the connection
again or throw an exception.  Instead simply invoke the handle and let the handle throw the
exception.
Do not proxy DisassociatableManagedConnections since they will automatically associate on
use.

Modified:
    geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
    geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java

Modified: geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java?view=diff&rev=503969&r1=503968&r2=503969
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector/src/main/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinator.java
Mon Feb  5 19:46:02 2007
@@ -26,6 +26,7 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import javax.resource.ResourceException;
+import javax.resource.spi.DissociatableManagedConnection;
 
 import org.apache.geronimo.connector.outbound.ConnectionInfo;
 import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
@@ -110,6 +111,14 @@
                         (ConnectionTrackingInterceptor) entry.getKey();
                 Set connections = (Set) entry.getValue();
 
+                // release proxy connections
+                if (lazyConnect) {
+                    for (Iterator infoIterator = connections.iterator(); infoIterator.hasNext();)
{
+                        ConnectionInfo connectionInfo = (ConnectionInfo) infoIterator.next();
+                        releaseProxyConnection(connectionInfo);
+                    }
+                }
+
                 // use connection interceptor to dissociate connections that support disassociation
                 mcci.exit(connections);
 
@@ -194,9 +203,10 @@
             }
         }
 
-        if (lazyConnect) {
-            releaseProxyConnection(connectionInfo, connectionReturnAction);
-        }
+        // NOTE: This method is also called by DissociatableManagedConnection when a connection
has been
+        // dissociated in addition to the normal connection closed notification, but this
is not a problem
+        // because DissociatableManagedConnection are not proied so this method will have
no effect
+        closeProxyConnection(connectionInfo);
     }
 
     /**
@@ -224,6 +234,11 @@
         // if this connection already has a proxy no need to create another
         if (connectionInfo.getConnectionProxy() != null) return;
 
+        // DissociatableManagedConnection do not need to be proxied
+        if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection)
{
+            return;
+        }
+
         try {
             Object handle = connectionInfo.getConnectionHandle();
             ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(connectionTrackingInterceptor,
connectionInfo, handle);
@@ -239,27 +254,19 @@
         }
     }
 
-    private void releaseProxyConnection(ConnectionInfo connectionInfo, ConnectionReturnAction
connectionReturnAction) {
-        Object proxy = connectionInfo.getConnectionProxy();
-        if (proxy == null) {
-            proxy = proxiesByConnectionInfo.get(connectionInfo);
-        }
-        if (proxy == null) {
-            // no proxy or proxy alreayd destroyed
-            return;
+    private void releaseProxyConnection(ConnectionInfo connectionInfo) {
+        ConnectionInvocationHandler invocationHandler = getConnectionInvocationHandler(connectionInfo);
+        if (invocationHandler != null) {
+            invocationHandler.releaseHandle();
         }
+    }
 
-        ConnectionInvocationHandler invocationHandler = getConnectionInvocationHandler(proxy);
+    private void closeProxyConnection(ConnectionInfo connectionInfo) {
+        ConnectionInvocationHandler invocationHandler = getConnectionInvocationHandler(connectionInfo);
         if (invocationHandler != null) {
-            if (connectionReturnAction == ConnectionReturnAction.RETURN_HANDLE) {
-                invocationHandler.releaseHandle();
-            } else if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
-                invocationHandler.destroy();
-                proxiesByConnectionInfo.remove(connectionInfo);
-                connectionInfo.setConnectionProxy(null);
-            } else {
-                throw new IllegalArgumentException("Unknown ConnectionReturnAction " + connectionReturnAction);
-            }
+            invocationHandler.close();
+            proxiesByConnectionInfo.remove(connectionInfo);
+            connectionInfo.setConnectionProxy(null);
         }
     }
 
@@ -272,11 +279,17 @@
         return handle.getClass().getClassLoader();
     }
 
-    private static ConnectionInvocationHandler getConnectionInvocationHandler(Object handle)
{
-        if (handle == null) return null;
+    private ConnectionInvocationHandler getConnectionInvocationHandler(ConnectionInfo connectionInfo)
{
+        Object proxy = connectionInfo.getConnectionProxy();
+        if (proxy == null) {
+            proxy = proxiesByConnectionInfo.get(connectionInfo);
+        }
+
+        // no proxy or proxy already destroyed
+        if (proxy == null) return null;
 
-        if (Proxy.isProxyClass(handle.getClass())) {
-            InvocationHandler invocationHandler = Proxy.getInvocationHandler(handle);
+        if (Proxy.isProxyClass(proxy.getClass())) {
+            InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy);
             if (invocationHandler instanceof ConnectionInvocationHandler) {
                 return (ConnectionInvocationHandler) invocationHandler;
             }
@@ -287,7 +300,7 @@
     public static class ConnectionInvocationHandler implements InvocationHandler {
         private ConnectionTrackingInterceptor connectionTrackingInterceptor;
         private ConnectionInfo connectionInfo;
-        private Object handle;
+        private final Object handle;
         private boolean released = false;
 
         public ConnectionInvocationHandler(ConnectionTrackingInterceptor connectionTrackingInterceptor,
ConnectionInfo connectionInfo, Object handle) {
@@ -325,16 +338,20 @@
             released = true;
         }
 
-        public synchronized void destroy() {
+        public synchronized void close() {
             connectionTrackingInterceptor = null;
             connectionInfo = null;
-            handle = null;
+            released = true;
         }
 
         public synchronized Object getHandle() {
             if (connectionTrackingInterceptor == null) {
-                throw new IllegalStateException("Connection has been destroyed");
+                // connection has been closed... send invocations directly to the handle
+                // which will throw an exception or in some clases like JDBC connection.close()
+                // ignore the invocation
+                return handle;
             }
+
             if (released) {
                 try {
                     connectionTrackingInterceptor.reassociateConnection(connectionInfo);

Modified: geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java?view=diff&rev=503969&r1=503968&r2=503969
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector/src/test/java/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorProxyTest.java
Mon Feb  5 19:46:02 2007
@@ -27,7 +27,6 @@
 import javax.security.auth.Subject;
 import javax.resource.ResourceException;
 import javax.resource.spi.ManagedConnection;
-import javax.resource.spi.DissociatableManagedConnection;
 import javax.resource.spi.ConnectionRequestInfo;
 import javax.resource.spi.ConnectionEventListener;
 import javax.resource.spi.LocalTransaction;
@@ -118,13 +117,11 @@
         connectionTrackingCoordinator.handleReleased(key1, connectionInfo, ConnectionReturnAction.DESTROY);
         connectionTrackingCoordinator.exit(oldConnectorInstanceContext);
 
-        // verify proxy is invalid
-        try {
-            connectionProxy.getString();
-            fail("Connection was destroyed so proxy should throw an IllegalStateException");
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        // use connection which will cause it to get a new handle if it is not closed
+        ConnectionTrackingCoordinator.ConnectionInvocationHandler invocationHandler = (ConnectionTrackingCoordinator.ConnectionInvocationHandler)
Proxy.getInvocationHandler(connectionProxy);
+        assertEquals("connection.getString()", "ConnectionString", connectionProxy.getString());
+        assertTrue("Proxy should be connected", invocationHandler.isReleased());
+        assertSame("Expected connection.getUnmanaged() to be original connection", connection,
connection.getUnmanaged());
     }
 
     public void testReassociateConnection() throws Exception {
@@ -186,13 +183,11 @@
         infos = (Set) connectionManagerMap.get(key1);
         assertNull("Expected no connection set for key1", infos);
 
-        // verify proxy is invalid
-        try {
-            connectionProxy.getString();
-            fail("Connection was destroyed so proxy should throw an IllegalStateException");
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        // use connection which will cause it to get a new handle if it is not closed
+        assertEquals("connection.getString()", "ConnectionString", connectionProxy.getString());
+        assertTrue("Proxy should be connected", invocationHandler.isReleased());
+        assertSame("Expected connection.getUnmanaged() to be original connection", connection,
connection.getUnmanaged());
+
     }
 
     // some code calls the release method using a freshly constructed ContainerInfo without
a proxy
@@ -238,11 +233,10 @@
         ConnectionTrackingCoordinator.ConnectionInvocationHandler invocationHandler = (ConnectionTrackingCoordinator.ConnectionInvocationHandler)
Proxy.getInvocationHandler(connectionProxy);
         assertTrue("Proxy should be disconnected", invocationHandler.isReleased());
 
-        // use connection to cause it to get a new handle
+        // use connection which will cause it to get a new handle if it is not closed
         assertEquals("connection.getString()", "ConnectionString", connectionProxy.getString());
-        assertFalse("Proxy should be connected", invocationHandler.isReleased());
+        assertTrue("Proxy should be connected", invocationHandler.isReleased());
         assertSame("Expected connection.getUnmanaged() to be original connection", connection,
connection.getUnmanaged());
-        assertNotSame("Expected connection to not be original connection", connection, connectionProxy);
 
         // exit outer component context
         connectionTrackingCoordinator.exit(oldConnectorInstanceContext1);
@@ -250,41 +244,22 @@
         // proxy should be disconnected
         assertTrue("Proxy should be disconnected", invocationHandler.isReleased());
 
+        // connection should not be in context
+        connectionManagerMap = componentContext.getConnectionManagerMap();
+        infos = (Set) connectionManagerMap.get(key1);
+        assertNull("Expected no connection set for key1", infos);
+
         // enter again
         oldConnectorInstanceContext1 = connectionTrackingCoordinator.enter(componentContext);
         assertNull("Expected old component context to be null", oldConnectorInstanceContext1);
 
-        // use connection to cause it to get a new handle
-        assertEquals("connection.getString()", "ConnectionString", connectionProxy.getString());
-        assertSame("Expected connection.getUnmanaged() to be original connection", connection,
connection.getUnmanaged());
-        assertNotSame("Expected connection to not be original connection", connection, connectionProxy);
-
-        // simulate handle destroy due to a event listener, which won't hav the proxy
-        connectionTrackingCoordinator.handleReleased(key1, createConnectionInfo(), ConnectionReturnAction.DESTROY);
-
-        // verify proxy is invalid
-        try {
-            connectionProxy.getString();
-            fail("Connection was destroyed so proxy should throw an IllegalStateException");
-        } catch (IllegalStateException e) {
-            // expected
-        }
-
         // exit context
         connectionTrackingCoordinator.exit(oldConnectorInstanceContext1);
 
-        // connection should not be in context
-        connectionManagerMap = componentContext.getConnectionManagerMap();
-        infos = (Set) connectionManagerMap.get(key1);
-        assertNull("Expected no connection set for key1", infos);
-
-        // verify proxy is invalid
-        try {
-            connectionProxy.getString();
-            fail("Connection was destroyed so proxy should throw an IllegalStateException");
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        // use connection which will cause it to get a new handle if it is not closed
+        assertEquals("connection.getString()", "ConnectionString", connectionProxy.getString());
+        assertTrue("Proxy should be connected", invocationHandler.isReleased());
+        assertSame("Expected connection.getUnmanaged() to be original connection", connection,
connection.getUnmanaged());
     }
 
 
@@ -330,7 +305,7 @@
         }
     }
 
-    public static class MockManagedConnection implements ManagedConnection, DissociatableManagedConnection
{
+    public static class MockManagedConnection implements ManagedConnection {
            public Object getConnection(Subject defaultSubject, ConnectionRequestInfo connectionRequestInfo)
throws ResourceException {
                return null;
            }



Mime
View raw message