JMX(Java Management Extensions)用来管理和监视java应用程序。
增加JMX支持
为使MINA应用程序支持JMX,需要做以下工作:
创建/获取MBean服务器
// create a JMX MBean Server server instance MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
实例化要求的MBeans(IoAcceptor, IoFilter)
// create a JMX-aware bean that wraps a MINA IoService object. In this case, a NioSocketAcceptor.
IoServiceMBean acceptorMBean = new IoServiceMBean( acceptor );
在MBean服务器上注册MBeans
// create a JMX ObjectName. This has to be 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 will happen for this acceptor.
mBeanServer.registerMBean( acceptorMBean, acceptorName );
启动Imagine Server
org.apache.mina.example.imagine.step3.server.ImageServer
开启Jconsole
开启Jconsole使用如下命令:
/bin/jconsole
We can see the different attributes and operations that are exposed by the MBeans