You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2014/01/23 23:40:08 UTC

git commit: https://issues.apache.org/jira/browse/AMQ-4486 - rework to open/close connection arround each xaresource op so there are no leaks during periodic recovery

Updated Branches:
  refs/heads/trunk d8cd37030 -> 3826a23ed


https://issues.apache.org/jira/browse/AMQ-4486 - rework to open/close connection arround each xaresource op so there are no leaks during periodic recovery


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3826a23e
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3826a23e
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3826a23e

Branch: refs/heads/trunk
Commit: 3826a23ed5e77115170f3ac57dc2385234473f1b
Parents: d8cd370
Author: gtully <ga...@gmail.com>
Authored: Thu Jan 23 22:38:56 2014 +0000
Committer: gtully <ga...@gmail.com>
Committed: Thu Jan 23 22:38:56 2014 +0000

----------------------------------------------------------------------
 .../activemq/ra/ActiveMQResourceAdapter.java    | 33 +++++++++++---------
 .../ra/ActiveMQConnectionFactoryTest.java       |  6 ++--
 2 files changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/3826a23e/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
----------------------------------------------------------------------
diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
index 81b4703..68b2178 100644
--- a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
+++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.ra;
 
+import java.lang.reflect.Method;
 import java.net.URI;
 import java.util.HashMap;
 
@@ -102,9 +103,6 @@ public class ActiveMQResourceAdapter extends ActiveMQConnectionSupport implement
         }
     }
 
-    /**
-     * @see org.apache.activemq.ra.MessageResourceAdapter#makeConnection()
-     */
     public ActiveMQConnection makeConnection() throws JMSException {
         if( connectionFactory == null ) {
             return makeConnection(getInfo());
@@ -235,18 +233,23 @@ public class ActiveMQResourceAdapter extends ActiveMQConnectionSupport implement
      */
     public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
         try {
-            final ActiveMQConnection connection = makeConnection();
-            return new XAResource[]{new LocalAndXATransaction(new TransactionContext(connection)) {
-                public void finalize() throws Throwable {
-                    try {
-                        connection.close();
-                    } catch (Throwable ignore) {
-                    } finally {
-                        super.finalize();
-                    }
-                }
-            }};
-        } catch (JMSException e) {
+            return new XAResource[]{(XAResource)
+                    java.lang.reflect.Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{XAResource.class},
+                            new java.lang.reflect.InvocationHandler () {
+                                @Override
+                                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+                                    ActiveMQConnection connection = makeConnection();
+                                    try {
+                                        return method.invoke(new TransactionContext(connection), args);
+                                    } finally {
+                                        try {
+                                            connection.close();
+                                        } catch (Throwable ignore) {}
+                                    }
+                                }
+                            })};
+
+        } catch (Exception e) {
             throw new ResourceException(e);
         }
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/3826a23e/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
index b677170..2191148 100644
--- a/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
+++ b/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java
@@ -113,9 +113,9 @@ public class ActiveMQConnectionFactoryTest extends TestCase {
         ra.setUserName(user);
         ra.setPassword(pwd);
 
-        XAResource[] resoruces = ra.getXAResources(null);
-        assertEquals("one resource", 1, resoruces.length);
+        XAResource[] resources = ra.getXAResources(null);
+        assertEquals("one resource", 1, resources.length);
 
-        assertEquals("no pending transactions", 0, resoruces[0].recover(100).length);
+        assertEquals("no pending transactions", 0, resources[0].recover(100).length);
     }
 }