Nice Bob.... I actually think you have cracked the JMX client stuff....
I dont think that is the right operation, it does work, but if you
stop/start the whole host, every webapp on the host will stop and start.
What we actually need is the context with those operations, and there doesnt
seem to be one.
There is another one under host, called deployer, it sounds promising but I
couldnt make sense of it.
Anyway.... it may sound like I have wriiten all the code, I havnt, just
wanted to tell you to get MC4J, if you havnt got it already.
It will show you all the MBeans and let you play with the operations, and
properties... save you struggling with the code.
I couldnt figure out how to stop/start a web-app (context).... maybe you
will crack it.
Good Luck
----- Original Message -----
From: "syg6" <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
Sent: Wednesday, June 27, 2007 1:28 PM
Subject: Re: Programmatically stop/start context (webapp)
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]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]