activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuconic <...@git.apache.org>
Subject [GitHub] activemq-artemis issue #1809: ARTEMIS-1415 potential JMS bridge conn leak
Date Tue, 23 Jan 2018 18:53:35 GMT
Github user clebertsuconic commented on the issue:

    https://github.com/apache/activemq-artemis/pull/1809
  
    do you mind if I ammend this method as:
    
    ```java
       private Connection createConnection(final String username,
                                           final String password,
                                           final ConnectionFactoryFactory cff,
                                           final String clientID,
                                           final boolean isXA,
                                           boolean isSource) throws Exception {
          Connection conn = null;
    
          try {
    
             Object cf = cff.createConnectionFactory();
    
             if (cf instanceof ActiveMQConnectionFactory && registry != null) {
                registry.register(XARecoveryConfig.newConfig((ActiveMQConnectionFactory) cf,
username, password, null));
             }
    
             if (qualityOfServiceMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE &&
!(cf instanceof XAConnectionFactory)) {
                throw new IllegalArgumentException("Connection factory must be XAConnectionFactory");
             }
    
             if (username == null) {
                if (isXA) {
                   if (JMSBridgeImpl.trace) {
                      ActiveMQJMSBridgeLogger.LOGGER.trace("Creating an XA connection");
                   }
                   conn = ((XAConnectionFactory) cf).createXAConnection();
                } else {
                   if (JMSBridgeImpl.trace) {
                      ActiveMQJMSBridgeLogger.LOGGER.trace("Creating a non XA connection");
                   }
                   conn = ((ConnectionFactory) cf).createConnection();
                }
             } else {
                if (isXA) {
                   if (JMSBridgeImpl.trace) {
                      ActiveMQJMSBridgeLogger.LOGGER.trace("Creating an XA connection");
                   }
                   conn = ((XAConnectionFactory) cf).createXAConnection(username, password);
                } else {
                   if (JMSBridgeImpl.trace) {
                      ActiveMQJMSBridgeLogger.LOGGER.trace("Creating a non XA connection");
                   }
                   conn = ((ConnectionFactory) cf).createConnection(username, password);
                }
             }
    
             if (clientID != null) {
                conn.setClientID(clientID);
             }
    
             boolean ha = false;
             BridgeFailoverListener failoverListener = null;
    
             if (conn instanceof ActiveMQConnection) {
                ActiveMQConnectionFactory activeMQCF = (ActiveMQConnectionFactory) cf;
                ha = activeMQCF.isHA();
    
                if (ha) {
                   ActiveMQConnection activeMQConn = (ActiveMQConnection) conn;
                   failoverListener = new BridgeFailoverListener(isSource);
                   activeMQConn.setFailoverListener(failoverListener);
                }
             }
    
             conn.setExceptionListener(new BridgeExceptionListener(ha, failoverListener, isSource));
    
             return conn;
          } catch (JMSException e) {
             try {
                if (conn != null) {
                   conn.close();
                }
             } catch (Throwable ignored) {
             }
             throw e;
          }
       }
    ```


---

Mime
View raw message