Well, I've made some progress.

Basically, you follow all the steps to get Tomcat to load JMX support,
essentially editing your catalina.sh.

Then you connect to Tomcat's JMX MBean server, choose a domain, choose an
MBean, choose an Operation, and execute it. The following code, mostly
pilfered, does all this:

JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:6666/jmxrmi");

Map map = new HashMap();
String[] credentials = new String[] { "monitorRole" , "QED" }; 
map.put("jmx.remote.credentials", credentials);
        
JMXConnector conn = JMXConnectorFactory.connect(url, map);
MBeanServerConnection mbsc = conn.getMBeanServerConnection();
ObjectName objName = new
ObjectName("Catalina:host=www.myapp.com,type=Host");
MBeanInfo mbeanInfo = mbsc.getMBeanInfo(objName);

Object[] params = new Object[0];
String[] signatures = new String[0];
mbsc.invoke(objName, action, params, signatures);
        
conn.close();

NOTES ON BOLD TEXT : 

1. 6666 is the port I told Tomcat to listen on in my catalina.sh file. The
params are the following:
CATALINA_OPTS="$CATALINA_OPTS ""-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=6666
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"

2. The host, www.myapp.com, is the name of my virtual host in my server.xml
file:
<Server>
  <Service>
    <Engine>
      <Host name="www.myapp.com" ...>

If you want a list of operations exposed by an MBean just use the following
code:
  
MBeanOperationInfo[] ops = mbeanInfo.getOperations();
for (int i = 0; i < ops.length; i++)
{
  MBeanOperationInfo op = ops[i];
  System.out.println("op: " + op.getName() + " , desc: " +
op.getDescription());
}

The MBean I have chosen, "Catalina:host=www.myapp.com,type=Host", has
start(), stop(), init() and a couple other operations (methods). 

All is ok when I stop an already started Host. But when I then call start()
or init(), it does nothing, throws no Exception.

What could I be doing wrong? I posted this question on the Java JMX forum as
well ...

Many thanks!
Bob


-- 
View this message in context: 
http://www.nabble.com/Programmatically-stop-start-context-%28webapp%29-tf3975317.html#a11322642
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to