[jbosstools-commits] JBoss Tools SVN: r40722 - branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed May 2 15:31:49 EDT 2012


Author: max.andersen at jboss.com
Date: 2012-05-02 15:31:48 -0400 (Wed, 02 May 2012)
New Revision: 40722

Modified:
   branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java
   branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java
Log:
JBIDE-11064 patch from rob about keeping connection around long enough for run to actually work plus made sure map with connectors does not grow indefinitly

Modified: branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java
===================================================================
--- branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java	2012-05-02 19:28:15 UTC (rev 40721)
+++ branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java	2012-05-02 19:31:48 UTC (rev 40722)
@@ -42,9 +42,11 @@
 
 	private String user;
 	private String pass;
+	private Map<MBeanServerConnection, JMXConnector> connectionToConnector;
 	protected void initializeEnvironment(IServer s, String user, String pass) throws CredentialException {
 		this.user = user;
 		this.pass = pass;
+		this.connectionToConnector = new HashMap<MBeanServerConnection, JMXConnector>();
 	}
 	
 	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 */ }
+		}
+	}
+
 }

Modified: branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java
===================================================================
--- branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java	2012-05-02 19:28:15 UTC (rev 40721)
+++ branches/jbosstools-3.3.0.Beta3/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java	2012-05-02 19:31:48 UTC (rev 40722)
@@ -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);
 	}



More information about the jbosstools-commits mailing list