You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2004/07/26 19:14:49 UTC
cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/management State.java
dain 2004/07/26 10:14:49
Modified: applications/jmxdebug project.xml
applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib
MBeanInfoHelper.java MBeanServerHelper.java
applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity
BasicVelocityActionServlet.java DebugServlet.java
velocity.defaults
applications/jmxdebug/src/webapp mbeaninfo.vm mbeanstack.vm
modules/kernel/src/java/org/apache/geronimo/kernel/management
State.java
Added: applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/util
ObjectNameComparator.java
applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib
AttributeData.java
Removed: applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/util
ObjectInstanceComparator.java
Log:
Fixed debug console
Revision Changes Path
1.7 +13 -1 incubator-geronimo/applications/jmxdebug/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/project.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- project.xml 24 Jun 2004 20:59:51 -0000 1.6
+++ project.xml 26 Jul 2004 17:14:48 -0000 1.7
@@ -31,6 +31,18 @@
</dependency>
<dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-kernel</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-common</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+
+ <dependency>
<groupId>mx4j</groupId>
<artifactId>mx4j-jmx</artifactId>
<version>2.0.1</version>
1.1 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/util/ObjectNameComparator.java
Index: ObjectNameComparator.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.jmxdebug.util;
import java.util.Comparator;
import java.util.StringTokenizer;
import javax.management.ObjectName;
/**
* Taken from orignial console-web module
*
* This class sort ObjectNames by canonical name. Unfortunately, it
* will not place single token domains before multiple token domains of
* the same type (foo.bar > foo at the moment).
*
* @version $Revision: 1.1 $ $Date: 2004/07/26 17:14:48 $
*/
public class ObjectNameComparator implements Comparator {
public static final ObjectNameComparator INSTANCE = new ObjectNameComparator();
private static final int LEFT_GREATER = 1;
private static final int RIGHT_GREATER = -1;
private static final int EQUAL = 0;
public int compare(Object o1, Object o2) {
String leftName = ((ObjectName) o1).getCanonicalName();
String rightName = ((ObjectName) o2).getCanonicalName();
StringTokenizer leftDomainTokenizer = new StringTokenizer(leftName, ".");
StringTokenizer rightDomainTokenizer = new StringTokenizer(rightName, ".");
while (leftDomainTokenizer.hasMoreTokens()) {
if (!rightDomainTokenizer.hasMoreTokens()) {
return RIGHT_GREATER;
}
String leftToken = leftDomainTokenizer.nextToken();
String rightToken = rightDomainTokenizer.nextToken();
int comparison = leftToken.compareToIgnoreCase(rightToken);
if (comparison != 0) {
return comparison;
}
}
// left has no more tokens
if (rightDomainTokenizer.hasMoreTokens()) {
return LEFT_GREATER;
}
// both ran out of tokens so they are equal
return EQUAL;
}
}
1.2 +59 -76 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/MBeanInfoHelper.java
Index: MBeanInfoHelper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/MBeanInfoHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MBeanInfoHelper.java 18 Feb 2004 15:33:09 -0000 1.1
+++ MBeanInfoHelper.java 26 Jul 2004 17:14:48 -0000 1.2
@@ -17,25 +17,24 @@
package org.apache.geronimo.jmxdebug.web.beanlib;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
import javax.management.MBeanInfo;
-import javax.management.ObjectInstance;
+import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanOperationInfo;
-import javax.management.MBeanException;
-import javax.management.AttributeNotFoundException;
import javax.management.RuntimeMBeanException;
-import java.util.Map;
-import java.util.List;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.HashMap;
/**
* Simple helper bean for dealing with MBeanInfo. Helps dodge such
@@ -45,43 +44,28 @@
* @version $Id$
*/
public class MBeanInfoHelper {
+ private final ObjectName objectName;
+ private final MBeanInfo info;
+ private final MBeanServer server;
- ObjectName oName;
- MBeanInfo info;
-
- public MBeanInfoHelper(String name) {
- MBeanServer server = MBeanServerHelper.getMBeanServer();
-
+ public MBeanInfoHelper(MBeanServerHelper kernelHelper, String name) throws Exception {
+ server = kernelHelper.getKernel().getMBeanServer();
if (server != null) {
- init(server, name);
+ objectName = new ObjectName(name);
+ info = server.getMBeanInfo(objectName);
+ } else {
+ objectName = null;
+ info = null;
}
- }
- void init(MBeanServer server, String name) {
- try {
- oName = new ObjectName(name);
- info = server.getMBeanInfo(oName);
- }
- catch (MalformedObjectNameException e) {
- e.printStackTrace();
- }
- catch (ReflectionException e) {
- e.printStackTrace();
- }
- catch (InstanceNotFoundException e) {
- e.printStackTrace();
- }
- catch (IntrospectionException e) {
- e.printStackTrace();
- }
}
public String getCanonicalName() {
- return oName.getCanonicalName();
+ return objectName.getCanonicalName();
}
public String getDomain() {
- return oName.getDomain();
+ return objectName.getDomain();
}
/**
@@ -92,11 +76,9 @@
* $item.key
* $item.value
* #end
- *
- * @return
*/
public List getKeyProperties() {
- Hashtable h = oName.getKeyPropertyList();
+ Hashtable h = objectName.getKeyPropertyList();
Iterator it = h.keySet().iterator();
@@ -124,48 +106,49 @@
return info.getClassName();
}
- public List getAttributes() {
-
- List l = new ArrayList();
+ public SortedMap getAttributes() {
+ TreeMap attributes = new TreeMap();
+
MBeanAttributeInfo[] arr = info.getAttributes();
- MBeanServer server = MBeanServerHelper.getMBeanServer();
for (int i = 0; i < arr.length; i++) {
- MBeanAttributeInfo foo = arr[i];
- Object value = null;
- try {
- value = server.getAttribute(oName, foo.getName());
- }
- catch (MBeanException e) {
- e.printStackTrace();
- }
- catch (AttributeNotFoundException e) {
- e.printStackTrace();
- }
- catch (InstanceNotFoundException e) {
- e.printStackTrace();
- }
- catch (ReflectionException e) {
- e.printStackTrace();
+ MBeanAttributeInfo attribute = arr[i];
+ String name = attribute.getName();
+
+ if ((!attribute.isReadable() && !attribute.isWritable()) || name.startsWith("$")) {
+ // hide attributes that are not readable or writable or start with a '$'
+ continue;
}
- catch (RuntimeMBeanException rme) {
- rme.printStackTrace();
+
+ Object value = null;
+ if (attribute.isReadable()) {
+ try {
+ value = server.getAttribute(objectName, name);
+ } catch (MBeanException e) {
+ e.printStackTrace();
+ } catch (AttributeNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstanceNotFoundException e) {
+ e.printStackTrace();
+ } catch (ReflectionException e) {
+ e.printStackTrace();
+ } catch (RuntimeMBeanException rme) {
+ rme.printStackTrace();
+ }
}
- Map m = new HashMap();
- m.put("info", foo);
- m.put("value", value);
- l.add(m);
+ try {
+ AttributeData attributeData = new AttributeData(attribute, value, server.getClassLoaderFor(objectName));
+ attributes.put(name, attributeData);
+ } catch (Exception e) {
+ // ignore; just hide weird attributes
+ }
}
- return l;
+ return attributes;
}
-
public MBeanOperationInfo[] getOperationInfo() {
- MBeanOperationInfo foo;
-
return info.getOperations();
}
-
}
1.2 +38 -43 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/MBeanServerHelper.java
Index: MBeanServerHelper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/MBeanServerHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MBeanServerHelper.java 18 Feb 2004 15:33:09 -0000 1.1
+++ MBeanServerHelper.java 26 Jul 2004 17:14:48 -0000 1.2
@@ -17,17 +17,17 @@
package org.apache.geronimo.jmxdebug.web.beanlib;
-import org.apache.geronimo.jmxdebug.util.ObjectInstanceComparator;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
-import java.util.List;
-import java.util.Collection;
-import java.util.Set;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.jmxdebug.util.ObjectNameComparator;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
/**
* Little helper bean to deal w/ the mbean server
@@ -35,30 +35,18 @@
* @version $Id$
*/
public class MBeanServerHelper {
- final private MBeanServer server;
+ private final Kernel kernel;
public MBeanServerHelper() {
- this.server = getMBeanServer();
+ kernel = Kernel.getSingleKernel();
}
- /**
- * Returns the mbean server. Hokey as we just take the first
- * one...
- *
- * @return
- */
- public static MBeanServer getMBeanServer() {
- List l = MBeanServerFactory.findMBeanServer(null);
-
- if (l.size() > 0) {
- return (MBeanServer) l.get(0);
- }
-
- return null;
+ public Kernel getKernel() {
+ return kernel;
}
/**
- * Returns a Collection of InstanceObjects for all mbeans in the server
+ * Returns a Collection of InstanceObjects for all mbeans in the server
*
* @return Collection of InstanceObjects
*/
@@ -67,35 +55,42 @@
}
/**
- * Returns a Collection of InstanceObjects filtered by the input
- * filter
+ * Returns a Collection of InstanceObjects filtered by the input filter
*
- * @param filterString filter to use. Defaults to *:* if null
+ * @param filterString filter to use. Defaults to *:* if null
* @return Collection of InstanceObjects that match the filter
*/
public Collection getMBeans(String filterString) {
+ if (filterString == null) {
+ filterString = "*:*";
+ }
- if (server != null) {
- ObjectName objectName = null;
+ if (kernel != null) {
+ ObjectName filter = null;
try {
- objectName = new ObjectName((filterString == null ? "*:*" : filterString));
- Set s = server.queryMBeans(objectName, null);
+ filter = new ObjectName(filterString);
+ Set names = kernel.listGBeans(filter);
- List list = new ArrayList();
- list.addAll(s);
- ObjectInstanceComparator comparator = new ObjectInstanceComparator();
- Collections.sort(list, comparator);
+ List sortedNames = new ArrayList(names);
+ Collections.sort(sortedNames, ObjectNameComparator.INSTANCE);
- return list;
- }
- catch (MalformedObjectNameException e) {
+ return sortedNames;
+ } catch (MalformedObjectNameException e) {
e.printStackTrace();
}
- }
- else {
+ } else {
System.out.println("MBeanServerHelper : error : no mbean server");
}
return null;
+ }
+
+ public String getState(ObjectName name) {
+ try {
+ int state = ((Integer) kernel.getAttribute(name, "state")).intValue();
+ return State.toString(state);
+ } catch (Exception e) {
+ return null;
+ }
}
}
1.1 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/AttributeData.java
Index: AttributeData.java
===================================================================
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.jmxdebug.web.beanlib;
import java.beans.PropertyEditor;
import javax.management.MBeanAttributeInfo;
import org.apache.geronimo.common.propertyeditor.PropertyEditors;
/**
* @version $Revision: 1.1 $ $Date: 2004/07/26 17:14:48 $
*/
public class AttributeData {
private final String name;
private final String value;
private final String type;
private final boolean readable;
private final boolean writable;
public AttributeData(String name, String value, String type, boolean readable, boolean writable) {
this.name = name;
this.value = value;
this.type = type;
this.readable = readable;
this.writable = writable;
}
public AttributeData(MBeanAttributeInfo attributeInfo, Object value, ClassLoader cl) throws ClassNotFoundException {
this.name = attributeInfo.getName();
PropertyEditor editor = PropertyEditors.findEditor(attributeInfo.getType(), cl);
editor.setValue(value);
this.value = editor.getAsText();
this.type = attributeInfo.getType();
this.readable = attributeInfo.isReadable();
this.writable = attributeInfo.isWritable();
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public String getType() {
return type;
}
public boolean isReadable() {
return readable;
}
public boolean isWritable() {
return writable;
}
}
1.2 +58 -102 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/BasicVelocityActionServlet.java
Index: BasicVelocityActionServlet.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/BasicVelocityActionServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicVelocityActionServlet.java 18 Feb 2004 15:33:41 -0000 1.1
+++ BasicVelocityActionServlet.java 26 Jul 2004 17:14:48 -0000 1.2
@@ -17,176 +17,132 @@
package org.apache.geronimo.jmxdebug.web.velocity;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.Template;
-
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.Properties;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
-import javax.servlet.ServletContext;
-import java.lang.reflect.Method;
-import java.util.Properties;
-import java.util.Enumeration;
-import java.io.InputStream;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
/**
- * Simple servlet to dispatch based on 'action'. Also inits velocity in a
- * simple way
- *
+ * Simple servlet to dispatch based on 'action'. Also inits velocity in a
+ * simple way
+ *
* @version $Id$
*/
public abstract class BasicVelocityActionServlet extends HttpServlet {
+ public static final String DEFAULT_PROPS = "org/apache/geronimo/jmxdebug/web/velocity/velocity.defaults";
/**
* for dispatch purposes
*/
- private final Class[] args =
- {HttpServletRequest.class, HttpServletResponse.class};
+ private static final Class[] DISPATCH_ARGS = {HttpServletRequest.class, HttpServletResponse.class};
/**
- * velocity engine for this servlet
+ * velocity engine for this servlet
*/
- private VelocityEngine velEngine = new VelocityEngine();
-
- public static final String DEFAULT_PROPS =
- "org/apache/geronimo/jmxdebug/web/velocity/velocity.defaults";
+ private final VelocityEngine velocityEngine = new VelocityEngine();
/**
* for dispatching to the method specified...
- *
- * @param req
- * @param res
- * @throws ServletException
- * @throws java.io.IOException
*/
- public void service(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, java.io.IOException {
-
- String actionVerb = getActionVerb();
+ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
- String what = req.getParameter(actionVerb);
-
- if (what == null) {
- what = "defaultAction";
+ // get the action
+ String action = req.getParameter(getActionVerb());
+ if (action == null || action.length() == 0) {
+ action = "defaultAction";
}
+ // look up and invoke the method with the action name
try {
- Method method = this.getClass().getMethod(what, args);
-
- Object[] objs = {req, res};
- method.invoke(this, objs);
- }
- catch (NoSuchMethodException nsme) {
+ Method method = this.getClass().getMethod(action, DISPATCH_ARGS);
+ method.invoke(this, new Object[]{req, res});
+ } catch (NoSuchMethodException nsme) {
unknownAction(req, res);
- }
- catch (Exception e) {
+ } catch (Exception e) {
log("BasicVelocityActionServlet.service() : exception", e);
}
}
- public void init()
- throws ServletException {
-
- /*
- * get the default properties from the classloader
- */
-
+ public void init() throws ServletException {
Properties p = new Properties();
+ // load the default properties file using the classloader
try {
- InputStream is = getClass().getClassLoader().getResourceAsStream(DEFAULT_PROPS);
-
- p.load(is);
- }
- catch (Exception e) {
+ p.load(getClass().getClassLoader().getResourceAsStream(DEFAULT_PROPS));
+ } catch (Exception e) {
log("BasicVelocityActionServlet : default " + DEFAULT_PROPS + " not found.", e);
throw new ServletException(e);
}
- /*
- * run through them and use them
- */
-
- for (Enumeration en = p.propertyNames(); en.hasMoreElements();) {
- String key = (String) en.nextElement();
-
- velEngine.setProperty(key, p.getProperty(key));
+ // apply default propertis to velocitty engine
+ for (Iterator iterator = p.keySet().iterator(); iterator.hasNext();) {
+ String key = (String) iterator.next();
+ velocityEngine.setProperty(key, p.getProperty(key));
}
- /*
- * for now, log to the servlet log
- */
-
- org.apache.geronimo.jmxdebug.web.velocity.ServletLogger sl = new org.apache.geronimo.jmxdebug.web.velocity.ServletLogger(getServletContext());
- velEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, sl);
-
- /*
- * set an app context for the webapploader if we are using it
- */
+ // hook velocity logger up to the servlet logger
+ ServletLogger sl = new ServletLogger(getServletContext());
+ velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, sl);
+ // set an app context for the webapploader if we are using it
ServletAppContext vssac = new ServletAppContext(getServletContext());
- velEngine.setApplicationAttribute(WebappLoader.KEY, vssac);
+ velocityEngine.setApplicationAttribute(WebappLoader.KEY, vssac);
+ // start the velocity engine
try {
- velEngine.init();
- }
- catch (Exception e) {
+ velocityEngine.init();
+ } catch (Exception e) {
log("BasicVelocityActionServlet", e);
throw new ServletException(e);
}
}
/**
- * Defines the 'action verb' for the app
- * @return
+ * Defines the 'action verb' for the app
*/
protected abstract String getActionVerb();
/**
* Called when there is a request w/ no action verb
- *
- * @param req
- * @param res
- * @throws ServletException
- * @throws java.io.IOException
*/
public abstract void defaultAction(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, java.io.IOException;
+ throws ServletException, IOException;
/**
* Called when there is a request w/ invalid action verb
- *
- * @param req
- * @param res
- * @throws ServletException
- * @throws java.io.IOException
*/
public abstract void unknownAction(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, java.io.IOException;
+ throws ServletException, IOException;
protected VelocityEngine getVelocityEngine() {
- return this.velEngine;
+ return this.velocityEngine;
}
protected boolean renderTemplate(HttpServletRequest req,
- HttpServletResponse res,
- VelocityContext vc, String template) {
- boolean result = false;
+ HttpServletResponse res,
+ VelocityContext velocityContext,
+ String templateName) {
try {
- Template t = getVelocityEngine().getTemplate(template);
- t.merge(vc, res.getWriter());
- result = true;
- }
- catch (Exception e) {
- e.printStackTrace();
+ Template template = getVelocityEngine().getTemplate(templateName);
+ template.merge(velocityContext, res.getWriter());
+ return true;
+ } catch (Exception e) {
+ log("Error rendering template: " + templateName, e);
}
- return result;
+ return false;
}
/**
1.2 +44 -35 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/DebugServlet.java
Index: DebugServlet.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/DebugServlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DebugServlet.java 18 Feb 2004 15:33:41 -0000 1.1
+++ DebugServlet.java 26 Jul 2004 17:14:48 -0000 1.2
@@ -17,25 +17,23 @@
package org.apache.geronimo.jmxdebug.web.velocity;
-import org.apache.velocity.VelocityContext;
-import org.apache.geronimo.jmxdebug.web.beanlib.MBeanServerHelper;
-import org.apache.geronimo.jmxdebug.web.beanlib.MBeanInfoHelper;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.geronimo.jmxdebug.web.beanlib.MBeanInfoHelper;
+import org.apache.geronimo.jmxdebug.web.beanlib.MBeanServerHelper;
+import org.apache.velocity.VelocityContext;
/**
- * Simple servlet for looking at mbeans
- *
+ * Simple servlet for looking at mbeans
+ *
* @version $Id$
*/
public class DebugServlet extends BasicVelocityActionServlet {
-
public static String OBJECT_NAME_FILTER_KEY = "ObjectNameFilter";
protected String getActionVerb() {
@@ -43,14 +41,9 @@
}
/**
- * The only real action - just puts the mbean server helper in the
- * context, and if there was a mbean specified for details, shoves
- * a MBeanINfoHelper in the context
- *
- * @param req
- * @param res
- * @throws ServletException
- * @throws IOException
+ * The only real action - just puts the mbean server helper in the
+ * context, and if there was a mbean specified for details, shoves
+ * a MBeanINfoHelper in the context
*/
public void defaultAction(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
@@ -64,16 +57,20 @@
VelocityContext vc = new VelocityContext();
- vc.put("mbctx", new MBeanServerHelper());
+ MBeanServerHelper kernelHelper = new MBeanServerHelper();
+ vc.put("mbctx", kernelHelper);
vc.put("encoder", new KickSunInHead());
vc.put(OBJECT_NAME_FILTER_KEY, filterKey);
if (beanName == null) {
vc.put("template", "nobean.vm");
- }
- else {
+ } else {
+ try {
+ vc.put("beanInfo", new MBeanInfoHelper(kernelHelper, beanName));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
vc.put("template", "mbeaninfo.vm");
- vc.put("beanInfo", new MBeanInfoHelper(beanName));
}
renderTemplate(req, res, vc, "index.vm");
@@ -86,23 +83,35 @@
/**
- * Why oh why couldn't this be one class...
+ * Why oh why couldn't this be one class...
*/
public class KickSunInHead {
- public String decode(String s) {
- return URLDecoder.decode(s);
+ public String decode(String string) {
+ return decode(string, "UTF-8");
}
- public String encode(String s) {
- return URLEncoder.encode(s);
+ public String decode(String string, String encoding) {
+ if (string != null) {
+ try {
+ return URLDecoder.decode(string, encoding);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
}
- public String encode(String s, String encoding) {
- try {
- return URLEncoder.encode(s, encoding);
- }
- catch (UnsupportedEncodingException uee) {
- uee.printStackTrace();
+ public String encode(String string) {
+ return encode(string, "UTF-8");
+ }
+
+ public String encode(String string, String encoding) {
+ if (string != null) {
+ try {
+ return URLEncoder.encode(string, encoding);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
return null;
1.2 +3 -0 incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/velocity.defaults
Index: velocity.defaults
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/velocity/velocity.defaults,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- velocity.defaults 18 Feb 2004 15:33:41 -0000 1.1
+++ velocity.defaults 26 Jul 2004 17:14:48 -0000 1.2
@@ -1,3 +1,6 @@
resource.loader = webapp
webapp.resource.loader.class = org.apache.geronimo.jmxdebug.web.velocity.WebappLoader
+
+velocimacro.library.autoreload = true
+
1.2 +20 -34 incubator-geronimo/applications/jmxdebug/src/webapp/mbeaninfo.vm
Index: mbeaninfo.vm
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/webapp/mbeaninfo.vm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mbeaninfo.vm 18 Feb 2004 15:31:07 -0000 1.1
+++ mbeaninfo.vm 26 Jul 2004 17:14:49 -0000 1.2
@@ -1,19 +1,15 @@
-
-<b>Info for :</b> $beanInfo.getCanonicalName()
-<hr/>
-
<table>
<tr>
<td>
- <b>Description : </b>
+ <b>ObjectName: </b>
</td>
<td>
- $!beanInfo.getDescription()
+ $beanInfo.getCanonicalName()
</td>
</tr>
<tr>
<td>
- <b>ClassName : </b>
+ <b>ClassName: </b>
</td>
<td>
$!beanInfo.getClassName()
@@ -21,49 +17,37 @@
</tr>
<tr>
<td>
- <b>Domain : </b>
+ <b>State: </b>
</td>
<td>
- $!beanInfo.getDomain()
+ $mbctx.getState($name)
</td>
</tr>
</table>
-<h3>Key Properties</h3>
-
-#foreach($i in $beanInfo.getKeyProperties())
-$i.key = $i.value
-<br/>
-#end
-
-<h3>MBean Attributes</h3>
+<h3>Attributes</h3>
<table>
<tr>
<th>Name</th>
<th>Value</th>
- <th>Type</th>
- <th>R</th>
- <th>W</th>
- <th>Is</th>
- <th>Desc</th>
-</tr>
-
-#foreach($i in $beanInfo.getAttributes())
-
-<tr>
- <td>$i.info.getName()</td>
- <td>$i.value</td>
- <td>$i.info.getType()</td>
- <td>$i.info.isReadable()</td>
- <td>$i.info.isWritable()</td>
- <td>$i.info.isIs()</td>
- <td>$!i.info.getDescription()</td>
+</tr>
+
+#foreach($i in $beanInfo.getAttributes().values())
+
+#set($name = $i.name)
+#if($name != "objectName" && $name != "statisticsProvider" && $name != "stateManageable" && $name != "eventProvider" && $name != "state" && $name != "startTime")
+<tr>
+ <td>$name</td>
+ <td>$!i.value</td>
</tr>
#end
+
+#end
</table>
+<!--
<h3>MBean Operations</h3>
@@ -81,3 +65,5 @@
</tr>
#end
</table>
+-->
+
1.2 +4 -5 incubator-geronimo/applications/jmxdebug/src/webapp/mbeanstack.vm
Index: mbeanstack.vm
===================================================================
RCS file: /home/cvs/incubator-geronimo/applications/jmxdebug/src/webapp/mbeanstack.vm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mbeanstack.vm 18 Feb 2004 15:31:07 -0000 1.1
+++ mbeanstack.vm 26 Jul 2004 17:14:49 -0000 1.2
@@ -9,6 +9,7 @@
(<a href="/geronimo-web-console/faq.jsp#objectName"/>help</a>)
</form>
+#set($filterParam = $encoder.encode($ObjectNameFilter, "UTF-8"))
#set($currentDomain = "")
#set($i = 0)
#set($mbeanList = $mbctx.getMBeans($ObjectNameFilter))
@@ -19,10 +20,7 @@
<hr/>
-#foreach($instance in $mbeanList)
-
- #set($name = $instance.getObjectName())
-
+#foreach($name in $mbeanList)
#if (!($name.getDomain().equals($currentDomain)))
#if ($i != 0)
@@ -38,9 +36,10 @@
#set($encodedName = $encoder.encode($cName, "UTF-8"))
#set($where = $cName.indexOf(":") + 1)
#set($output = $cName.substring($where))
+ #set($state = $mbctx.getState($name))
<li>
- <a href="index.vm?ObjectNameFilter=$encoder.encode($ObjectNameFilter, "UTF-8")&MBeanName=$encodedName">$output</a>
+ <a href="index.vm?ObjectNameFilter=$filterParam&MBeanName=$encodedName">$output</a> [$state]
</li>
#set($i = $i + 1)
1.6 +8 -1 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/management/State.java
Index: State.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/management/State.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- State.java 2 Jun 2004 19:46:24 -0000 1.5
+++ State.java 26 Jul 2004 17:14:49 -0000 1.6
@@ -63,6 +63,13 @@
return fromInt(index.intValue());
}
+ public static String toString(int state) {
+ if (state < 0 || state >= fromInt.length) {
+ throw new IllegalArgumentException("State must be between 0 and " + fromInt.length);
+ }
+ return fromInt[state].name;
+ }
+
/**
* The user readable name of this state from the J2EE Management specification
*/