Original address: JMX Support
Java Management Extensions (JMX) are used to manage and monitor Java applications. This tutorial will provide you with an example of how to build a jmx-usable mina application. The purpose of this tutorial is to help you integrate the JMX technology with the Mina based application. In this tutorial, we will consolidate the MINA-JMX class to the virtual (imagined) server sample program. Add JMX support
To enable JMX to support the Mina application, we need to do the following: Create/Acquire Mbean (Ioacceptor Iofilter) required for Mbean server instantiation and Mbean Server registration Mbean
The rest of the time we will discuss according to \src\main\java\org\apache\mina\example\imagine\step3\server\imageserver.java. Create or acquire an Mbean service side
Create a JMX MBean server server instance
mbeanserver mbeanserver = Managementfactory.getplatformmbeanserver ();
This line of code is to get an Mbean service-side instance.
instantiating an Mbean (s)
We create an mbean for Ioservice:
Create a jmx-aware bean that wraps a MINA Ioservice object. In here
//Case, a niosocketacceptor.
Ioservicembean Acceptormbean = new Ioservicembean (acceptor);
Create a Ioservice MBean. It accepts a sink instance through JMX. Similarly, you can add Iofiltermbean and other custom Mbeans.
registering an Mbean through an Mbean server
Create a JMX objectname. This is has to is in a specific format.
ObjectName acceptorname = new ObjectName (Acceptor.getclass (). Getpackage (). GetName () +
": type=acceptor,name=" + Acceptor.getclass (). Getsimplename ());
Register the Bean on the mbeanserver. Without this line, no JMX would happen for
//this acceptor.
Mbeanserver.registermbean (Acceptormbean, acceptorname);
We create an object name that needs to be used as a logical name to access the Mbean and an Mbean server that registers the Mbean. JMX is now enabled in our applications. Let's look at its practical application.
to start the virtual Mbean server side
If you are using Java 5 or earlier:
Java-dcom.sun.management.jmxremote-classpath <CLASSPATH> Org.apache.mina.example.imagine.step3.server.ImageServer
If you use Java 6:
Java -classpath <CLASSPATH>}}{{{}org.apache.mina.example.imagine.step3.server.imageserver
Start Jconsole
Start jconsole using the following command:
/bin/jconsole
We can see the different properties and the Mbeans exposed by the operation.