NFJS Session 3: JMX and Spring: Manageability for Spring-based Applications
Basically I went to this session since the last one from Ken Sipe was pretty good. As I came here though, I had no idea what the heck JMX is. Thankfully the first part of the presentation covered what JMX is, since of course you need to know what it is in order to even think about leveraging it in Spring.
So what is it? JMX was defined in JSR-3 (recognized need early and very mature) and defines monitoring services with notification services. It’s also a core part of JDK 5. There’s an evolution of JMX through multiple JSRs defining good things such as remote APIs, JVM monitoring and management, Deployment API, etc. There’s a lot out there on it… essentially JMX is just an API that provides gauges that allow you to just monitor all kinds of things going on your server/application.
Creating an MBean is pretty straightforward… create an interface that ends with “MBean” (However, with JMX 1.2 you don’t need to have the name end with MBean) that defines a set of methods for the publicly exposed API and a concrete implementation of the interface. Then you just register it with an MBean server (“just” … it can be slightly involved). The example given was a bean that reports number of active threads, free memory, and totaly memory. MBeans are commonly viewed from an administration console.
Types of MBeans:
- Dynamic MBeans
- Any MBean that is dynamic
- Model MBeans
- Extends ModelMBean interface, which extends the Dynamic MBean. It provides a generic template for managing resources and is very dynamic.
- Open MBeans
- Dynamic MBean which follows specific rules. These rules help promote interoperability.
The first half pretty much covered everything related to JMX and MBeans, but what I took away from it is you can use JMX to create monitoring services and notification services for your applications (Ken was able to setup SMS and Jabber notifications). This interests me… there was some weird and cryptic MBean menu in Cruise Control I had no idea what it was before. Now I know. And now I can do some very nifty stuff with it.
Where Does Spring Come In?
Spring takes away the pain of creating/registering MBeans. Although it’s hard for me to describe the difference, the first examples of “the old way” of creating/registering MBeans looked slightly complex and convoluted… the Spring way allows you to just any object (you don’t need an interface to implement) and make it an MBean as well as some “automatic” detection schemes.
Overall, nifty stuff. Uses? I might find use in this by writing some MBeans to allow me to get SMS messages when VERY bad things happen in my next JEE application.