Establish JMX management system for web applications (2)

zhaozj2021-02-16  95

Establish JMX management system for web applications (2)

Previous: "Create a JMX-based management system (1)" for your web application. Creating a MBean description file In the third code above, we can see that you must create MBean to MBean Server must first create MBeanInfo, MBean's setModelmbeanInfo () is used to set MBeanInfo into the MBEAN. In order to get the MBean information, the MBean is registered to MBeanServer, which is mentioned in the "Best Practice of Java Enterprise" published in O'Reilly, and the XML file is a very good option, and A XML description example is provided, so this article also recommends a method of managing web applications using a MBean description file. In fact, regardless of Tomcat4.x, or JBoss, the MBEAN is created by using the MBean description file. The following is provided with the MBean description file scheme in Tomcat4.x, and uses the scheme to describe the two database connection management mentioned above. MBean. Tomcat provides a way to read the description file, you can see the help documentation provided by Tomcat - how to use MBean Descriptor ("http://jakarta.apache.org/tomcat/tomcat-4.1-doc/mbeans-descriptor-howto .html ").

< Attribute name = "dburl" description = "database url" type = "java.lang.string" />

Description = "Test configure attribute" impact = "action" Returntype = "java.lang.string"> < Parameter name = "Username" description = "Database user name for test" type = "java.lang.string" /> 5. Register MBean is right Before the MBean registration, the description of MBean must be obtained, and saved in the MBeanInfo instance, otherwise it is unable to register with MBean to MBean Server, through the MBean description file, get various types of MBean description information is a very simple Things, and these are what is needed to create MBean. This is the advantage that it is not necessary to modify the code, you can add new MBean, and the registered code is actually listed before our previous code has been listed. When you register in MBean, you must specify the corresponding ObjectName, ObjectName is equivalent to the unique name of MBean in MBean Server, its format is: "Domain: Key1 = Value1, Key2 = Value2 ...", can define a set according to the requirements of the system Named rules.

/ / Register MBean to MBean Server

MBeanServer Serv = getmbeanserver (); objectName oname = CreateObjectName (MBean); serv.registermbean (MBean, oname);

6. Write the client's client we have completed the registration of the server-side MBean, and how to make users can use these MBean management resources. Although HTMLADAPTERs are provided in JMX reference implementations, users can use MBean through the browser. But the interface is not so friendly, and the harsh customer will never be satisfied with this. Therefore, it is still necessary to write some simple access to the MBean page. How to access MBean through Java, you can refer to JMX information, which is very much. According to the above introduction, if you want to increase the management function or management system for web applications, JMX-based management framework is definitely a very sensible choice. At the time of being abducted, it is inevitable that there is a mistake, and I hope to know the taxis, I will give it to the mind, and I am grateful to the heart.

转载请注明原文地址:https://www.9cbs.com/read-13206.html

New Post(0)