activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject [23/25] 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
Date Thu, 20 Mar 2014 15:59:18 GMT
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/a1645a42
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/a1645a42
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/a1645a42

Branch: refs/heads/activemq-5.9
Commit: a1645a429c8c8bacff0c14068f7a573980b2d7c5
Parents: 3987c37
Author: gtully <gary.tully@gmail.com>
Authored: Thu Jan 23 22:38:56 2014 +0000
Committer: Hadrian Zbarcea <hadrian@apache.org>
Committed: Thu Mar 20 11:34:48 2014 -0400

----------------------------------------------------------------------
 .../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/a1645a42/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/a1645a42/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);
     }
 }


Mime
View raw message