Hi,
I'm trying to deploy a custom mbean to a tomcat. This mbean is not part of a webapp. It should be instantiated when tomcat starts. My problem is, I can't find any complete documentation about how to deploy such a mbean. I'm getting different exceptions, depending on my configuration. Has anyone hints, a complete documentation or has implemented a mbean by himself and can post an example?
I configured tomcat to read a configuration from his conf directory:
<Engine name="Catalina" defaultHost="localhost" mbeansFile="${catalina.base}/conf/mbeans-descriptors.xml">
The content is as follows:
<?xml version="1.0"?>
<!--
<!DOCTYPE mbeans-descriptors PUBLIC
"-//Apache Software Foundation//DTD Model MBeans Configuration File"
"http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd">
-->
<!-- Descriptions of JMX MBeans -->
<mbeans-descriptors>
<mbean name="Performance"
description="Caculate JVM throughput"
type="Performance">
<attribute name="throughput"
description="calculated throughput (ratio between gc times and uptime of JVM)"
type="double"
writeable="false"/>
</mbean>
</mbeans-descriptors>
When name in the xml file and class name match, I get this excption:
SEVERE: Error creating mbean Performance
javax.management.MalformedObjectNameException: Key properties cannot be empty
at javax.management.ObjectName.construct(ObjectName.java:467)
at javax.management.ObjectName.<init>(ObjectName.java:1403)
at org.apache.tomcat.util.modeler.modules.MbeansSource.execute(MbeansSource.java:202)
at org.apache.tomcat.util.modeler.modules.MbeansSource.load(MbeansSource.java:137)
at org.apache.catalina.core.StandardEngine.readEngineMbeans(StandardEngine.java:517)
at org.apache.catalina.core.StandardEngine.init(StandardEngine.java:321)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:411)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
When changing the name attribute in the xml file to test.example:type=Performance, I get this exception:
SEVERE: Error creating mbean test.example:type=Performance javax.management.NotCompliantMBeanException: MBean class must have public constructor
at com.sun.jmx.mbeanserver.Introspector.testCreation(Introspector.java:127)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:284)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:199)
at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:393)
at org.apache.tomcat.util.modeler.modules.MbeansSource.execute(MbeansSource.java:207)
at org.apache.tomcat.util.modeler.modules.MbeansSource.load(MbeansSource.java:137)
at org.apache.catalina.core.StandardEngine.readEngineMbeans(StandardEngine.java:517)
at org.apache.catalina.core.StandardEngine.init(StandardEngine.java:321)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:411)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
The documentation from apache is not really helpful, as it just explains a small part.
I'm aware of this question but it doesn't help me. The answer I gave worked just for a short time, after that I got some other exceptions.
For additional info, the java interface
public interface PerformanceMBean {
public double getThroughput();
}
and implementing class
/* some import statements */
public class Performance implements PerformanceMBean {
public double getThroughput() {
...
}
}