First see some basic things and run the code Some basic understanding of JMX, then look at the JMX specification Basic concept: 1: MBean is usually a Java class, which provides interfaces to make this class with management functions (such as Standard MBean, definition The method makes the MBean have management functions). 2: MBean Server is a Java class that manages MBean. After you need to register a MBean to MBean Server, this MBean will have management functions. The MBean Server also provides the function of query functionality and registration listener. SUN is only interface, MBean Server implementations in different JMX implementations are also different. 3: JMX Agentage is to manage a range of MBeans, and a series of services, as shown above, usually with MBean Relationships, Dynamically Loading Classes, Simple Monitoring Services, Timers. Agent can utilize Protocol Adapters (eg HTTP and SNMP) and Connectors (RMI, and JINI) to enable different clients to access MBean. 4: Protocol Adapters and Connectors Adapters and Connectors Key to use this Agent in different protocols and clients, one Agent can have multiple Protocol Adapters and Connectors, which manages MBean is more convenient (there are multiple types) The client and protocol can operate MBean). Note that Protocol Adapters and Connectors are usually MBean.
JMX1.1 has great improvements relative to 1.0, providing 4 types of MBean, 3, 4 MBEANs in 1.1, are special types of Dynamic MBean. 1: Standard mbean2: dynamic mbean3: Open MBean4: Model MBeanStandard MBean Programming Introduction Running Environment: First go to SUN to download two compressed packs http://java.sun.com/products/javaManagement/download.html: 1,jmx-1_2_1 -bin2, jmxremote-1_0_1-bin The following programs require only LiB / *. JAR Note: JMX and JMXRemote are two different packages.
Let's write a few programs: 1: Write interface 2: Write MBean3: Writing the code under the Agent, Very Easy, mainly defined the Get / Get method and other methods you want to use PUBLIC Interface HelloWorldmbean {public void setgreeting (String Greeting;
PUBLIC STRING GETGREETING ();
Public void printgreeting ();
Look at the MBean code, it is very similar to the traditional bean, adding an attribute having only a get method, indicating that this property is read-only, and the get / set has, indicating that this property is readable, this MBean Only one attribute Greeting is defined. There is also a way a method PrintGreeting is also defined. Public class helloworld imports helloworldmbean {
PRIVATE STRING = NULL;
Public helloworld () {this.greeting = "Hello World! I am a standard mbean";} public helloworld (string greeting) {this.greeting = Greeting;
Public void setgreeting (string greeting) {this.greeting = Greeting;
Public string getgreeting () {returnome
Public void printgreeting () {system.out.println (greeting);}}
The following is written in the Agent 1: Create a MBeanServer2: Create an Adapter3: Sign up with MBean to MBeanServer, and register APAPTER to MBeanServer4: Start Adapter Import Javax.Management. *; Import com.sun.jdmk.comm. *; Public class helloagent { private MBeanServer mbs = null; public HelloAgent () {mbs = MBeanServerFactory.createMBeanServer ( "HelloAgent"); HtmlAdaptorServer adapter = new HtmlAdaptorServer (); HelloWorld hw = new HelloWorld (); ObjectName adapterName = null; ObjectName helloWorldName = null;