[jbosstools-commits] JBoss Tools SVN: r39794 - in trunk: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7 and 6 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 23 07:21:03 EDT 2012


Author: rob.stryker at jboss.com
Date: 2012-03-23 07:21:02 -0400 (Fri, 23 Mar 2012)
New Revision: 39794

Added:
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AS71JMXClassLoaderRepository.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AbstractJBossJMXConnectionProvider.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss3To6ConnectionProvider.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss70ConnectionProvider.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ConnectionProvider.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossJMXConnectionProviderModel.java
Removed:
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java
Modified:
   trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/extendedproperties/ServerExtendedProperties.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7Server.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/plugin.xml
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/Activator.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerJMXRunner.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXClassLoaderRepository.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXPoller.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXSafeRunner.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXServerLifecycleListener.java
   trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/IConnectionWrapper.java
   trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/providers/DefaultConnectionWrapper.java
   trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeBuilder.java
   trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeUtils.java
   trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/ObjectNameNode.java
   trunk/jmx/tests/org.jboss.tools.jmx.core.test/src/org/jboss/tools/jmx/core/test/MockConnectionWrapper.java
Log:
JBIDE-11064 - see comments on jira

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/extendedproperties/ServerExtendedProperties.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/extendedproperties/ServerExtendedProperties.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/extendedproperties/ServerExtendedProperties.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,3 +1,13 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
 package org.jboss.ide.eclipse.as.core.server.internal.extendedproperties;
 
 import org.eclipse.core.runtime.IAdaptable;

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7Server.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7Server.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7Server.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -24,6 +24,7 @@
 import org.eclipse.wst.server.core.IRuntime;
 import org.jboss.ide.eclipse.as.core.extensions.polling.WebPortPoller;
 import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
 import org.jboss.ide.eclipse.as.core.util.ExpressionResolverUtil;
 import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
 import org.jboss.ide.eclipse.as.core.util.ServerUtil;
@@ -43,7 +44,7 @@
 			setAttribute(IJBossToolingConstants.STARTUP_POLLER_KEY, JBoss7ManagerServicePoller.POLLER_ID);
 	}
 	public boolean hasJMXProvider() {
-		return false;
+		return getExtendedProperties().getJMXProviderType() != ServerExtendedProperties.JMX_NULL_PROVIDER;
 	}
 	
 	public int getManagementPort() {

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/plugin.xml	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/plugin.xml	2012-03-23 11:21:02 UTC (rev 39794)
@@ -10,8 +10,14 @@
    <extension
          point="org.jboss.tools.jmx.core.MBeanServerConnectionProvider">
       <connectionProvider
-            class="org.jboss.ide.eclipse.as.jmx.integration.JBossServerConnectionProvider">
+            class="org.jboss.ide.eclipse.as.jmx.integration.JBoss3To6ConnectionProvider">
       </connectionProvider>
+      <connectionProvider
+            class="org.jboss.ide.eclipse.as.jmx.integration.JBoss70ConnectionProvider">
+      </connectionProvider>
+      <connectionProvider
+            class="org.jboss.ide.eclipse.as.jmx.integration.JBoss71ConnectionProvider">
+      </connectionProvider>
    </extension>
 
    <extension

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AS71JMXClassLoaderRepository.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AS71JMXClassLoaderRepository.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AS71JMXClassLoaderRepository.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,46 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
+
+public class AS71JMXClassLoaderRepository extends JMXClassLoaderRepository {
+	protected URLClassLoader createClassLoader(IServer s) throws MalformedURLException {
+		IRuntime rt = s.getRuntime();
+		IPath loc = rt.getLocation();
+		IPath clientJar = findClientJar(loc);
+		if( clientJar != null ) {
+			URL url = clientJar.toFile().toURI().toURL();
+			URLClassLoader loader = new URLClassLoader(new URL[] { url, }, 
+					Thread.currentThread().getContextClassLoader());
+			return loader;
+		}
+		return null;
+	}
+	
+	public IPath findClientJar(IPath root) {
+		IPath p2 = root.append(IJBossRuntimeResourceConstants.BIN)
+				.append(IJBossRuntimeResourceConstants.CLIENT);
+		String[] children = p2.toFile().list();
+		for( int i = 0; i < children.length; i++ ) {
+			if( children[i].endsWith(".jar") && children[i].startsWith("jboss-client-"))
+				return p2.append(children[i]);
+		}
+		return null;
+	}
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AbstractJBossJMXConnectionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AbstractJBossJMXConnectionProvider.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/AbstractJBossJMXConnectionProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,180 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerLifecycleListener;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.tools.jmx.core.IConnectionProvider;
+import org.jboss.tools.jmx.core.IConnectionProviderListener;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
+
+public abstract class AbstractJBossJMXConnectionProvider implements IConnectionProvider, IServerLifecycleListener  {
+
+	private ArrayList<IConnectionProviderListener> listeners = 
+		new ArrayList<IConnectionProviderListener>();
+	
+	private HashMap<String, IConnectionWrapper> idToConnection;
+	public AbstractJBossJMXConnectionProvider() {
+		ServerCore.addServerLifecycleListener(this);
+	}
+	
+	protected abstract boolean belongsHere(IServer server);
+	public abstract String getId();
+	protected abstract IConnectionWrapper createConnection(IServer server);
+	public abstract String getName(IConnectionWrapper wrapper);
+
+	public void serverAdded(IServer server) {
+		if( belongsHere(server)) {
+			getConnections();
+			if( !idToConnection.containsKey(server.getId())) {
+				IConnectionWrapper connection = createConnection(server);
+				idToConnection.put(server.getId(), connection);
+				if( connection != null )
+					fireAdded(idToConnection.get(server.getId()));
+			}
+		}
+	}
+
+	public void serverChanged(IServer server) {
+		if( belongsHere(server)) {
+			getConnections();
+			IConnectionWrapper connection = createConnection(server);
+			idToConnection.put(server.getId(), connection);
+			if( connection != null )
+				fireAdded(idToConnection.get(server.getId()));
+		}
+	}
+
+	public void serverRemoved(IServer server) {
+		if( belongsHere(server)) {
+			IConnectionWrapper connection;
+			if( idToConnection != null ) {
+				connection = idToConnection.get(server.getId());
+				if( connection != null ) {
+					idToConnection.remove(server.getId());
+					fireRemoved(connection);
+				}
+			} else {
+				// hasn't been initialized yet
+				getConnections();
+				
+				// but now its missing from the collection, so make one up
+				IConnectionWrapper dummy = createConnection(server);
+				
+				// Make sure we don't fire a removal for a connection that doesn't exist
+				if( dummy != null )
+					fireRemoved(dummy);
+			}
+		}
+	}
+
+	public IConnectionWrapper findConnection(IServer s) {
+		getConnections();
+		return idToConnection.get(s.getId());
+	}
+	
+	public IConnectionWrapper[] getConnections() {
+		// do it all on demand right now
+		if( idToConnection == null ) {
+			// load them all
+			idToConnection = new HashMap<String, IConnectionWrapper>();
+			IServer[] allServers = ServerCore.getServers();
+			IConnectionWrapper c;
+			for( int i = 0; i < allServers.length; i++ ) {
+				if( belongsHere(allServers[i])) {
+					c = createConnection(allServers[i]);
+					if( c != null ) 
+						idToConnection.put(allServers[i].getId(), c);
+				}
+			}
+		} 
+		ArrayList<IConnectionWrapper> list = new ArrayList<IConnectionWrapper>();
+		list.addAll(idToConnection.values());
+		return list.toArray(new IConnectionWrapper[list.size()]);
+	}
+	
+	public void addListener(IConnectionProviderListener listener) {
+		if( !listeners.contains(listener))
+			listeners.add(listener);
+	}
+
+	public void removeListener(IConnectionProviderListener listener) {
+		listeners.remove(listener);
+	}
+	
+	void fireAdded(IConnectionWrapper wrapper) {
+		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
+			try {
+				i.next().connectionAdded(wrapper);
+			} catch(RuntimeException re) {
+				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
+			}
+	}
+
+	void fireChanged(IConnectionWrapper wrapper) {
+		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
+			try {
+				i.next().connectionChanged(wrapper);
+			} catch(RuntimeException re) {
+				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
+			}
+	}
+
+	void fireRemoved(IConnectionWrapper wrapper) {
+		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
+			try {
+				i.next().connectionRemoved(wrapper);
+			} catch(RuntimeException re) {
+				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
+			}
+	}
+
+	public boolean canCreate() {
+		return false;
+	}
+
+	@SuppressWarnings(value={"unchecked"})
+	public IConnectionWrapper createConnection(Map map) throws CoreException {
+		throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, Messages.NotSupported, null));
+	}
+
+	public void addConnection(IConnectionWrapper connection) {
+		// Not Supported
+	}
+	public void removeConnection(IConnectionWrapper connection) {
+		// Not Supported
+	}
+	public boolean canDelete(IConnectionWrapper wrapper) {
+		return false;
+	}
+	public void connectionChanged(IConnectionWrapper connection) {
+		// do nothing
+	}
+	
+	public boolean hasClassloaderRepository() {
+		return false;
+	}
+	
+	public JMXClassLoaderRepository getClassloaderRepository() {
+		return null;
+	}
+}

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/Activator.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/Activator.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/Activator.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 

Copied: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss3To6ConnectionProvider.java (from rev 39642, trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss3To6ConnectionProvider.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss3To6ConnectionProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,57 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ExtendedServerPropertiesAdapterFactory;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.JBossExtendedProperties;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
+
+public class JBoss3To6ConnectionProvider extends AbstractJBossJMXConnectionProvider{
+	public static final String PROVIDER_ID = "org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider"; //$NON-NLS-1$
+	
+	private JMXClassLoaderRepository repository;
+	public JBoss3To6ConnectionProvider() {
+		super();
+		repository = new JMXClassLoaderRepository();
+		JBossJMXConnectionProviderModel.getDefault().registerProvider(ServerExtendedProperties.JMX_AS_3_TO_6_PROVIDER, this);
+	}
+	
+	public String getName(IConnectionWrapper wrapper) {
+		if( wrapper instanceof JBossServerConnection) {
+			return ((JBossServerConnection)wrapper).getName();
+		}
+		return null;
+	}
+
+	protected boolean belongsHere(IServer server) {
+		JBossExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getJBossExtendedProperties(server);
+		int type = props == null ? -1 : props.getJMXProviderType();
+		return type == JBossExtendedProperties.JMX_AS_3_TO_6_PROVIDER;
+	}
+	
+	protected IConnectionWrapper createConnection(IServer server) {
+		return new JBossServerConnection(server);
+	}
+	
+	public String getId() {
+		return PROVIDER_ID;
+	}
+	public boolean hasClassloaderRepository() {
+		return true;
+	}
+	
+	public JMXClassLoaderRepository getClassloaderRepository() {
+		return repository;
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss70ConnectionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss70ConnectionProvider.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss70ConnectionProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,117 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.server.internal.ExtendedServerPropertiesAdapterFactory;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.JBossExtendedProperties;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
+import org.jboss.tools.jmx.core.IConnectionProviderListener;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
+import org.jboss.tools.jmx.core.providers.DefaultConnectionWrapper;
+import org.jboss.tools.jmx.core.providers.MBeanServerConnectionDescriptor;
+
+public class JBoss70ConnectionProvider extends AbstractJBossJMXConnectionProvider{
+	public static final String PROVIDER_ID = "org.jboss.ide.eclipse.as.core.extensions.jmx.JBoss70ConnectionProvider"; //$NON-NLS-1$
+	
+	public JBoss70ConnectionProvider() {
+		super();
+		JBossJMXConnectionProviderModel.getDefault().registerProvider(ServerExtendedProperties.JMX_DEFAULT_PROVIDER, this);
+	}
+
+	public String getName(IConnectionWrapper wrapper) {
+		if( wrapper instanceof JBossServerConnection) {
+			return ((JBossServerConnection)wrapper).getName();
+		}
+		return null;
+	}
+
+	protected boolean belongsHere(IServer server) {
+		JBossExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getJBossExtendedProperties(server);
+		int type = props == null ? -1 : props.getJMXProviderType();
+		return type == JBossExtendedProperties.JMX_DEFAULT_PROVIDER;
+	}
+	
+	protected IConnectionWrapper createConnection(IServer server) {
+		return createDefaultServerConnection(server);
+	}
+	
+	protected IConnectionWrapper createDefaultServerConnection(IServer server) {
+		// This situation is not even fully supported and requires revisiting
+		String SIMPLE_PREFIX = "service:jmx:rmi:///jndi/rmi://"; //$NON-NLS-1$  constants are in jmx.ui feh
+		String SIMPLE_SUFFIX = "/jmxrmi"; //$NON-NLS-1$
+		String host = server.getHost();
+		String port = "1090"; // TODO fix hard code
+		String url = SIMPLE_PREFIX + host + ":" + port + SIMPLE_SUFFIX; //$NON-NLS-1$ 
+
+		MBeanServerConnectionDescriptor desc = new
+				MBeanServerConnectionDescriptor(server.getName(), url, "", "");
+		try {
+			return new ExtendedDefaultConnectionWrapper(desc, server);
+		} catch( MalformedURLException murle) {
+			// TODO log  
+			return null;
+		}
+	}
+	
+	private class ExtendedDefaultConnectionWrapper extends DefaultConnectionWrapper 
+	 	implements IServerListener, IConnectionProviderListener {
+		private IServer server;
+		public ExtendedDefaultConnectionWrapper(
+				MBeanServerConnectionDescriptor descriptor, IServer server)
+				throws MalformedURLException {
+			super(descriptor);
+			this.server = server;
+			server.addServerListener(this);
+		}
+		public void serverChanged(ServerEvent event) {
+			int eventKind = event.getKind();
+			if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
+				// server change event
+				if ((eventKind & ServerEvent.STATE_CHANGE) != 0) {
+					boolean started = event.getServer().getServerState() == IServer.STATE_STARTED;
+					try {
+						if( started )
+							connect();
+						else
+							disconnect();
+					} catch( IOException ioe) {
+						if( started ) 
+							JBossServerCorePlugin.log(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Error connecting to this server's JMX service: " + event.getServer().getName(), ioe));
+						else
+							JBossServerCorePlugin.log(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Error disconnecting from this server's JMX service: " + event.getServer().getName(), ioe));
+					}
+				}
+			}
+		}
+		public void connectionAdded(IConnectionWrapper connection) {
+		}
+		public void connectionRemoved(IConnectionWrapper connection) {
+			if( connection == this )
+				server.removeServerListener(this);
+		}
+		public void connectionChanged(IConnectionWrapper connection) {
+		}
+	}
+
+	public String getId() {
+		return PROVIDER_ID;
+	}
+	
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ConnectionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ConnectionProvider.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ConnectionProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,58 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ExtendedServerPropertiesAdapterFactory;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.JBossExtendedProperties;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
+
+public class JBoss71ConnectionProvider extends AbstractJBossJMXConnectionProvider{
+	public static final String PROVIDER_ID = "org.jboss.ide.eclipse.as.core.extensions.jmx.JBoss71ServerConnectionProvider"; //$NON-NLS-1$
+	
+	private JMXClassLoaderRepository repository;
+	public JBoss71ConnectionProvider() {
+		super();
+		repository = new AS71JMXClassLoaderRepository();
+		JBossJMXConnectionProviderModel.getDefault().registerProvider(ServerExtendedProperties.JMX_AS_710_PROVIDER, this);
+	}
+
+	
+	public String getName(IConnectionWrapper wrapper) {
+		if( wrapper instanceof JBossServerConnection) {
+			return ((JBossServerConnection)wrapper).getName();
+		}
+		return null;
+	}
+
+	protected boolean belongsHere(IServer server) {
+		JBossExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getJBossExtendedProperties(server);
+		int type = props == null ? -1 : props.getJMXProviderType();
+		return type == JBossExtendedProperties.JMX_AS_710_PROVIDER;
+	}
+	
+	protected IConnectionWrapper createConnection(IServer server) {
+		return new JBoss71ServerConnection(server);
+	}
+	
+	public String getId() {
+		return PROVIDER_ID;
+	}
+	
+	public boolean hasClassloaderRepository() {
+		return true;
+	}
+	
+	public JMXClassLoaderRepository getClassloaderRepository() {
+		return repository;
+	}
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBoss71ServerConnection.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,52 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.jmx.integration.JMXUtil.CredentialException;
+import org.jboss.tools.jmx.core.ExtensionManager;
+import org.jboss.tools.jmx.core.IConnectionProvider;
+
+public class JBoss71ServerConnection extends JBossServerConnection {
+	public JBoss71ServerConnection(IServer server) {
+		super(server);
+	}
+
+	protected void initializeEnvironment(IServer s, String user, String pass) throws CredentialException {
+		// Do nothing
+	}
+	
+	public IConnectionProvider getProvider() {
+		return ExtensionManager.getProvider(JBoss71ConnectionProvider.PROVIDER_ID);
+	}
+
+	protected MBeanServerConnection createConnection(IServer s) throws Exception  {
+		try {
+			String url = "service:jmx:remoting-jmx://" + s.getHost() + ":9999";  // TODO externalize this? 
+			Map<String, String[]> environment = new HashMap<String, String[]>();
+			JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(url), environment);
+			MBeanServerConnection connection = connector.getMBeanServerConnection();
+			return connection;
+		} catch(Exception e ) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossJMXConnectionProviderModel.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossJMXConnectionProviderModel.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossJMXConnectionProviderModel.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -0,0 +1,74 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+package org.jboss.ide.eclipse.as.jmx.integration;
+
+import java.util.HashMap;
+
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
+import org.jboss.tools.jmx.core.IJMXRunnable;
+import org.jboss.tools.jmx.core.JMXException;
+
+public class JBossJMXConnectionProviderModel {
+	// Singleton
+	private static JBossJMXConnectionProviderModel instance;
+	public static JBossJMXConnectionProviderModel getDefault() {
+		if( instance == null )
+			instance = new JBossJMXConnectionProviderModel();
+		return instance;
+	}
+	
+	private HashMap<Integer, AbstractJBossJMXConnectionProvider> providers;
+	public JBossJMXConnectionProviderModel() {
+		providers = new HashMap<Integer, AbstractJBossJMXConnectionProvider>();
+//		providers.put(ServerExtendedProperties.JMX_NULL_PROVIDER, null);
+//		providers.put(ServerExtendedProperties.JMX_AS_3_TO_6_PROVIDER, new JBoss3To6ConnectionProvider());
+//		providers.put(ServerExtendedProperties.JMX_DEFAULT_PROVIDER, new JBoss70ConnectionProvider());
+//		providers.put(ServerExtendedProperties.JMX_AS_710_PROVIDER, null);		
+	}
+	
+	public void registerProvider(int type, AbstractJBossJMXConnectionProvider provider) {
+		providers.put(type, provider);
+	}
+	
+	public AbstractJBossJMXConnectionProvider getProvider(int type) {
+		return providers.get(type);
+	}
+
+	
+	public IConnectionWrapper getConnection(IServer s) {
+		AbstractJBossJMXConnectionProvider provider = getProvider(s);
+		if( provider == null )
+			return null;
+		return provider.findConnection(s);
+	}
+
+	public AbstractJBossJMXConnectionProvider getProvider(IServer s) {
+		ServerExtendedProperties properties = (ServerExtendedProperties) s.loadAdapter(ServerExtendedProperties.class, null);
+		if( properties == null )
+			return null;
+		
+		int i = properties.getJMXProviderType();
+		AbstractJBossJMXConnectionProvider provider = providers.get(i);
+		return provider;
+	}
+	
+	// Run this action on the server. 
+	// If the connection doesn't exist, make a new one
+	public void run(IServer s, IJMXRunnable r) throws JMXException {
+		IConnectionWrapper c = getConnection(s);
+		if( c != null )
+			// JMX is not installed here
+			c.run(r);
+	}
+
+}

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -11,8 +11,12 @@
 package org.jboss.ide.eclipse.as.jmx.integration;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Properties;
 
 import javax.management.MBeanServerConnection;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -24,7 +28,9 @@
 import org.eclipse.wst.server.core.ServerEvent;
 import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
 import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
 import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.jmx.integration.JMXUtil.CredentialException;
 import org.jboss.tools.jmx.core.ExtensionManager;
 import org.jboss.tools.jmx.core.IConnectionProvider;
 import org.jboss.tools.jmx.core.IConnectionProviderListener;
@@ -45,7 +51,7 @@
 		this.isConnected = false;
 		this.isLoading = false;
 		checkState(); // prime the state
-		((JBossServerConnectionProvider)getProvider()).addListener(this);
+		((AbstractJBossJMXConnectionProvider)getProvider()).addListener(this);
 		server.addServerListener(this);
 	}
 	
@@ -58,8 +64,12 @@
 	}
 
 	public IConnectionProvider getProvider() {
-		return ExtensionManager.getProvider(JBossServerConnectionProvider.PROVIDER_ID);
+		return ExtensionManager.getProvider(JBoss3To6ConnectionProvider.PROVIDER_ID);
 	}
+	
+	protected AbstractJBossJMXConnectionProvider getProvider2() {
+		return (AbstractJBossJMXConnectionProvider)getProvider();
+	}
 
 	public Root getRoot() {
 		return root;
@@ -70,7 +80,7 @@
 			isLoading = true;
 			// saferunner just adds itself as a concern and then removes, after each call.
 			// This will ensure the classloader does not need to make multiple loads
-			JMXClassLoaderRepository.getDefault().addConcerned(server, this);
+			getProvider2().getClassloaderRepository().addConcerned(server, this);
 			try {
 				if( root == null ) {
 					root = NodeUtils.createObjectNameTree(this, monitor);
@@ -80,7 +90,7 @@
 				JBossServerCorePlugin.getDefault().getLog().log(status);
 				root = new ErrorRoot();
 			} finally {
-				JMXClassLoaderRepository.getDefault().removeConcerned(server, this);
+				getProvider2().getClassloaderRepository().removeConcerned(server, this);
 				isLoading = false;
 			}
 		}
@@ -91,12 +101,66 @@
 	}
 
 	public void run(IJMXRunnable runnable) throws JMXException {
-		// do nothing if the server is down.
-		if( server.getServerState() != IServer.STATE_STARTED ) 
-			return;
-		JMXSafeRunner.run(server, runnable);
+		run(runnable, new HashMap<String, String>());
 	}
 	
+	protected void run(IJMXRunnable runnable, boolean force) throws JMXException {
+		HashMap<String, String> map = new HashMap<String,String>();
+		map.put("force", "true");
+		run(runnable, map);
+	}
+	
+	// Potential api upstream in jmx ?
+	public void run(IJMXRunnable runnable, HashMap<String, String> prefs) throws JMXException {
+		boolean force = prefs.get("force") == null ? false : Boolean.parseBoolean(prefs.get("force"));
+		if( force || server.getServerState() == IServer.STATE_STARTED) {
+			String defaultUser = ServerConverter.getJBossServer(server).getUsername();
+			String defaultPass = ServerConverter.getJBossServer(server).getPassword();
+			String user = prefs.get("user") == null ? defaultUser : prefs.get("user");
+			String pass = prefs.get("pass") == null ? defaultPass : prefs.get("pass");
+			run(server, runnable, user, pass);
+		}
+	}
+	
+	public void run(IServer s, IJMXRunnable r, String user, String pass) throws JMXException {
+		// Mark the event
+		getProvider2().getClassloaderRepository().addConcerned(s, r);
+		
+		// Set the classloader
+		ClassLoader currentLoader = Thread.currentThread()
+				.getContextClassLoader();
+		ClassLoader newLoader = getProvider2().getClassloaderRepository().getClassLoader(s);
+		Thread.currentThread().setContextClassLoader(newLoader);
+		try {
+			initializeEnvironment(s, user, pass);
+			MBeanServerConnection connection = createConnection(s);
+			if( connection != null ) {
+				r.run(connection);
+			}
+		} catch( Exception e ) {  
+			throw new JMXException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, 
+					e.getMessage() == null ? e.getClass().getName() : e.getMessage(), e));
+		} finally {
+			getProvider2().getClassloaderRepository().removeConcerned(s, r);
+			Thread.currentThread().setContextClassLoader(currentLoader);
+		}
+	}
+
+	protected MBeanServerConnection createConnection(IServer s) throws Exception {
+		Properties p = JMXUtil.getDefaultProperties(s);
+		InitialContext ic = new InitialContext(p);
+		Object obj = ic.lookup(IJBossRuntimeConstants.RMIAdaptor);
+		ic.close();
+		if (obj instanceof MBeanServerConnection) {
+			return (MBeanServerConnection)obj;
+		}
+		return null;
+	}
+	
+	protected void initializeEnvironment(IServer s, String user, String pass) throws CredentialException {
+		JMXUtil.setCredentials(s,user,pass);
+	}
+	
 	public String getName() {
 		return server.getName();
 	}
@@ -127,21 +191,21 @@
 		IDeployableServer jbs = ServerConverter.getDeployableServer(server);
 		if( server.getServerState() == IServer.STATE_STARTED && jbs != null && jbs.hasJMXProvider()) {
 			try {
-				JMXSafeRunner.run(server, new IJMXRunnable() {
+				run(new IJMXRunnable() {
 					public void run(MBeanServerConnection connection)
 							throws Exception {
 						// Do nothing, just see if the connection worked
 					} 
-				});
+				}, true);
 				if( !isConnected ) {
 					isConnected = true;
-					((JBossServerConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
+					((AbstractJBossJMXConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
 				}
 			} catch( Exception jmxe ) {
 				// I thought i was connected but I'm not. 
 				if( isConnected ) {
 					isConnected = false;
-					((JBossServerConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
+					((AbstractJBossJMXConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
 				}
 			}
 		} else {
@@ -149,7 +213,7 @@
 			if( isConnected ) {
 				// server is not in STATE_STARTED, but thinks its connected
 				isConnected = false;
-				((JBossServerConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
+				((AbstractJBossJMXConnectionProvider)getProvider()).fireChanged(JBossServerConnection.this);
 			}
 		}
 	}

Deleted: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,291 +0,0 @@
-/******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
- * Distributed under license by Red Hat, Inc. All rights reserved. 
- * This program is made available under the terms of the 
- * Eclipse Public License v1.0 which accompanies this distribution, 
- * and is available at http://www.eclipse.org/legal/epl-v10.html 
- * 
- * Contributors: 
- * Red Hat, Inc. - initial API and implementation 
- ******************************************************************************/ 
-package org.jboss.ide.eclipse.as.jmx.integration;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerLifecycleListener;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.ServerEvent;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.server.internal.ExtendedServerPropertiesAdapterFactory;
-import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.JBossExtendedProperties;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.core.util.ServerUtil;
-import org.jboss.tools.jmx.core.ExtensionManager;
-import org.jboss.tools.jmx.core.IConnectionProvider;
-import org.jboss.tools.jmx.core.IConnectionProviderListener;
-import org.jboss.tools.jmx.core.IConnectionWrapper;
-import org.jboss.tools.jmx.core.IJMXRunnable;
-import org.jboss.tools.jmx.core.JMXException;
-import org.jboss.tools.jmx.core.providers.DefaultConnectionWrapper;
-import org.jboss.tools.jmx.core.providers.MBeanServerConnectionDescriptor;
-
-public class JBossServerConnectionProvider implements IConnectionProvider, IServerLifecycleListener {
-	public static final String PROVIDER_ID = "org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider"; //$NON-NLS-1$
-	
-	public static JBossServerConnectionProvider getProvider() {
-		return (JBossServerConnectionProvider)ExtensionManager.getProvider(PROVIDER_ID);
-	}
-	
-	public static IConnectionWrapper getConnection(IServer s) {
-		return getProvider().findConnection(s);
-	}
-	
-	// Run this action on the server. 
-	// If the connection doesn't exist, make a new one
-	public static void run(IServer s, IJMXRunnable r) throws JMXException {
-		IConnectionWrapper c = getConnection(s);
-		if( c != null )
-			// JMX is not installed here
-			c.run(r);
-	}
-	
-	
-	private ArrayList<IConnectionProviderListener> listeners = 
-		new ArrayList<IConnectionProviderListener>();
-	
-	private HashMap<String, IConnectionWrapper> idToConnection;
-	public JBossServerConnectionProvider() {
-		ServerCore.addServerLifecycleListener(this);
-	}
-
-	protected boolean belongsHere(IServer server) {
-		return ServerConverter.getJBossServer(server) != null;
-	}
-	
-	protected boolean requiresDefaultProvider(IServer server) {
-		if(ServerUtil.isJBoss7(server))
-			return true;
-		return false;
-	}
-	
-	protected IConnectionWrapper createConnection(IServer server) {
-		JBossExtendedProperties props = ExtendedServerPropertiesAdapterFactory.getJBossExtendedProperties(server);
-		int type = props == null ? -1 : props.getJMXProviderType();
-		switch(type) {
-		case JBossExtendedProperties.JMX_AS_3_TO_6_PROVIDER:
-			return new JBossServerConnection(server);
-		case JBossExtendedProperties.JMX_DEFAULT_PROVIDER:
-			return createDefaultServerConnection(server);
-		// TODO add as7.1 logic here when we figure it out
-		default:
-			return null;
-		}
-	}
-	
-	protected IConnectionWrapper createDefaultServerConnection(IServer server) {
-		// This situation is not even fully supported and requires revisiting
-		String SIMPLE_PREFIX = "service:jmx:rmi:///jndi/rmi://"; //$NON-NLS-1$  constants are in jmx.ui feh
-		String SIMPLE_SUFFIX = "/jmxrmi"; //$NON-NLS-1$
-		String host = server.getHost();
-		String port = "1090"; // TODO fix hard code
-		String url = SIMPLE_PREFIX + host + ":" + port + SIMPLE_SUFFIX; //$NON-NLS-1$ 
-
-		MBeanServerConnectionDescriptor desc = new
-				MBeanServerConnectionDescriptor(server.getName(), url, "", "");
-		try {
-			return new ExtendedDefaultConnectionWrapper(desc, server);
-		} catch( MalformedURLException murle) {
-			// TODO log  
-			return null;
-		}
-	}
-	
-	private class ExtendedDefaultConnectionWrapper extends DefaultConnectionWrapper 
-	 	implements IServerListener, IConnectionProviderListener {
-		private IServer server;
-		public ExtendedDefaultConnectionWrapper(
-				MBeanServerConnectionDescriptor descriptor, IServer server)
-				throws MalformedURLException {
-			super(descriptor);
-			this.server = server;
-			server.addServerListener(this);
-		}
-		public void serverChanged(ServerEvent event) {
-			int eventKind = event.getKind();
-			if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
-				// server change event
-				if ((eventKind & ServerEvent.STATE_CHANGE) != 0) {
-					boolean started = event.getServer().getServerState() == IServer.STATE_STARTED;
-					try {
-						if( started )
-							connect();
-						else
-							disconnect();
-					} catch( IOException ioe) {
-						if( started ) 
-							JBossServerCorePlugin.log(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Error connecting to this server's JMX service: " + event.getServer().getName(), ioe));
-						else
-							JBossServerCorePlugin.log(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, "Error disconnecting from this server's JMX service: " + event.getServer().getName(), ioe));
-					}
-				}
-			}
-		}
-		public void connectionAdded(IConnectionWrapper connection) {
-		}
-		public void connectionRemoved(IConnectionWrapper connection) {
-			if( connection == this )
-				server.removeServerListener(this);
-		}
-		public void connectionChanged(IConnectionWrapper connection) {
-		}
-	}
-	
-	public void serverAdded(IServer server) {
-		if( belongsHere(server)) {
-			getConnections();
-			if( !idToConnection.containsKey(server.getId())) {
-				IConnectionWrapper connection = createConnection(server);
-				idToConnection.put(server.getId(), connection);
-				if( connection != null )
-					fireAdded(idToConnection.get(server.getId()));
-			}
-		}
-	}
-
-	public void serverChanged(IServer server) {
-		if( belongsHere(server)) {
-			getConnections();
-			IConnectionWrapper connection = createConnection(server);
-			idToConnection.put(server.getId(), connection);
-			if( connection != null )
-				fireAdded(idToConnection.get(server.getId()));
-		}
-	}
-
-	public void serverRemoved(IServer server) {
-		if( belongsHere(server)) {
-			IConnectionWrapper connection;
-			if( idToConnection != null ) {
-				connection = idToConnection.get(server.getId());
-				if( connection != null ) {
-					idToConnection.remove(server.getId());
-					fireRemoved(connection);
-				}
-			} else {
-				// hasn't been initialized yet
-				getConnections();
-				
-				// but now its missing from the collection, so make one up
-				IConnectionWrapper dummy = createConnection(server);
-				
-				// Make sure we don't fire a removal for a connection that doesn't exist
-				if( dummy != null )
-					fireRemoved(dummy);
-			}
-		}
-	}
-
-	public IConnectionWrapper findConnection(IServer s) {
-		getConnections();
-		return idToConnection.get(s.getId());
-	}
-	
-	public IConnectionWrapper[] getConnections() {
-		// do it all on demand right now
-		if( idToConnection == null ) {
-			// load them all
-			idToConnection = new HashMap<String, IConnectionWrapper>();
-			IServer[] allServers = ServerCore.getServers();
-			IConnectionWrapper c;
-			for( int i = 0; i < allServers.length; i++ ) {
-				if( belongsHere(allServers[i])) {
-					c = createConnection(allServers[i]);
-					if( c != null ) 
-						idToConnection.put(allServers[i].getId(), c);
-				}
-			}
-		} 
-		ArrayList<IConnectionWrapper> list = new ArrayList<IConnectionWrapper>();
-		list.addAll(idToConnection.values());
-		return list.toArray(new IConnectionWrapper[list.size()]);
-	}
-	
-	public String getName(IConnectionWrapper wrapper) {
-		if( wrapper instanceof JBossServerConnection) {
-			return ((JBossServerConnection)wrapper).getName();
-		}
-		return null;
-	}
-
-	public String getId() {
-		return PROVIDER_ID;
-	}
-	
-	public void addListener(IConnectionProviderListener listener) {
-		if( !listeners.contains(listener))
-			listeners.add(listener);
-	}
-
-	public void removeListener(IConnectionProviderListener listener) {
-		listeners.remove(listener);
-	}
-	
-	void fireAdded(IConnectionWrapper wrapper) {
-		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
-			try {
-				i.next().connectionAdded(wrapper);
-			} catch(RuntimeException re) {
-				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
-			}
-	}
-
-	void fireChanged(IConnectionWrapper wrapper) {
-		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
-			try {
-				i.next().connectionChanged(wrapper);
-			} catch(RuntimeException re) {
-				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
-			}
-	}
-
-	void fireRemoved(IConnectionWrapper wrapper) {
-		for(Iterator<IConnectionProviderListener> i = listeners.iterator(); i.hasNext();)
-			try {
-				i.next().connectionRemoved(wrapper);
-			} catch(RuntimeException re) {
-				// Intentionally ignore. This is just to protect against a bad implementer blowing away the stack
-			}
-	}
-	public boolean canCreate() {
-		return false;
-	}
-
-	@SuppressWarnings(value={"unchecked"})
-	public IConnectionWrapper createConnection(Map map) throws CoreException {
-		throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, Messages.NotSupported, null));
-	}
-
-	public void addConnection(IConnectionWrapper connection) {
-		// Not Supported
-	}
-	public void removeConnection(IConnectionWrapper connection) {
-		// Not Supported
-	}
-	public boolean canDelete(IConnectionWrapper wrapper) {
-		return false;
-	}
-	public void connectionChanged(IConnectionWrapper connection) {
-		// do nothing
-	}
-}

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerJMXRunner.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerJMXRunner.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerJMXRunner.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -30,7 +30,7 @@
 			}
 		};
 		try {
-			JBossServerConnectionProvider.run(server, runnable2);
+			JBossJMXConnectionProviderModel.getDefault().run(server, runnable2);
 		} catch(JMXException jmxe) {
 			// TODO wrap and log
 			throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, jmxe.getMessage(), jmxe));
@@ -38,10 +38,14 @@
 	}
 
 	public void beginTransaction(IServer server, Object lock) {
-		JMXClassLoaderRepository.getDefault().addConcerned(server, lock);
+		AbstractJBossJMXConnectionProvider provider = JBossJMXConnectionProviderModel.getDefault().getProvider(server);
+		if( provider != null && provider.hasClassloaderRepository())
+			provider.getClassloaderRepository().addConcerned(server, lock);
 	}
 
 	public void endTransaction(IServer server, Object lock) {
-		JMXClassLoaderRepository.getDefault().removeConcerned(server, lock);
+		AbstractJBossJMXConnectionProvider provider = JBossJMXConnectionProviderModel.getDefault().getProvider(server);
+		if( provider != null && provider.hasClassloaderRepository())
+			provider.getClassloaderRepository().removeConcerned(server, lock);
 	}
 }

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXClassLoaderRepository.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXClassLoaderRepository.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXClassLoaderRepository.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -24,7 +24,7 @@
 import org.eclipse.wst.server.core.IServer;
 import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
 import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
 
 /**
  * A repository for classloaders that relate to servers, 
@@ -35,14 +35,6 @@
  *
  */
 public class JMXClassLoaderRepository {
-	protected static JMXClassLoaderRepository instance;
-	public static JMXClassLoaderRepository getDefault() {
-		if( instance == null ) {
-			instance = new JMXClassLoaderRepository();
-		}
-		return instance;
-	}
-	
 	protected HashMap<String, ClassLoader> idToLoader;
 	protected HashMap<String, ArrayList<Object>> idToConcerned;
 	protected JMXClassLoaderRepository() {
@@ -107,12 +99,7 @@
 	 */
 	protected void loadClassLoader(IServer s) {
 		try {
-			IRuntime rt = s.getRuntime();
-			IPath loc = rt.getLocation();
-			URL url = loc.append(IJBossServerConstants.CLIENT).append(IJBossServerConstants.JBOSSALL_CLIENT_JAR)
-					.toFile().toURI().toURL();
-			URLClassLoader loader = new URLClassLoader(new URL[] { url, }, 
-					Thread.currentThread().getContextClassLoader());
+			URLClassLoader loader = createClassLoader(s);
 			idToLoader.put(s.getId(), loader);
 		} catch (MalformedURLException murle) {
 			JBossServerCorePlugin.getDefault().getLog().log(
@@ -121,6 +108,17 @@
 		}
 	}
 
+	protected URLClassLoader createClassLoader(IServer s) throws MalformedURLException {
+		IRuntime rt = s.getRuntime();
+		IPath loc = rt.getLocation();
+		URL url = loc.append(IJBossRuntimeResourceConstants.CLIENT)
+				.append(IJBossRuntimeResourceConstants.JBOSSALL_CLIENT_JAR)
+				.toFile().toURI().toURL();
+		URLClassLoader loader = new URLClassLoader(new URL[] { url, }, 
+				Thread.currentThread().getContextClassLoader());
+		return loader;
+	}
+	
 	/**
 	 * Are there any concerned citizens for this server?
 	 * @param server

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXPoller.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXPoller.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXPoller.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -25,6 +25,7 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.ExtensionManager.IServerJMXRunnable;
 import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
 import org.jboss.ide.eclipse.as.core.Messages;
 import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
@@ -64,16 +65,13 @@
 	private RequiresInfoException requiresInfoException = null;
 	private Properties requiredPropertiesReturned = null;
 
-	private JMXPollerRunnable runnable;
-	private JMXSafeRunner runner;
-	
 	public void beginPolling(IServer server, boolean expectedState) throws PollingException {
 		ceFound = nnfeFound = startingFound = canceled = done = false;
 		this.server = server;
 		launchJMXPoller();
 	}
 
-	private static class JMXPollerRunnable implements IJMXRunnable {
+	private static class JMXPollerRunnable implements IJMXRunnable,IServerJMXRunnable {
 		private boolean result;
 		public void run(MBeanServerConnection connection) throws Exception {
 			Object attInfo = connection.getAttribute(
@@ -85,9 +83,11 @@
 	
 	private class PollerRunnable implements Runnable {
 		public void run() {
-			JMXClassLoaderRepository.getDefault().addConcerned(server, this);
-			runnable = new JMXPollerRunnable();
-			runner = new JMXSafeRunner(server);
+			JBossServerJMXRunner runner2 = new JBossServerJMXRunner();
+			runner2.beginTransaction(server, this);
+
+			JMXPollerRunnable runnable = new JMXPollerRunnable();
+			JMXSafeRunner runner = new JMXSafeRunner(server);
 			while( !done && !canceled) {
 				try {
 					runner.run(runnable);
@@ -100,7 +100,7 @@
 						log(s);
 					}
 				} catch(CoreException ce) {
-					handleException(ce.getCause());
+					handleException(ce.getCause(), runner);
 				} 
 
 				try { 
@@ -109,10 +109,10 @@
 					// Intentionally ignore
 				}
 			}
-			JMXClassLoaderRepository.getDefault().removeConcerned(server, this);
+			runner2.endTransaction(server, this);
 		}
 		
-		protected void handleException(Throwable t) {
+		protected void handleException(Throwable t, final JMXSafeRunner runner) {
 			if( t instanceof SecurityException ) {
 				synchronized(this) {
 					if( !waitingForCredentials ) {
@@ -251,11 +251,12 @@
 	}
 
 	public IStatus getCurrentStateSynchronous(IServer server) {
-		JMXClassLoaderRepository.getDefault().addConcerned(server, this);
+		JBossServerJMXRunner runner = new JBossServerJMXRunner();
+		runner.beginTransaction(server, this);
 		JMXPollerRunnable runnable2 = new JMXPollerRunnable();
-		JMXSafeRunner runner2 = new JMXSafeRunner(server);
+
 		try {
-			runner2.run(runnable);
+			runner.run(server, runnable2);
 			int started2 = runnable2.result ? STATE_STARTED : STATE_TRANSITION;
 			if( started2 == STATE_STARTED ) {
 				Status s = new Status(IStatus.OK, Activator.PLUGIN_ID, 
@@ -265,7 +266,7 @@
 		} catch(CoreException ce) {
 			// No need to return the specifics of the exception. Just note we could not connect. 
 		} finally {
-			JMXClassLoaderRepository.getDefault().removeConcerned(server, this);
+			runner.endTransaction(server, this);
 		}
 		Status s = new Status(IStatus.INFO, Activator.PLUGIN_ID, 
 				"JMX Poller did not find a running server on " + server.getHost());

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -41,7 +41,6 @@
 import org.jboss.ide.eclipse.as.core.util.ServerUtil;
 import org.jboss.ide.eclipse.as.ui.JBossServerUISharedImages;
 import org.jboss.ide.eclipse.as.ui.UIUtil;
-import org.jboss.tools.jmx.core.ExtensionManager;
 import org.jboss.tools.jmx.core.IConnectionWrapper;
 import org.jboss.tools.jmx.ui.internal.views.navigator.JMXNavigator;
 import org.jboss.tools.jmx.ui.internal.views.navigator.MBeanExplorerContentProvider;
@@ -125,10 +124,7 @@
 					if (view != null) {
 						Display.getDefault().asyncExec(new Runnable() { 
 							public void run() {
-								JBossServerConnectionProvider provider = 
-										(JBossServerConnectionProvider)ExtensionManager.getProvider(
-												JBossServerConnectionProvider.PROVIDER_ID);
-								IConnectionWrapper connection = provider.getConnection(server);
+								IConnectionWrapper connection = JBossJMXConnectionProviderModel.getDefault().getConnection(server);
 								if( connection != null ) {
 									view.getCommonViewer().collapseAll();
 									ISelection sel = new StructuredSelection(new Object[] { connection });
@@ -150,7 +146,7 @@
 		}
 		public Object[] getChildren(Object parentElement) {
 			if( parentElement instanceof IServer ) {
-				Object sel = JBossServerConnectionProvider.getConnection((IServer)parentElement);
+				Object sel = JBossJMXConnectionProviderModel.getDefault().getConnection((IServer)parentElement);
 				if( sel != null )
 					return new Object[] { sel };
 			}

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXSafeRunner.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXSafeRunner.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXSafeRunner.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -1,5 +1,5 @@
 /******************************************************************************* 
- * Copyright (c) 2011 Red Hat, Inc. 
+ * Copyright (c) 2012 Red Hat, Inc. 
  * Distributed under license by Red Hat, Inc. All rights reserved. 
  * This program is made available under the terms of the 
  * Eclipse Public License v1.0 which accompanies this distribution, 
@@ -10,18 +10,13 @@
  ******************************************************************************/ 
 package org.jboss.ide.eclipse.as.jmx.integration;
 
-import java.util.Properties;
+import java.util.HashMap;
 
-import javax.management.MBeanServerConnection;
-import javax.naming.InitialContext;
-
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
 import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.tools.jmx.core.ExtensionManager;
+import org.jboss.tools.jmx.core.IConnectionWrapper;
 import org.jboss.tools.jmx.core.IJMXRunnable;
 import org.jboss.tools.jmx.core.JMXException;
 
@@ -42,7 +37,7 @@
 		this.pass = pass;
 	}
 	
-	public  void run(IJMXRunnable r) throws CoreException {
+	public void run(IJMXRunnable r) throws CoreException {
 		run(server,r,user,pass);
 	}
 	
@@ -53,29 +48,14 @@
 	}
 	
 	public static void run(IServer s, IJMXRunnable r, String user, String pass) throws JMXException {
-		JMXClassLoaderRepository.getDefault().addConcerned(s, r);
-		ClassLoader currentLoader = Thread.currentThread()
-				.getContextClassLoader();
-		ClassLoader newLoader = JMXClassLoaderRepository.getDefault()
-				.getClassLoader(s);
-		Thread.currentThread().setContextClassLoader(newLoader);
-		InitialContext ic = null;
-		try {
-			JMXUtil.setCredentials(s,user,pass);
-			Properties p = JMXUtil.getDefaultProperties(s);
-			ic = new InitialContext(p);
-			Object obj = ic.lookup(IJBossRuntimeConstants.RMIAdaptor);
-			ic.close();
-			if (obj instanceof MBeanServerConnection) {
-				MBeanServerConnection connection = (MBeanServerConnection) obj;
-				r.run(connection);
-			}
-		} catch( Exception e ) {  
-			throw new JMXException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, 
-					e.getMessage() == null ? e.getClass().getName() : e.getMessage(), e));
-		} finally {
-			JMXClassLoaderRepository.getDefault().removeConcerned(s, r);
-			Thread.currentThread().setContextClassLoader(currentLoader);
+		ExtensionManager.getProviders(); // todo clean up, this is here to ensure it's initialized 
+		IConnectionWrapper c = JBossJMXConnectionProviderModel.getDefault().getConnection(s);
+		if( c != null ) {
+			HashMap<String, String> prefs = new HashMap<String, String>();
+			prefs.put("force", "true");
+			prefs.put("user", user);
+			prefs.put("pass", pass);
+			c.run(r, prefs);
 		}
 	}
 

Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXServerLifecycleListener.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXServerLifecycleListener.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXServerLifecycleListener.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -59,7 +59,7 @@
 			}
 		};
 		try {
-			JBossServerConnectionProvider.run(server, r);
+			JBossJMXConnectionProviderModel.getDefault().run(server, r);
 		} catch( JMXException jmxe ) {
 			IStatus s = jmxe.getStatus();
 			IStatus newStatus = new Status(s.getSeverity(), s.getPlugin(), IEventCodes.ADD_DEPLOYMENT_FOLDER_FAIL, 

Modified: trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/IConnectionWrapper.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/IConnectionWrapper.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/IConnectionWrapper.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -11,6 +11,7 @@
 package org.jboss.tools.jmx.core;
 
 import java.io.IOException;
+import java.util.HashMap;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,5 +39,22 @@
 	 * @return
 	 */
 	public Root getRoot();
+	
+	/**
+	 * Run this runnable 
+	 * @param runnable
+	 * @throws JMXException
+	 */
 	public void run(IJMXRunnable runnable) throws JMXException;
+	
+	/**
+	 * Run this runnable, but pass in a map full of preferences 
+	 * that may contribute to the setup 
+	 * 
+	 * @param runnable
+	 * @param prefs
+	 * @throws JMXException
+	 */
+	 public void run(IJMXRunnable runnable, HashMap<String, String> prefs) throws JMXException;
+	
 }

Modified: trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/providers/DefaultConnectionWrapper.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/providers/DefaultConnectionWrapper.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/providers/DefaultConnectionWrapper.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -120,4 +120,10 @@
 			throw new JMXException(s);
 		}
 	}
+
+	@Override
+	public void run(IJMXRunnable runnable, HashMap<String, String> prefs)
+			throws JMXException {
+		run(runnable);
+	}
 }

Modified: trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeBuilder.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeBuilder.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeBuilder.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -7,6 +7,7 @@
  *******************************************************************************/
 package org.jboss.tools.jmx.core.tree;
 
+import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
 import org.jboss.tools.jmx.core.IConnectionWrapper;
@@ -20,6 +21,10 @@
     }
 
     public static void addToTree(Node root, ObjectName on) {
+    	addToTree(root, on, null);
+    }
+    
+    public static void addToTree(Node root, ObjectName on, MBeanServerConnection mbsc) {
         Node node = buildDomainNode(root, on.getDomain());
         String keyPropertyListString = on.getKeyPropertyListString();
         String[] properties = keyPropertyListString.split(","); //$NON-NLS-1$
@@ -29,7 +34,7 @@
             String value = property.substring(property.indexOf('=') + 1,
                     property.length());
             if (i == properties.length - 1) {
-                node = buildObjectNameNode(node, key, value, on);
+                node = buildObjectNameNode(node, key, value, on, mbsc);
             } else {
                 node = buildPropertyNode(node, key, value);
             }
@@ -58,7 +63,12 @@
 
     static Node buildObjectNameNode(Node parent, String key, String value,
             ObjectName on) {
-        Node n = new ObjectNameNode(parent, key, value, on);
+    	return buildObjectNameNode(parent, key, value, on, null);
+    }
+    
+    static Node buildObjectNameNode(Node parent, String key, String value,
+            ObjectName on, MBeanServerConnection mbsc) {
+        Node n = new ObjectNameNode(parent, key, value, on, mbsc);
         if (parent != null) {
             return parent.addChildren(n);
         }

Modified: trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeUtils.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeUtils.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/NodeUtils.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -59,7 +59,7 @@
 		        Iterator iter = beanInfo.iterator();
 		        while (iter.hasNext()) {
 		            ObjectName on = (ObjectName) iter.next();
-		            NodeBuilder.addToTree(_root[0], on);
+		            NodeBuilder.addToTree(_root[0], on, connection);
 		        	subMon.worked(100);
 		        }
 		        subMon.done();

Modified: trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/ObjectNameNode.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/ObjectNameNode.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/tree/ObjectNameNode.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -39,7 +39,31 @@
     	}
     	wrapper = array[0];
     }
+    
+    public ObjectNameNode(Node parent, String key, String value, ObjectName on, MBeanServerConnection mbsc) {
+        super(parent, key, value);
+        Root root = getRoot(parent);
+        IConnectionWrapper connectionWrapper = root.getConnection();
+        this.on = on;
+    	final MBeanInfoWrapper[] array = new MBeanInfoWrapper[1];
+    	final ObjectName on2 = on;
+    	try {
+        	if( mbsc != null ) 
+        		wrapper = new MBeanInfoWrapper(on2, mbsc.getMBeanInfo(on2), mbsc, ObjectNameNode.this);
+        	else {
+		    	connectionWrapper.run(new IJMXRunnable() {
+		    		public void run(MBeanServerConnection mbsc) throws Exception {
+						array[0] = new MBeanInfoWrapper(on2, mbsc.getMBeanInfo(on2), mbsc, ObjectNameNode.this);
+		    		}
+		    	});
+        	}
+    	} catch( Exception e ) {
+    		// TODO FIX THIS
+    	}
+    	wrapper = array[0];
+    }
 
+
     public ObjectName getObjectName() {
         return on;
     }

Modified: trunk/jmx/tests/org.jboss.tools.jmx.core.test/src/org/jboss/tools/jmx/core/test/MockConnectionWrapper.java
===================================================================
--- trunk/jmx/tests/org.jboss.tools.jmx.core.test/src/org/jboss/tools/jmx/core/test/MockConnectionWrapper.java	2012-03-23 11:16:00 UTC (rev 39793)
+++ trunk/jmx/tests/org.jboss.tools.jmx.core.test/src/org/jboss/tools/jmx/core/test/MockConnectionWrapper.java	2012-03-23 11:21:02 UTC (rev 39794)
@@ -11,6 +11,7 @@
 package org.jboss.tools.jmx.core.test;
 
 import java.io.IOException;
+import java.util.HashMap;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -51,4 +52,8 @@
 	public void loadRoot(IProgressMonitor monitor) {
 	}
 
+	public void run(IJMXRunnable runnable, HashMap<String, String> prefs)
+			throws JMXException {
+	}
+
 }



More information about the jbosstools-commits mailing list