Wadjet -JMX 5.3.0

Intrduction

Wadjet-JMX supplies a set of utilities to help build JMX (Java management eXtension) aware applications.

It supplies you with a set of utility classes for:

  • Helper classes for running an MBeanServer.
  • Dynamic MBeans that can be configured with XML.
  • A JMX Http Adaptor using the the HTTP Daemon.

The MBeanServerhelper can load and create MBeans that are defined in XML that follows the DynamicMBean declarations Schema .

Using Wadjet-JMX

The following sections describe how to use Wadjet-JMX in your programs:

Getting The MBean Server Helper

The IMBeanServcerHelper implementation is the heart of the Wadjet-JMX package, you obtain a instance of this class using a locator:

    m_mbsHelper = MBeanServerHelperLocator.getMBeanServerHelper();

The default implementation is the NullMBeanServerhelper which does not start the Java MBeanServer and does nothing. It is used as a dummy for client programs that do not need MBeans but may include libraries like Wadjet-JMS that will create MBeans if the service has been started.

To ensure that you get the JMX enabled version, set the jmx-service property in the services.conf file to the value com.addc.jmx.MBeanServcerHelperImpl or explicitly set the value in the IServicesConfiguration implementation before you use the MBeanServiceHelperLocator :

    ISerivicesConfig cfg = ServicesConfigFactory.getSerivicesConfig();
    cfg.setServicesProperty(IServicesConfiguration.JMX_KEY, 
                            "com.addc.jmx.MBeanServcerHelperImpl");
    MBeanServerHelperLocator.reset();
    m_mbsHelper = MBeanServerHelperLocator.getMBeanServerHelper();

In your code you should check for the availability of JMX like this:

    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(mbean, 
                               "Domain:name=something,typr=somethingElse");
    }

Back to top

Registering and de-registering MBeans

You can, of course, register your MBeans directly with the MBeanServer, but for MBeans that implement either of the MBean helper interfaces in Wadjet-JMX , there are a set of registration methods supplied that call the underlying MBeanServer for you:

    IDynamicJmxBean mbean = new MyMBean();
    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(mbean, 
                            "Domain:name=something,type=somethingElse");
    }

or

    IDynamicJmxBean mbean = new MyMBean();
    ObjectName oname = new ObjectName("Domain:name=something,type=somethingElse");
    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(mbean, oname);
    }

and

    IJmxBean mbean = new MyMBean();
    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(mbean);
    }

The IMBeanServerHelper also wraps the de-registration for any MBean whose name you know:

    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(mbean.getObjectName());
    }

or

    if (m_mbsHelper.isJMXAvailable()) {
        m_mbsHelper.registerAbstractMBean(oname);
    }

Back to top

Loading MBeans from XML Definitions

You can slo define all your MBeans in an XML file (see DynamicMBean declarations Schema ) and load them using the MBeanServerHelperImpl:

    m_mbsHelper = MBeanServerHelperLocator.getMBeanServerHelper();
    m_mbsHelper.loadMBeans(xmlFileName);

The MBeans that are flaged in the XML for loadAtStartup will be created and registered with the platform MBeanServer. The others are stored erady for use.

You can create DynamicMBeanImpl instances which wrap an object and delegate the method calls to get or set attributes and invoke operations to that class as you need them. This class is the key for finding the descriptors. For example if you have a bean that delegates to com.mycompany.mbeans.processor , you can create and register the MBean like this:

    m_mbsHelper = MBeanServerHelperLocator.getMBeanServerHelper();
    Element descriptor = m_mbsHelper.getMBeanDescriptor("com.mycompany.mbeans.processor");
    DynamicMBeanImpl mbean = new DynamicMBeanImpl("Domain:", descriptor);
    m_mbsHelper.registerAbstractMBean(mbean);

Back to top

Creating Dynamic MBeans

To create a Dynamic MBean you simply need to extend the AbstractDynamicMBeanImpl class and implement the createMBeanInfo info method along with the code to get and set the attributes and implement the operations you declare there and make a call to initMBeanInfo() in the constructor:

    public MyMBean() {
        super();
        ...
        initMBeanInfo();
    }
    
    protected MBeanInfo createMBeanInfo() {
        List<MBeanAttributeInfo> attrs = new ArrayList<MBeanAttributeInfo>();
        MBeanAttributeInfo mbai = new MBeanAttributeInfo("AppCommunity",
                String.class.getName(),
                "Application trap community",
                true,
                true,
                false);
        attrs.add(mbai);
        mbai = new MBeanAttributeInfo("SecCommunity", 
                String.class.getName(), 
                "Security trap community", 
                true, 
                true, 
                false);
        attrs.add(mbai);
        mbai = new MBeanAttributeInfo("ManagerHost", 
                String.class.getName(), 
                "Trap Receiver host name", 
                true, 
                true, 
                false);
        attrs.add(mbai);
        mbai = new MBeanAttributeInfo("ManagerPort", 
                int.class.getName(), 
                "Trap Receiver port", 
                true, 
                true, 
                false);
        attrs.add(mbai);
        mbai = new MBeanAttributeInfo("ServerName", 
                String.class.getName(), 
                "The name of this server", 
                true, 
                true, 
                false);
        attrs.add(mbai);
        MBeanInfo mBeanInfo = new MBeanInfo(getClass().getName(),
                "Alarming Service",
                (MBeanAttributeInfo[]) attrs.toArray(new MBeanAttributeInfo[attrs.size()]),
                new MBeanConstructorInfo[0],
                new MBeanOperationInfo[0],
                new MBeanNotificationInfo[0]);
        return mBeanInfo;
    }

All the code required to invoke the methods and get or set attributes is part of the AbstractDynamicMBeanImpl including handling of primitive types.


Back to top

Getting the Http Adaptor

The Wadjet-JMX supplies an http adaptor for JMX that is build on the Wadjet-HTTP package. When using this adaptor any entries in the Httpd.conf file are ignored and all the settings for http daemon are taken from the jmx.conf file.

The properties you can set for the server are shown in the table.

Key Description Default
http.authType The authentication type to use, one of None , Basic or Digest None
http.passFile The path to the password file if the authentication is not None
http.port The port the httpd should listen on 8088

The adaptor use XSLT transformation to convert the MBean information obtained from the platform MBeanServer to html. The xslt files can be found in the code and are loaded from jar file.

To obtain a fully initialised and running IJmxHttpAdaptor instance you use the locator. If you write your own, you will need to set the jmx-http-adaptor property in the services.conf file.

    IJmxHttpAdaptor adaptor = JmxHttpAdaptorFactory.getJmxHttpAdaptor();

Back to top

Getting the RMI Connector

The JmxRmiServerConnector class will create a fully configured, initialised and connected JMX-RMI server connector with an RMI registry for you. It is a service and as such is configured from a service property file, jmx.xonf like the http adaptor.

Key Description Default
rmi.port The port for the rmi registry 3000
rmi.ssl (true/false) Use SSL for connecting false
rmi.authenticate (true/false) Authenticate connections false
rmi.passfile Path to the pass file, see JMX documentation
rmi.accessfile Path to the access file, see JMX documentation

Both the Http adaptor and the RMI connector can be run concurrently.

To obtain an RMI server connector use the locator:

    JmxRmiServerConnector rmi = JmxRmiConnectorFactory.getJmxRmiServerConnector();

To get the JMXServiceURL from this to register with a slpd :

    JMXServiceURL url = rmi.getConnectorServer().getAddress();

Back to top