Wednesday November 02, 2005
Relying on a standard JMX framework
The goal of this weblog entry is to detail how the Java
JMX management framework can be leveraged when developing applications using Netbeans.
It is difficult to write about Java development outside of the context
of an IDE.
The way a Java library is used or understood is greatly influenced by
the IDE used.
Using the IDE for writing, executing and debugging code is fine, but
today we expect more than that. We want an IDE to help us realize
the main use cases implied by the technologies we are using.
Among other tools, the Netbeans 5.0 beta release provides tools
centered around Swing, XML, Web Services, and JMX
API (you can download the JMX module from the beta update center). If
you
are not yet familiar with these features (including very cool Swing,
CVS and J2EE
support, among others), you should have a quick look at
Roman Strobl's
presentation.
Before we start, if you feel that a refresher is needed, have a look at
the following excellent
JMX API,
JConsole
and
JDK
5 Management and Monitoring articles.
Something that can appear a little confusing when you are trying to
find out
where the borders of JMX technology are, is the coexistence of the JMX
library and
the
JMX instrumentation of the JVM. You will in fact discover that ignoring
this distinction and taking a global approach will make the use of JMX
technology much
more simple and powerful.
A brief history of JMX technology
In the old days of JMX, everyone who wanted to
register MBeans had to create their own MBeanServer, then create and
start
some kind of non-standard remote access. A step toward better
interoperability was achieved by the introduction of standard RMI
access. But still people were not able to rely on a standard
"management
framework". People had to create multiple paths to access their
management. This
situation lead to a kind of "management divide".
Java 2 Platform, Standard Edition
(J2SE) 5 introduced a new and standard
management platform. The JMX developer can now rely on
this management platform to deploy their management. An MBeanServer
linked to
a fully configurable RMI ConnectorServer are present on any JVM. If you
want management you can get going with straight away, just use them!
As an example, management consoles (such as JConsole) rely increasingly
on the existence of this standard framework. Deploying your
MBeans in this framework will make them accessible from a wide range of
JMX managers.
By relying on the Java management platform, you will greatly simplify
the way you use JMX. In turn, if your IDE uses it, developing a
JMX application should become a child's play...
This is what we are going to see.
The Netbeans JMX module relies on the standard management framework.
It makes use of the platform MBeanServer when:
- Generating a JMX Agent.
The JMX Agent is a Platform MBeanServer wrapper that allows you to
instantiate, name and register your MBeans
- Generating a JUnit JMX Test.
Such tests allow you to activate MBean attributes and operations
without dealing with the framework. The MBean under test is
automatically registered in this MBeanServer. At the end of a
test session, the MBeanServer is cleaned from the MBean references.
==> During your JMX instrumentation coding and testing phase, you
can rely on the presence of the platform MBeanServer.
The Netbeans JMX module makes use of the platform remote RMI access:
- At execution time: The
application under development is automatically launched with the RMI
access enabled.
- At debugging time: The
application under debug is automatically launched with the RMI access
enabled.
==> During the execution and debugging phases, again, you can rely
on the presence of the remote RMI access.
Having your application ready to receive remote management requests is
fine, but what about the manager layer? How do JMX managers / consoles
enter the scene?
- If you are not developing a full JMX Manager, you can rely on the
JConsole generic management console.
It will automatically connect to the running application, allowing
visualization of the JVM
state and interaction with MBeans.
- If you are developing a JMX Manager, a JMX URL Editor helps you construct
a reference to the remote RMI access.
==> Again, JMX clients will benefit from the existence of this
framework.
I said that it's child's play... To help you, I have written a
tutorial
on how to start a JMX enabled Java application and how to connect to it.
The tutorial shows how the complexity of client / server application
development
can be reduced when handled directly from inside the IDE.
I recommend that you work through the tutorial. If you think that parts
are still too complex, please let
me know and we'll find an answer together to improve it.
If you want more details about how to add JMX to your application, you
can work through
another
tutorial that shows you how to develop an MBean, test it, register
it and interact with it at runtime.
To conclude, choosing to rely on this standard framework
orientates the way you use JMX. One advantage of choosing
it is that it will help you build your overall application management
system. Making consistent choices will result in a coherent
manageability application management solution.
Posted by jeanfrancoisdenise
( Nov 02 2005, 05:47:12 PM GMT+02:00 )
Permalink