Index: plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java =================================================================== --- plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java (revision 40622) +++ plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java (working copy) @@ -42,9 +42,11 @@ private String user; private String pass; + private Map connectionToConnector; protected void initializeEnvironment(IServer s, String user, String pass) throws CredentialException { this.user = user; this.pass = pass; + this.connectionToConnector = new HashMap(); } protected MBeanServerConnection createConnection(IServer s) throws Exception { @@ -64,6 +66,7 @@ try { connector = JMXConnectorFactory.connect(new JMXServiceURL(url), environment); MBeanServerConnection connection = connector.getMBeanServerConnection(); + this.connectionToConnector.put(connection, connector); return connection; } catch(IOException ioe) { return null; @@ -71,12 +74,17 @@ IStatus stat = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Runtime Exception contacting JBoss instance. Please ensure your server is up and exposes its management ports via the -Djboss.bind.address.management=yourwebsite.com system property", re); throw new JMXException(stat); - } finally { - if( connector != null ) { - try { - connector.close(); - } catch(Exception e) { /* Ignore */ } - } } } + + protected void cleanupConnection(IServer server, MBeanServerConnection connection) { + super.cleanupConnection(server, connection); + if( connectionToConnector.get(connection) != null ) { + try { + connectionToConnector.remove(connection); + connectionToConnector.get(connection).close(); + } catch(Exception e) { /* Ignore */ } + } + } + } Index: plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java =================================================================== --- plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java (revision 40622) +++ plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java (working copy) @@ -132,9 +132,10 @@ .getContextClassLoader(); ClassLoader newLoader = getProvider2().getClassloaderRepository().getClassLoader(s); Thread.currentThread().setContextClassLoader(newLoader); + MBeanServerConnection connection = null; try { initializeEnvironment(s, user, pass); - MBeanServerConnection connection = createConnection(s); + connection = createConnection(s); if( connection != null ) { r.run(connection); } @@ -146,6 +147,7 @@ throw new JMXException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Error connecting to remote JMX. Please ensure your server is properly configured for JMX access.", e)); } finally { + cleanupConnection(s, connection); getProvider2().getClassloaderRepository().removeConcerned(s, r); Thread.currentThread().setContextClassLoader(currentLoader); } @@ -162,6 +164,10 @@ return null; } + protected void cleanupConnection(IServer server, MBeanServerConnection connection) { + // Do nothing, provide subclasses ability + } + protected void initializeEnvironment(IServer s, String user, String pass) throws CredentialException { JMXUtil.setCredentials(s,user,pass); }