-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Yogesh,

On 8/5/14, 10:18 AM, Yogesh Rao wrote:
> I am trying to write a MBean using the Modeler API in tomcat. The
> details of my environment are as below:-
> 
> Tomcat version : 7.0.54 JDK version : 1.7 OS : windows 7
> 
> The MBean written using Modeler API is not getting deployed and
> hence not showing up on JConsole. Following is the simple MBean
> code which has been written with its mbeans-descriptors.xml
> 
> HelloMBean.java -------------------------
> 
> package com.example.mbean;
> 
> public interface HelloMBean {
> 
> void sayHello(); }
> 
> 
> Hello.java --------------------------- package com.example.mbean;
> 
> import javax.management.MBeanException; import
> javax.management.RuntimeOperationsException;
> 
> import org.apache.catalina.mbeans.MBeanUtils; import
> org.apache.tomcat.util.modeler.BaseModelMBean; import
> org.apache.tomcat.util.modeler.ManagedBean; import
> org.apache.tomcat.util.modeler.Registry;
> 
> public class Hello extends BaseModelMBean implements HelloMBean  {
> 
> 
> protected Registry registry = MBeanUtils.createRegistry(); 
> protected ManagedBean managed =
> registry.findManagedBean("Custom");
> 
> protected Hello() throws MBeanException, RuntimeOperationsException
> { super(); }
> 
> @Override public void sayHello() { 
> System.out.println("sayHello()"); }
> 
> }
> 
> mbeans-descriptors.xml ------------------------------ <?xml
> version="1.0"?> <mbeans-descriptors> <mbean name="Custom" 
> className="com.example.mbean.Hello" description="Custom Hello" 
> domain="Catalina" group="Custom" 
> type="com.example.mbean.HelloMBean">
> 
> <operation name="sayHello" description="Saying Hello" 
> impact="ACTION" returnType="void"> </operation> </mbean> 
> </mbeans-descriptors>
> 
> 
> All the above files are in the same package and bundled as jar. I
> have tried placing this jar in server\lib directory as well as in a
> webapp.
> 
> Sadly there is very little documentation on how to go about writing
> a MBean using this API.
> 
> Any help on this would be greatly appreciated.

I never had any luck getting Tomcat to auto-load my beans: I had to
load them myself by manually-registering the bean with the local server.

Take a look at my presentation from ApacheCon NA 2014:
http://people.apache.org/~schultz/ApacheCon%20NA%202014/Monitoring%20Apache%20Tomcat%20with%20JMX.pdf

Check page 28 for a slide containing code where I manually-register
the bean. Note that I don't use any Tomcat-specific APIs.

I keep forgetting that I never posted the full source code, etc. for
my presentation. I really need to do that...

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJT4XalAAoJEBzwKT+lPKRYIt0QAKxJ1mt1tkylY9HUkGGKcpaa
kHXauvdCtC0RFqG/Gqrm73CO/f1//nrBqMr1n/HU8zK+6a1ygA0+u1tNtiU0nLBl
sXop34Ks/3Y1lKc7Nht5GcpB4+0CGTIyXwfHqdCMc9wQLaxpuSoS7VTsOWSpaLSZ
PY9IMdiFL0cGv301gsfDI7xn7pGzDSfGvCoakM+tGMMYywTidJNNxR1OyEZ070Wu
2AH3sydY2Xbbc/9Mlx0FRVjz7U+nQw/KDd3RZkyi/3EFCNt6Nh4zOwXQyY6Tm3Ik
+Mjff+5t1ggz7UM0sUFvbQqc+HaP7y45UWstWEKMsbHVX/KJIDIeLKJq6A44SV2i
og/JLrtOjLneu5D388hfX7CVwXaThXNuDQdyISXBai8i33YXGBwRUS9bLDAXOFRi
u1vroin2B2FTVNX1zkQNt+BkkuJCNrRfxmk5FSGsr3bWaNO4udrqqQFeImcj7msg
GDzs7vGmI3w599/tudo0o63G2DzquTwrIPq3BtbSGRn/SSYA8uEqJPjnWmpTBXjg
IUtMzW0VyFyJIuS9IjzfpwClNm2MOCehLsfZDeozsGDEl+Wku9PUUg1YW9tmbP/I
ai6so+eyChdD1XewZNIIbb8P8hSsAs6qfp3zlZrCA4gNkcvAbJahTsz/t3SkoBTn
xlY4+lKQnMoXgrzmRRrI
=O7gF
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to