|
From: Sal I. <sal...@sy...> - 2003-08-22 02:03:51
|
Leif:
I saw the previous posting on WrapperActionServer and find this to be
relevant.
We all know that one of the most important features of the wrapper is to
dump threads.
This is especially useful when running as a service, otherwise you basically
can't do it (1).
But how do you tell the wrapper to dump threads? I was faced with this
issue before I had the wrapper server came about.... so here is what I did.
I developed a jmx-mbean that proxies calls to the WrapperManager. I chose
to write a jmx-mbean in order to code this only once and be able to deploy
it to different environments.
The mbean is made of these 2 java files, which need to be located in the
same directory (2).
[WrapperManagerMBean.java]
package com.syncvoice.commons.silveregg.wrapper.jmx;
public interface WrapperManagerMBean {
String getBuildTime ();
int getJVMId ();
String getVersion ();
boolean getHasShutdownHookBeenTriggered ();
boolean isControlledByNativeWrapper ();
boolean isDebugEnabled ();
boolean isLaunchedAsService ();
void restart ();
void requestThreadDump ();
}
[WrapperManager.java]
package com.syncvoice.commons.silveregg.wrapper.jmx;
import com.syncvoice.commons.silveregg.wrapper.jmx.WrapperManagerMBean;
public class WrapperManager implements WrapperManagerMBean {
public String getBuildTime () { return
org.tanukisoftware.wrapper.WrapperManager.getBuildTime (); }
public int getJVMId () { return
org.tanukisoftware.wrapper.WrapperManager.getJVMId (); }
public String getVersion () { return
org.tanukisoftware.wrapper.WrapperManager.getVersion (); }
public boolean getHasShutdownHookBeenTriggered () { return
org.tanukisoftware.wrapper.WrapperManager.hasShutdownHookBeenTriggered (); }
public boolean isControlledByNativeWrapper () { return
org.tanukisoftware.wrapper.WrapperManager.isControlledByNativeWrapper (); }
public boolean isDebugEnabled () { return
org.tanukisoftware.wrapper.WrapperManager.isDebugEnabled (); }
public boolean isLaunchedAsService () { return
org.tanukisoftware.wrapper.WrapperManager.isLaunchedAsService (); }
public void restart () { org.tanukisoftware.wrapper.WrapperManager.restart
(); }
public void requestThreadDump () {
org.tanukisoftware.wrapper.WrapperManager.requestThreadDump (); }
}
As you can see to write an mbean all you do is write an interface and
implement it.
No libraries to import and no custom interfaces to implement.
The mbean i developed is nothing but a proxy into the WrapperManager.
Now all you do is add a couple lines of configuration to your jmx-aware
application, and you can point a browser to
http://localhost/jmx-console (for JBoss)
or
http://localhost:8082 (default jmx listening port when using the sun jmx-ri)
You'll get a UI that allows you to look at all the mbeans.
For each mbean, you can see its attributes, which are any mbean functions
that starts with get ().
For each mbean, you can invoke its operations, which are any non-get*/set*
method.
But how do you publish an mbean in a jmx-aware application?
In a JBoss environment, for example, take the following file and put it in
the JBoss deploy folder (3).
[wrapper-service.xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
<classpath archives="wrapper.jar" codebase="../../lib"/>
<mbean code="com.syncvoice.commons.silveregg.wrapper.jmx.WrapperManager"
name="Adaptor:protocol=SilverEggWrapper"/>
</server>
In JBoss, this file represents a service, and JBoss will hot-deploy it. Now
to test it:
1. point a browser to http://localhost/jmx-console
2. click on the wrapper mbean
3. click "requestThreadDump"
4. Look into jboss_home/logs/wrapper.log for your thread dump!
In addition to the HTTP based interface, there are a ton of other
already-built interfaces, such as SNMP, sockets, SOAP, RMI, JMS, etc, which
allow you to invoke mbean methods, which means that you can get to the
wrapper manager from just as many different places.
So now, simply by providing an mbean for the wrapper manager, i could do
crazy things such as have my site monitoring software issue a wrapper
restart through the RMI interface.
Leif, if you want to add this functionality, i'll gladly test it out for
you.
Sal.
(1) Actually, you kind of can: some people use nohup in unix..., but you
gotta know the side effects.....
(2) I developed this when the wrapper was still in the "silveregg" package.
(3) wrapper.exe goes in jboss/bin, wrapper.dll and wrapper.jar go in
jboss/lib
|