JMX and Configuration

The Java Management Extensions (JMX) technology is an open technology for management and monitoring that can be deployed wherever management and monitoring are needed. By design, this standard is suitable for adapting legacy systems, implementing new management and monitoring solutions and plugging into those of the future.

The JMX specification provides Java developers across all industries with the means to instrument Java code, create smart Java agents, implement distributed management middleware and managers, and smoothly integrate these solutions into existing management and monitoring systems.

Instrumentation is made by means of managed beans or MBeans. The components of these MBeans are:

  • Attributes
  • Operations
  • Constructors
  • Notifications
If a MBean represents an instrumentation of a system, subsytem or component, the Attributes could be seen as its properties and by extensions its configuration. The most widely extended use of MBeas is the configuration of the different components of a large system. (See for example JBoss JMX Microkernel)

EasyConf and JMX

Since version: 0.9

There are several ways which EasyConf could make use of JMX. The first one and more obvious is providing a MBean whose attributes are the properties of some ComponentConfiguration. This MBean has also some useful operations to add a new property ann to reload the configuration from its source.

This MBean is implemented as a DynamicMBean of the JMX specification. Its fully qualified name is com.germinus.easyconf.jmx.ComponentConfigurationDynamicMBean. Here is an example of use of this MBean:

ComponentConfiguration componentConfiguration=EasyConf.getConfiguration("some_module");
ComponentConfigurationDynamicMBean confMBean = 
  new ComponentConfigurationDynamicMBean(componentConfiguration);
ObjectName moduleMBeanName = new ObjectName(JMX_NAME_PREFIX + "some_module");
} catch (InstanceAlreadyExistsException e) {
} catch (MBeanRegistrationException e) {
} catch (NotCompliantMBeanException e) {
Or you can skip the first line delegating the configuration loading to the MBean, simply by passing it the module name:
ComponentConfigurationDynamicMBean confMBean = 
  new ComponentConfigurationDynamicMBean("some_module");
Now we have the ComponentConfiguration for module some_module registerd in the MBean Server. Later, we can retrieve the value of some property simply querying the MBean server:
try {			
  Object property=mbeanServer.getAttribute(moduleMBeanName,SOME_PROPERTY);
  String propertyString=(String)property;
} catch (AttributeNotFoundException e2) {
} catch (InstanceNotFoundException e2) {
} catch (MBeanException e2) {
Notice how the module is referenced in the MBean Server through an ObjectName moduleMBeanName. This name must be unique in all the MBean Server otherwise an InstanceAlreadyExistsException is launched when trying to register a new MBean with that name.

There are methods for retrieving several properties at the same time:

AttributeList attributes=

Furthermore this MBean provides the possibility to change some property value, although this new value is only available in memory until the JVM finishes. (TODO: Persist ComponentConfiguration changes)

This can be achieved with the method setAttribute

Attribute changedAttribute=
  new Attribute(SOME_PROPERTY,"new_value");
The next time you invoke the getAttribute for this attribute and this MBean the value new_value will be returned.