Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Superior app management with JMX

Integrate JMX, a reusable configuration framework, with your JSPs

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Let's face it, configuration management of any application server can be a burden, and most projects don't even have enough development cycles to include a configuration framework. Java Management Extensions (JMX) to the rescue: Now you have a reusable framework for exposing your application to remote or local management tools. JMX enables you to query the configuration settings and change them during runtime. It also provides other services, such as monitoring, event notification, a timer, and dynamic class loading from XML files. You can use JMX to load, initialize, change, and monitor your application and its distributed components. You can leverage your knowledge of this framework across third-party or your own custom software, creating a consistent approach to managing your applications.

This article will reveal some of JMX's architecture. The specification is detailed in JSR-000003, and is available for download. You can also download a reference implementation with source code. After exploring JMX internals, we will use a JavaServer Page (JSP) to interface with JMX using JBoss and Tomcat.

JMX revealed

The three JMX layers that are important here are instrumentation, agent, and distributed services.

The instrumentation layer

The instrumentation layer exposes the application as one or more managed beans (MBeans). Each MBean provides access to its state using public methods. An MBean can be any Java object that you modify to support the interfaces and semantics specified in the JMX specification for the type of MBean you create. The MBean types are standard, dynamic, open, and model. A standard MBean provides a static interface. A dynamic MBean exposes its interface to the JMX agent at runtime using metadata. The open MBean is a dynamic MBean that uses predefined Java data types so that dependencies on other classes are reduced, allowing for better runtime discovery and dynamic behavior. The model MBean, as the name implies, is a generic and configurable MBean that is provided with each JMX implementation. You can instantiate and use the model instead of defining your own MBean classes.

The standard MBean is the most common type. As an example, suppose you have a class called Logger that configures application debug messages by specifying a log filename and a verbosity level. You can turn Logger into a standard MBean by creating an interface called LoggerMBean. On this interface, add public setter and getter methods to expose the filename and verbosity attributes. Examples of these methods for the filename attribute would be setFileName() and getFileName(). The method naming convention for setters and getters is based on the setXXX and getXXX method names like in a JavaBean. Completing the puzzle, the Logger class needs to implement the LoggerMBean interface so that the JMX agent can use introspection to create metadata about the Logger MBean. The MBean is managed from the JMX agent by invoking attribute and other operational methods defined in the interface. The MBean is the link between the managed resource (your application) and the rest of the JMX framework.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources