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:
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"); try{ mbeanServer.registerMBean(confMBean,testMBeanName); } catch (InstanceAlreadyExistsException e) { ... } catch (MBeanRegistrationException e) { ... } catch (NotCompliantMBeanException e) { ... }
ComponentConfigurationDynamicMBean confMBean = new ComponentConfigurationDynamicMBean("some_module");
try { Object property=mbeanServer.getAttribute(moduleMBeanName,SOME_PROPERTY); String propertyString=(String)property; } catch (AttributeNotFoundException e2) { ... } catch (InstanceNotFoundException e2) { ... } catch (MBeanException e2) { ... }
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= mbeanServer.getAttributes( moduleMBeanName, new String[]{PROPERTY_ONE,PROPERTY_TWO,SOME_OTHER_PROPERTY});
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"); mbeanServer.setAttribute(moduleMBeanName,changedAttribute);