JMX architecture understanding
Board bridge http://www.jdon.com 2002/12/26
JMX should be said about the framework of network application management. If you have developed a complicated system, you have to provide this system's own management system, JMX more applications are reflected on Server, if you want to use Java development Self-Server or complex application system, then recommend that you develop based on JMX architecture, JBoss 3.0 WebLogic is based on JMX-developed server software that meets J2EE specifications.
Understanding JMX can give you a deep understanding of the J2EE server, why we usually say "EJB" is a comparison "Weight" program selection, one of which is part of the J2EE server software itself is part of your system, it as your system's container, for you The system has a vital role. If you can't directly intervene or "tune" it, then there is no doubt that your system itself has implicit dangers. Now, through JMX, you can now go deep into your J2EE container inside you. . (I seem to have the first J2EE server in China, I don't know if it is based on JMX development?)
J2EE does not summarize all applications, such as the system that requires high-speed games or stock markets such as speed and performance requires themselves to develop Server. If it is possible based on JMX development, then it can be said to greatly improve the efficiency of writing management programs. You can turn your module into the MBEAN of JMX, you can initialize the initialization restart and parameter settings inside the program or through the Web Management page.
The benefits of JMX are: It can be convenient to connect existing Java technology, such as JNDI JDBC JTS and others. In particular, it is possible to use JINI query discovery mechanism and protocol. We know that Jini provides a service query and discovery mechanism that can be managed by JMX.
Now we start JMX understanding:
1. The JMX page of the Java.sun.com home page, download the JMX specified instructions and Samples programs. 2. Tutorial in accordance with JMX, learn how to add deletion Configuring a MBean, tutorial is a SimpleMbean as an example, can we build a MBean?
Let's do a Hello's MBean. Here is a small key point. Your class name has a rule. You need to end with mbean. If we are named hellombean:
Public interface hellombean {
// management attributes public string getName (); public void setname (String name);
// management operations public void print ();
}
In this class, there is an implied attributes: name, providing SET and GET methods, and there is an operational method print ():
A CONCRETE class again:
Public class hello imports hellombean {
Private string name = "";
Public string getname () {return name;}
Public void setname (String name) {this.name = name;}
Public void print () {system.out.println ("Hello," Name "!");}} This simple MBean is done, we can join this Hello through the admin interface.
Press TUTORIAL to start the baseagent, refer to Simple in the Agent Administration: domain: standard_hello_mbeans
Keys: name = hello, number = 1java class: hello
CREATE SUCCESSFUL information will appear. Enter the MBean View Give the Name, click Apply, then press Print, this is your Hello method in your Hello, you will see the output.
Is it very surprising that Attributes and Operations in Hello can be dynamic access and control? Have you felt about JMX architectural principles?
The following will further define some concepts: The above Hellombean resources are managed through the HTTP web interface such as Admin, which is a DISTRIBUTED service layer belonging to JMX, and JMX can deploy and manage MBean resources through the Distributed layer. As the example above, it is the maintenance management of HTTP web interfaces provided by HTMLADAPTOR HELLOMBEAN.
So can we automatically manage and deploy my MBean in the program? Of course, this is done through the Agent layer. Now we already have this level, the resource layer where MBean is located, the outer DISTRIBUTED service layer, the Distributed service layer is through the Agent layer to access MBean resources, see below Sun Architecture diagram specified by company JMX:
As seen from the figure, Agent Level (Agent Layer) includes MBean Server and Agent Services, then let's make an example of Hellombean's Agent:
// Create the mbeanserver // system.out.println ("/ N / TCREATE THE MBEANSERVER."); MBeanServer Server = mbeanserverFactory.creatembeanserver ();
// Create Registe hellombean // system.out.println ("/ N / TCREATE, Register A New Hello Standard_mbean:"); Hellombean Hellombean = New Hello ();
Objectname hello_name = null; try {hello_name = new objectname ("standard_hello_mbeans: name = hello, number = 1"); system.out.println ("/ TOBJECT NAME =" hello_name);
// Register Hellombean to MBeanServer to server.registermbean (Hellombean, Hello_Name);} catCH (Exception E) {E.PrintStackTrace (); Return;}
After registering MBeanserver, JMX will know this Hellombean resources later.
Manage an Agent's MBean resource or the service that uses it must pass through a protocol adaptor or Connector, Adaptor or Connector belongs to the Distributed Layer Level (DISTRIBUTED service layer), and we manage Hellombean from HTTP web interface through HTTPTAPTOR this Adaptor. Realize it. Through this article, you should generally understand the architecture of JMX and some principles and applications, and then in depth can study Sun's JMX Specification.