Starting / stopping a context using JMX with Tomcat
Hello,
Tomcat 6 (as well as 5) has built-in support for JMX for administering Tomcat servers. I would like to be able to start and stop a context on a given host.
I've been going about it like this:
I create a JMXServiceURL, create a JMXConnector and with it I create a MBeanServerConnection (mbsc).
I then find the 'Catalina' domain and get a list of all exposed MBeans by calling mbsc.queryMBeans(). When I find the 'Catalina:host=www.myapp.com,type=Host' MBean I call mbsc.getMBeanInfo() with its name and then call mbeanInfo.getOperations() to get a list of exposed operations.
Two of the exposed operation are start() and stop(). What I don't know how to do is actually execute them! Or perhaps I am going about this the wrong way ...
Any hints?
Thanks,
Bob
[824 byte] By [
syg6a] at [2007-11-15]

Well, I figured it out, sort of. At least half-way. This is what I did:
Object[] params = new Object[0];
String[] signatures = new String[0];
mbsc.invoke(objName, action, params, signatures);
When I call the 'stop' method it kills my webapp. More specifically it kills the virtual host my app is running on, since the MBean I am using is 'Catalina:host=www.myapp.com,type=Host'
But when I try calling the 'start' method it does nothing. Same goes for 'init':
What am I doing wrong? Should I use a different MBean? Context instead of Host? The only Context I find in all exposed MBeans in the Catalina domain is:
Catalina:host=www.myapp.com,path=/,resourcetype=Context,type=NamingResources
But as you can see its type is NamingResources, not Host, thus the operations exposed by this MBean don't have start or stop among them.
Stopping the host seems correct. Why won't start do anything?
Bob