blob: bc267db851b2ece8991ba4d9ff5c0ee585a846bc [file] [log] [blame]
Title: Chapter 16 - JMX Support
NavPrev: ../ch15-proxy/ch15-proxy.html
NavPrevText: Chapter 15 - Proxy
NavUp: ../user-guide-toc.html
NavUpText: User Guide
NavNext: ../ch17-spring-integration/ch17-spring-integration.html
NavNextText: Chapter 17 - Spring Integration
Notice: Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
# Chapter 16 - JMX Support
Java Management Extensions (JMX) is used for managing and monitoring java applications. This tutorial will provide you with an example as to how you can JMX-enable your MINA based application.
This tutorial is designed to help you get the JMX technology integrated in to your MINA-based application. In this tutorial, we will integrate the MINA-JMX classes into the imagine server example program.
# Adding JMX Support
To JMX enable MINA application we have to perform following
* Create/Get MBean server
* Instantiate desired MBeans (IoAcceptor, IoFilter)
* Register MBeans with MBean server
We shall follow \src\main\java\org\apache\mina\example\imagine\step3\server\ImageServer.java, for the rest of our discussion
## Create/Get MBean server
:::java
// create a JMX MBean Server server instance
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
This lines get the MBean Server instance.
## Instantiate MBean(s)
We create an MBean for IoService
:::java
// create a JMX-aware bean that wraps a MINA IoService object. In this
// case, a NioSocketAcceptor.
IoServiceMBean acceptorMBean = new IoServiceMBean( acceptor );
This creates an IoService MBean. It accepts instance of an acceptor that it exposed via JMX.
Similarly, you can add IoFilterMBean and other custom MBeans as well
## Registering MBeans with MBean Server
:::java
// 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 );
We create an ObjectName that need to be used as logical name for accessing the MBean and register the MBean to the MBean Server. Our application in now JMX enabled. Lets see it in action.
## Start the Imagine Server
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 are using Java 6:
java -classpath <CLASSPATH> }}{{{}org.apache.mina.example.imagine.step3.server.ImageServer
## Start JConsole
Start JConsole using the following command:
<JDK_HOME>/bin/jconsole
We can see the different attributes and operations that are exposed by the MBeans