Author: rob.stryker(a)jboss.com
Date: 2007-08-21 17:04:36 -0400 (Tue, 21 Aug 2007)
New Revision: 3264
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java
Log:
Improved error reporting for polling.
Preparation for JBIDE-400
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java 2007-08-21
19:52:47 UTC (rev 3263)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java 2007-08-21
21:04:36 UTC (rev 3264)
@@ -4,7 +4,7 @@
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
-* This is free software; you can redistribute it and/or modify it
+ * This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
@@ -21,7 +21,9 @@
*/
package org.jboss.ide.eclipse.as.core.runtime.server.polling;
+import java.io.IOException;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
@@ -30,10 +32,18 @@
import java.util.Date;
import java.util.Properties;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.naming.CommunicationException;
import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -52,21 +62,21 @@
public static final String TYPE_TERMINATED =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_TERMINATED";
public static final String TYPE_RESULT =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_RESULT";
-
+
public static final int STATE_STARTED = 1;
public static final int STATE_STOPPED = 0;
public static final int STATE_TRANSITION = -1;
-
- private boolean expectedState;
- private int started;
+
+ private int started;
private boolean canceled;
private boolean done;
private IServer server;
private PollingException pollingException = null;
-
+
private EventLogTreeItem event;
- public void beginPolling(IServer server, boolean expectedState, PollThread pt) {
- this.expectedState = expectedState;
+
+ public void beginPolling(IServer server, boolean expectedState,
+ PollThread pt) {
this.canceled = false;
this.done = false;
this.server = server;
@@ -76,101 +86,164 @@
private class PollerRunnable implements Runnable {
public void run() {
- ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader currentLoader = Thread.currentThread()
+ .getContextClassLoader();
ClassLoader twiddleLoader = getClassLoader();
- if( twiddleLoader != null ) {
+ if( pollingException != null ) {done = true; return;}
+ if (twiddleLoader != null) {
int port = ServerConverter.getJBossServer(server).getJNDIPort();
-
+
Thread.currentThread().setContextClassLoader(twiddleLoader);
Properties props = new Properties();
- props.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
-
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
- props.put("java.naming.provider.url","jnp://" +
server.getHost() + ":" + port);
-
- setCredentials();
-
- while( !done && !canceled ) {
+ props.put("java.naming.factory.initial",
+ "org.jnp.interfaces.NamingContextFactory");
+ props.put("java.naming.factory.url.pkgs",
+ "org.jboss.naming:org.jnp.interfaces");
+ props.put("java.naming.provider.url", "jnp://"
+ + server.getHost() + ":" + port);
+
+ setCredentials();
+ if( pollingException != null ) {done = true; return;}
+
+ Exception failingException = null;
+ while (!done && !canceled) {
InitialContext ic;
try {
ic = new InitialContext(props);
- Object obj = ic.lookup("jmx/invoker/RMIAdaptor");
- ic.close();
- if( obj instanceof MBeanServerConnection ) {
- MBeanServerConnection connection = (MBeanServerConnection)obj;
- Object attInfo = connection.getAttribute(new
ObjectName("jboss.system:type=Server"), "Started");
- boolean b = ((Boolean)attInfo).booleanValue();
- started = b ? STATE_STARTED : STATE_TRANSITION;
- if( b && expectedState )
- done = true;
- }
- } catch( SecurityException se ) {
- pollingException = new PollingSecurityException("Security Exception: " +
se.getMessage());
+ Object obj = ic.lookup("jmx/invoker/RMIAdaptor");
+ ic.close();
+ if (obj instanceof MBeanServerConnection) {
+ MBeanServerConnection connection = (MBeanServerConnection) obj;
+ Object attInfo = connection.getAttribute(
+ new ObjectName("jboss.system:type=Server"),
+ "Started");
+ boolean b = ((Boolean) attInfo).booleanValue();
+ started = b ? STATE_STARTED : STATE_TRANSITION;
+ done = b;
+ }
+ } catch (SecurityException se) {
+ pollingException = new PollingSecurityException(
+ "Security Exception: " + se.getMessage());
done = true;
- } catch( Exception e ) {
+ } catch (CommunicationException ce) {
started = STATE_STOPPED;
- if( !expectedState )
- done = true;
+ } catch (NamingException nnfe) {
+ started = STATE_STOPPED;
+ } catch (AttributeNotFoundException e) {
+ failingException = e;
+ } catch (InstanceNotFoundException e) {
+ failingException = e;
+ } catch (MalformedObjectNameException e) {
+ failingException = e;
+ } catch (MBeanException e) {
+ failingException = e;
+ } catch (ReflectionException e) {
+ failingException = e;
+ } catch (NullPointerException e) {
+ failingException = e;
+ } catch (IOException e) {
+ failingException = e;
}
-
+ if( failingException != null ) {
+ pollingException = new PollingException(failingException.getMessage());
+ done = true;
+ }
+
try {
Thread.sleep(500);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
- } // end while
+ } // end while
}
-
+
Thread.currentThread().setContextClassLoader(currentLoader);
}
-
+
protected void setCredentials() {
+ Exception temp = null;
try {
- ILaunchConfiguration lc = server.getLaunchConfiguration(true, new
NullProgressMonitor());
- String twiddleArgs =
lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS
- + JBossServerLaunchConfiguration.PRGM_ARGS_TWIDDLE_SUFFIX, (String)null);
+ ILaunchConfiguration lc = server.getLaunchConfiguration(true,
+ new NullProgressMonitor());
+ String twiddleArgs = lc
+ .getAttribute(
+ IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS
+ + JBossServerLaunchConfiguration.PRGM_ARGS_TWIDDLE_SUFFIX,
+ (String) null);
String user = ArgsUtil.getValue(twiddleArgs, "-u", "--user");
- String password = ArgsUtil.getValue(twiddleArgs, "-p",
"--password");
+ String password = ArgsUtil.getValue(twiddleArgs, "-p",
+ "--password");
// get our methods
- Class simplePrincipal =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SimplePrincipal");
- Class securityAssoc =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SecurityAssociation");
- securityAssoc.getMethods(); // force-init the methods since the class hasn't been
initialized yet.
-
- Constructor newSimplePrincipal = simplePrincipal.getConstructor(new Class[] {
String.class });
- Object newPrincipalInstance = newSimplePrincipal.newInstance(new Object[] {user});
-
+ Class simplePrincipal = Thread.currentThread()
+ .getContextClassLoader().loadClass(
+ "org.jboss.security.SimplePrincipal");
+ Class securityAssoc = Thread.currentThread()
+ .getContextClassLoader().loadClass(
+ "org.jboss.security.SecurityAssociation");
+ securityAssoc.getMethods(); // force-init the methods since the
+ // class hasn't been initialized yet.
- // set the principal
- Method setPrincipalMethod = securityAssoc.getMethod("setPrincipal", new
Class[] {Principal.class});
- setPrincipalMethod.invoke(null, new Object[] {newPrincipalInstance});
-
- // set the credential
- Method setCredentialMethod = securityAssoc.getMethod("setCredential", new
Class[] {Object.class});
- setCredentialMethod.invoke(null, new Object[] {password});
- } catch( Exception e ) {
- e.printStackTrace();
+ Constructor newSimplePrincipal = simplePrincipal
+ .getConstructor(new Class[] { String.class });
+ Object newPrincipalInstance = newSimplePrincipal
+ .newInstance(new Object[] { user });
+
+ // set the principal
+ Method setPrincipalMethod = securityAssoc.getMethod(
+ "setPrincipal", new Class[] { Principal.class });
+ setPrincipalMethod.invoke(null,
+ new Object[] { newPrincipalInstance });
+
+ // set the credential
+ Method setCredentialMethod = securityAssoc.getMethod(
+ "setCredential", new Class[] { Object.class });
+ setCredentialMethod.invoke(null, new Object[] { password });
+ } catch (CoreException e) {
+ temp = e;
+ } catch (ClassNotFoundException e) {
+ temp = e;
+ } catch (SecurityException e) {
+ temp = e;
+ } catch (NoSuchMethodException e) {
+ temp = e;
+ } catch (IllegalArgumentException e) {
+ temp = e;
+ } catch (InstantiationException e) {
+ temp = e;
+ } catch (IllegalAccessException e) {
+ temp = e;
+ } catch (InvocationTargetException e) {
+ temp = e;
}
+ if( temp != null ) {
+ pollingException = new PollingException(temp.getMessage());
+ }
}
+
protected ClassLoader getClassLoader() {
try {
IRuntime rt = server.getRuntime();
IPath loc = rt.getLocation();
- URL url =
loc.append("client").append("jbossall-client.jar").toFile().toURI().toURL();
- URL url2 =
loc.append("bin").append("twiddle.jar").toFile().toURI().toURL();
- URLClassLoader loader = new URLClassLoader(new URL[] {url, url2},
Thread.currentThread().getContextClassLoader());
+ URL url = loc.append("client").append("jbossall-client.jar")
+ .toFile().toURI().toURL();
+ URL url2 = loc.append("bin").append("twiddle.jar").toFile()
+ .toURI().toURL();
+ URLClassLoader loader = new URLClassLoader(new URL[] { url,
+ url2 }, Thread.currentThread().getContextClassLoader());
return loader;
- } catch( MalformedURLException murle) {
- murle.printStackTrace();
+ } catch (MalformedURLException murle) {
+ pollingException = new PollingException(murle.getMessage());
}
return null;
}
}
+
private void launchJMXPoller() {
PollerRunnable run = new PollerRunnable();
Thread t = new Thread(run, "JMX Poller");
t.start();
}
+
public void cancel(int type) {
canceled = true;
}
@@ -179,28 +252,34 @@
}
public class PollingSecurityException extends PollingException {
- public PollingSecurityException(String msg) {super(msg);}
+ public PollingSecurityException(String msg) {
+ super(msg);
+ }
}
-
- public boolean getState() throws PollingException {
- if( pollingException != null ) throw pollingException;
- if( started == 0 ) return SERVER_DOWN;
- if( started == 1 ) return SERVER_UP;
- if( !done && !canceled )
- return !expectedState; // Not there yet.
+ public boolean getState() throws PollingException {
+ if (pollingException != null)
+ throw pollingException;
+ if (started == 0)
+ return SERVER_DOWN;
+ if (started == 1)
+ return SERVER_UP;
- return expectedState; // done or canceled, doesnt matter
+ if (!done && !canceled)
+ return SERVER_DOWN; // Not there yet.
+
+ return SERVER_UP; // done or canceled, doesnt matter
}
public boolean isComplete() throws PollingException {
- if( pollingException != null )
+ if (pollingException != null)
throw pollingException;
return done;
}
-
+
public class JMXPollerEvent extends EventLogTreeItem {
- public JMXPollerEvent(SimpleTreeItem parent, String type, int status, boolean
expectedState) {
+ public JMXPollerEvent(SimpleTreeItem parent, String type, int status,
+ boolean expectedState) {
super(parent, PollThread.SERVER_STATE_MAJOR_TYPE, type);
setProperty(PollThread.EXPECTED_STATE, new Boolean(expectedState));
setProperty(STATUS, new Integer(status));
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java 2007-08-21
19:52:47 UTC (rev 3263)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java 2007-08-21
21:04:36 UTC (rev 3264)
@@ -138,9 +138,8 @@
// abort and put the message in event log
poller.cancel(IServerStatePoller.CANCEL);
poller.cleanup();
- if( expectedState == IServerStatePoller.SERVER_UP) behavior.stop(true);
- if( expectedState == IServerStatePoller.SERVER_DOWN) behavior.setServerStarted();
alertEventLogPollerException(e);
+ alertBehavior(IServerStatePoller.SERVER_DOWN, false);
return;
}
}
@@ -162,9 +161,8 @@
// abort and put the message in event log
poller.cancel(IServerStatePoller.CANCEL);
poller.cleanup();
- if( expectedState == IServerStatePoller.SERVER_UP) behavior.stop(true);
- if( expectedState == IServerStatePoller.SERVER_DOWN) behavior.setServerStarted();
alertEventLogPollerException(pe);
+ alertBehavior(IServerStatePoller.SERVER_DOWN, false);
return;
}
} else {
@@ -183,13 +181,13 @@
protected void alertBehavior(boolean currentState, boolean finalAlert) {
if( currentState != expectedState ) {
// it didnt work... cancel all processes! force stop
- behavior.stop(true);
+ behavior.forceStop(false);
if( finalAlert ) alertEventLogFailure();
} else {
if( currentState == IServerStatePoller.SERVER_UP )
behavior.setServerStarted();
else {
- behavior.stop(true);
+ behavior.forceStop(false);
}
if( finalAlert ) alertEventLogSuccess(currentState);
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2007-08-21 19:52:47 UTC (rev
3263)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2007-08-21 21:04:36 UTC (rev
3264)
@@ -287,7 +287,7 @@
id="org.jboss.ide.eclipse.as.core.runtime.server.JMXPoller"
name="JMX Poller"
supportsStartup="true"
- supportsShutdown="true"/>
+ supportsShutdown="false"/>
<serverPoller
class="org.jboss.ide.eclipse.as.core.runtime.server.polling.ProcessTerminatedPoller"
id="org.jboss.ide.eclipse.as.core.runtime.server.processTerminatedPoller"
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java 2007-08-21
19:52:47 UTC (rev 3263)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java 2007-08-21
21:04:36 UTC (rev 3264)
@@ -148,7 +148,7 @@
}
protected Image getErrorImage() {
- return
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+ return
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
}
public Image getStartedImage() {
return getStateImage(IServer.STATE_STARTED);