This is an article from TSS, with a simple example explains how to use JMX to manage your components in web applications.
http://www.theserverside.com/resources/article.jsp?l=jmxwebapps
Generally we use JMX to make your resources (which is some of the need to manage bean) to increase manageability, package the object you need to manage into MBean, then register into MBeanServer. Our management client calls the properties or operations exposed by MBeanServer to achieve the purpose of dynamic management components. Probably looked at this article, simply analyze the key in the following:
1. Look at the MBean code to implement Myjspstats, get MBeanServer through WebLogic JNDI service in the constructor and register yourself to MBeanServer. It uses the MBeanserver of the WebLogic server here, you can of course create your own MBeanServer, put it in the Application. Public class myjspstats imports myjspstatsmbean {
MBeanServer Server = null; // mbeanserver
INT Starts = 0; // Number Abandoned At Start Page Int Selects = 0; // Number Abandoned At Selection Int Confirms = 0; // Number Abandoned Before Confirmation Int Completions = 0; // Number of Completed User TX
Hashtable instart = new hashtable (); // track user tx started hashtable inselect = new has select hashtable inconfirm = new hashtable (); // track user tx in confirm
/ ** A no-argument constructor is necessary for Beans in JSPs ** / public MyJspStats () {try {Environment env = new Environment (); env.setProviderUrl ( "t3: // localhost: 7001"); env.setSecurityPrincipal ( "weblogic"); // username env.setSecurityCredentials ( "weblogic"); // password Context myCtx = env.getInitialContext (); MBeanHome mbeanHome = (MBeanHome) myCtx.lookup ( "weblogic.management.home.localhome") Server = mbeanhome.getmbeanserver ();
Objectname ObjName = new objectName (mbeanhome.getdomainName () ": name = myjspstats, type = myjspstats");
// register mbean so mabean can be subject.registermbean (this, objName);} catch (exception ex) {system.err.println ("Cannot get MBeanserver: ex);}} .... .
2. Look at the code of using Myjspstats below in JSP, create an object within the Application range using JSP's UseBean tags.
<% mbean.Updatetx (Request.GetSession (True), "Start");%>
Start a Transaction b>
Transfer Money Between Accounts
3. Below is a management page, on the management page, how to get MBeanServer, and call MBean management operations. MBeanhome mbeanhome = ("WebLogic.Management.home.localhome); MBeanServer Server = mbeanhome.getmbeanserver (); here acquire MBeanserver in the same way. Server.GetaTribute (ObjName, "Completions") This is the property of MBean.
<% @ Page import = "import javax.naming.Context; import javax.naming.InitialContext; import javax.management.ObjectName; import weblogic.jndi.Environment; import weblogic.management.MBeanHome; import javax.management.MBeanServer;" %>