Author: rob.stryker(a)jboss.com
Date: 2011-08-01 06:28:00 -0400 (Mon, 01 Aug 2011)
New Revision: 33408
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/JBossServerConnectionProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java
Log:
JBIDE-9421 - mbean explorer for as7
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 2011-08-01
10:13:14 UTC (rev 33407)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnection.java 2011-08-01
10:28:00 UTC (rev 33408)
@@ -170,7 +170,8 @@
}
public void connectionRemoved(IConnectionWrapper connection) {
- server.removeServerListener(this);
+ if( connection == this )
+ server.removeServerListener(this);
}
public boolean canControl() {
Modified:
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 2011-08-01
10:13:14 UTC (rev 33407)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JBossServerConnectionProvider.java 2011-08-01
10:28:00 UTC (rev 33408)
@@ -10,23 +10,24 @@
******************************************************************************/
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 javax.management.MBeanServerConnection;
-
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.jboss.ide.eclipse.as.core.ExtensionManager.IServerJMXRunnable;
-import org.jboss.ide.eclipse.as.core.ExtensionManager.IServerJMXRunner;
+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.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.tools.jmx.core.ExtensionManager;
import org.jboss.tools.jmx.core.IConnectionProvider;
@@ -34,6 +35,8 @@
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$
@@ -42,14 +45,14 @@
return (JBossServerConnectionProvider)ExtensionManager.getProvider(PROVIDER_ID);
}
- public static JBossServerConnection getConnection(IServer s) {
- return (JBossServerConnection)getProvider().findConnection(s);
+ 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 {
- JBossServerConnection c = getConnection(s);
+ IConnectionWrapper c = getConnection(s);
if( c != null )
// JMX is not installed here
c.run(r);
@@ -59,7 +62,7 @@
private ArrayList<IConnectionProviderListener> listeners =
new ArrayList<IConnectionProviderListener>();
- private HashMap<String, JBossServerConnection> idToConnection;
+ private HashMap<String, IConnectionWrapper> idToConnection;
public JBossServerConnectionProvider() {
ServerCore.addServerLifecycleListener(this);
}
@@ -68,15 +71,77 @@
return ServerConverter.getJBossServer(server) != null;
}
- protected JBossServerConnection createConnection(IServer server) {
- return new JBossServerConnection(server);
+ protected boolean requiresDefaultProvider(IServer server) {
+ if(server.getServerType().getId().equals(IJBossToolingConstants.SERVER_AS_70))
+ return true;
+ return false;
}
+ protected IConnectionWrapper createConnection(IServer server) {
+ if( !requiresDefaultProvider(server))
+ return new JBossServerConnection(server);
+ return createDefaultServerConnection(server);
+ }
+
+ protected IConnectionWrapper createDefaultServerConnection(IServer server) {
+ 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) {
+ // TODO log
+ }
+ }
+ }
+ }
+ 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())) {
- JBossServerConnection connection = createConnection(server);
+ IConnectionWrapper connection = createConnection(server);
idToConnection.put(server.getId(), connection);
}
fireAdded(idToConnection.get(server.getId()));
@@ -87,7 +152,7 @@
if( belongsHere(server)) {
getConnections();
if( !idToConnection.containsKey(server.getId())) {
- JBossServerConnection connection = createConnection(server);
+ IConnectionWrapper connection = createConnection(server);
idToConnection.put(server.getId(), connection);
}
fireAdded(idToConnection.get(server.getId()));
@@ -96,7 +161,7 @@
public void serverRemoved(IServer server) {
if( belongsHere(server)) {
- JBossServerConnection connection;
+ IConnectionWrapper connection;
if( idToConnection != null ) {
connection = idToConnection.get(server.getId());
if( connection != null ) {
@@ -122,9 +187,9 @@
// do it all on demand right now
if( idToConnection == null ) {
// load them all
- idToConnection = new HashMap<String, JBossServerConnection>();
+ idToConnection = new HashMap<String, IConnectionWrapper>();
IServer[] allServers = ServerCore.getServers();
- JBossServerConnection c;
+ IConnectionWrapper c;
for( int i = 0; i < allServers.length; i++ ) {
if( belongsHere(allServers[i])) {
c = createConnection(allServers[i]);
@@ -133,9 +198,9 @@
}
}
}
- ArrayList<JBossServerConnection> list = new
ArrayList<JBossServerConnection>();
+ ArrayList<IConnectionWrapper> list = new ArrayList<IConnectionWrapper>();
list.addAll(idToConnection.values());
- return list.toArray(new JBossServerConnection[list.size()]);
+ return list.toArray(new IConnectionWrapper[list.size()]);
}
public String getName(IConnectionWrapper wrapper) {
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 2011-08-01
10:13:14 UTC (rev 33407)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.jmx.integration/src/org/jboss/ide/eclipse/as/jmx/integration/JMXProvider.java 2011-08-01
10:28:00 UTC (rev 33408)
@@ -117,7 +117,7 @@
JBossServerConnectionProvider provider =
(JBossServerConnectionProvider)ExtensionManager.getProvider(
JBossServerConnectionProvider.PROVIDER_ID);
- JBossServerConnection connection = provider.getConnection(server);
+ IConnectionWrapper connection = provider.getConnection(server);
if( connection != null ) {
view.getCommonViewer().collapseAll();
ISelection sel = new StructuredSelection(new Object[] { connection });
Show replies by date