FTP Online
Search:
Locator+ Code:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Improve Application Management With JMX (Continued)

Instrument Your Application
Assume this common situation: You have an existing application configured at startup time through a configuration file. The configuration is represented at run time by a single instance of your AppConfig class, which has methods for working with the configuration file and parameters. Many of your business objects rely on this singleton to get configuration parameters. Reconfiguring the application requires an administrator to know the configuration file well (format, location, and so on) in order to change it, and it also requires a server restart.

To remedy the situation, you could develop a proprietary administration console for your application and make it dynamically manageable—but you'd be in for a serious development ride. Or you could simply expose the AppConfig instance as a managed bean and be done with it. The exposed MBean attributes and operations will be automatically available to off-the-shelf management consoles, remote applications, and scripting environments.

Look at a sample AppConfig class (see Listing 1). The class has some general methods to read a property file, along with set and get individual properties. It could serve as part of a utility package you could reuse in different applications; you could directly expose those methods for management. However, this would not be helpful to administrators. Also, perhaps you can safely change only some of the configuration properties at run time. You're better off defining a management interface that directly reflects this application's particular configuration parameters.

As I explained, you can expose a management interface either from a conventional Java interface or by implementing the DynamicMBean generic interface. For simplicity, I use the former. With this approach, JMX mandates that you call the management interface AppConfigMBean and that the AppConfig class implements it. The AppConfigMBean interface exposes a few properties for management (see Listing 2).

Now, by using aspect-oriented programming (AOP) technology (see "Make Your Applications Operations Friendly With AOP"), you can integrate the instrumentation without interfering with the main application code. Check out the AspectJ source code that weaves the MBean interface implementation into the AppConfig class (see Listing 3). You can easily extend the code to support, for example, notifications on property changes and registration with the MBean server. No modifications—and with recent AOP tools, no recompilation—of the AppConfig class are needed.

By combining JMX and AOP, you can enhance your application's management abilities with only a few lines of code. Moreover, the MBean operations can embed "management intelligence" about the various configuration properties and guard against administrative mistakes. For instance, a URL property containing a service's address that your application needs might be changed to an invalid value. The MBean could perform a check and detect the error before committing the change to the application, which remains decoupled from all management activity.

Monitoring is another example where JMX and AOP play nicely. You can define aspects to monitor operations of interest and log the activity into managed beans that make all information available through a common management console—again without touching the core application.

Note that I've barely scratched the surface of JMX capabilities (for more information on JMX and AOP, see Resources). JMX is a fairly mature technology. The first final release of the standard came out nearly four years ago, and research started in 1995 during Java's early days. JMX is the outgrowth of the pioneering Java Management API (JMAPI) technology (1995) and the later Java Dynamic Management Kit. Today, nearly all J2EE application servers implement or use the technology, and many tools—such as management consoles, adaptors for legacy standards, and tools that automate instrumentation—have been developed in both open-source and commercial varieties.

About the Author
Borislav Iordanov is chief architect at Kobrix Software, a maker of rapid application development (RAD) tools for thin-client development.



Back to top



ADVERTISEMENT

Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home