You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/09/04 13:04:59 UTC

[tomee] 04/07: Fix TOMEE-2506 and add Jonathan Gallimore's JMS Context Tests

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 532e737a2c5430063a49efcc13e61ec25b0aa341
Author: Jonathan S. Fisher <jo...@emoneyusa.com>
AuthorDate: Tue Sep 3 14:28:48 2019 -0500

    Fix TOMEE-2506 and add Jonathan Gallimore's JMS Context Tests
---
 .../openejb/resource/AutoConnectionTracker.java    | 77 +++++++++++-----------
 1 file changed, 40 insertions(+), 37 deletions(-)

diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java
index b5080ab..bb7b10f 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/AutoConnectionTracker.java
@@ -109,52 +109,55 @@ public class AutoConnectionTracker implements ConnectionTracker {
     @Override
     public void handleObtained(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo, final boolean reassociate) throws ResourceException {
         if (txMgr != null && registry != null) {
-            TransactionImpl currentTx = null;
             try {
-                currentTx = (TransactionImpl) txMgr.getTransaction();
-            } catch (SystemException | ClassCastException e) {
-                //ignore
-            }
-
-            if (currentTx != null) {
-                Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY);
-                if (txConnections == null) {
-                    txConnections = new HashMap<>();
-                    registry.putResource(KEY, txConnections);
-                }
+                final TransactionImpl currentTx = (TransactionImpl) txMgr.getTransaction();
+                if (currentTx != null) {
+                    Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry
+                            .getResource(KEY);
+                    if (txConnections == null) {
+                        txConnections = new HashMap<ManagedConnectionInfo, Map<ConnectionInfo, Object>>();
+                        registry.putResource(KEY, txConnections);
+                    }
 
-                Map<ConnectionInfo, Object> connectionObjects = txConnections.computeIfAbsent(connectionInfo.getManagedConnectionInfo(), k -> new HashMap<>());
+                    Map<ConnectionInfo, Object> connectionObjects = txConnections.get(connectionInfo.getManagedConnectionInfo());
+                    if (connectionObjects == null) {
+                        connectionObjects = new HashMap<ConnectionInfo, Object>();
+                        txConnections.put(connectionInfo.getManagedConnectionInfo(), connectionObjects);
+                    }
 
-                connectionObjects.put(connectionInfo, connectionInfo.getConnectionProxy());
+                    connectionObjects.put(connectionInfo, connectionInfo.getConnectionProxy());
 
-                registry.registerInterposedSynchronization(new Synchronization() {
-                    @Override
-                    public void beforeCompletion() {
-                        final Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) registry.getResource(KEY);
-                        if (txConnections != null && txConnections.size() > 0) {
+                    registry.registerInterposedSynchronization(new Synchronization() {
+                        @Override
+                        public void beforeCompletion() {
+                        }
 
-                            for (final Map.Entry<ManagedConnectionInfo, Map<ConnectionInfo, Object>> managedConnectionInfoMapEntry : txConnections.entrySet()) {
-                                final StringBuilder sb = new StringBuilder();
-                                final Collection<ConnectionInfo> connectionInfos = managedConnectionInfoMapEntry.getValue().keySet();
-                                for (final ConnectionInfo connectionInfo : connectionInfos) {
-                                    sb.append("\n  ").append("Connection handle opened at ").append(stackTraceToString(connectionInfo.getTrace().getStackTrace()));
+                        @Override
+                        public void afterCompletion(final int status) {
+                            final Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>> txConnections = (Map<ManagedConnectionInfo, Map<ConnectionInfo, Object>>) currentTx
+                                    .getResource(KEY);
+                            if (txConnections != null && txConnections.size() > 0) {
+                                for (final ManagedConnectionInfo managedConnectionInfo : txConnections.keySet()) {
+                                    final StringBuilder sb = new StringBuilder();
+                                    final Collection<ConnectionInfo> connectionInfos = txConnections.get(managedConnectionInfo)
+                                            .keySet();
+                                    for (final ConnectionInfo connectionInfo : connectionInfos) {
+                                        sb.append("\n  ").append("Connection handle opened at ")
+                                                .append(stackTraceToString(connectionInfo.getTrace().getStackTrace()));
+                                    }
+                                    logger.warning("Transaction complete, but connection still has handles associated: "
+                                            + managedConnectionInfo + "\nAbandoned connection information: " + sb.toString());
                                 }
-
-                                logger.warning("Transaction complete, but connection still has handles associated: " + managedConnectionInfoMapEntry.getKey() + "\nAbandoned connection information: " + sb);
                             }
                         }
-                    }
-
-                    @Override
-                    public void afterCompletion(final int status) {
-
-                    }
-                });
+                    });
+                }
+            } catch (SystemException | ClassCastException e) {
+                // ignore
+            }
+            if (!reassociate) {
+                proxyConnection(interceptor, connectionInfo);
             }
-        }
-
-        if (! reassociate) {
-            proxyConnection(interceptor, connectionInfo);
         }
     }