iPOJO JMX Handler

This handler provides JMX management of component instance. It could be useful to manage instance remotely. As the handler exposes MBeans, you must have a MBean server running on your platform (as the platform MBean server or the MOSGi MBean Server).


The handler allows to:


To be functional this handler must register on an MBean Server,thus you obviously need it. Several servers are currently supported : the standard platform MBean server (included in the Java Virtual Machine since version 5), MOSGi (Apache Felix sub-project), ...


The JMX handler is available in the Felix trunk in the iPOJO project. See the Download page to download and compile these sources.

How to use it

The handler needs to be added in the metadata.xml, you just add a namespace (e.g., jmx) :

<ipojo xmlns:jmx="org.apache.felix.ipojo.handlers.jmx">

So, you could now expose in JMX properties and methods of your component. They are surrounded by the tag.

    <jmx:property name="message" field="m_msg" rights="w" notification="true"/>
    <jmx:method name="doSomethingBad"/>
    <jmx:method name="doSomethingGood"/>


Be careful that the argument and return type of methods must be serializable. In case of several methods have the same name, each of them will be exposed.

JMX Handler options

Here you can find all configuration options of the JMX handler. There are two kinds of manageable elements : properties and methods. First is described the global configuration of the handler. Then elements can be configured, using several attributes, as described below.

Global handler attributes

Attribute name Required Description
objectName No The complete object name of the managed component. The syntax of this attribute must be compliant with the ObjectName syntax, detailed in the JMX specification. If neither domain nor name attributes are specified, the default value is determined by the package, the type and the instance name of the component. This attribute overrides the domain and name attributes. Example: "my.domain:type=myType,name=myName"
domain No The domain of the managed object (i.e., the left part of the object name). This attribute must be compliant with the domain syntax, as described in the JMX specification. Example: "my.domain:type=myType,name=my.domain"
name No The name property of the managed object. The value of this attribute must comply with the ObjectName value syntax, as described in the JMX specification.
usesMOSGi No Determines if the component must be register on the MOSGi MBean server or not.
preRegister, postRegister, preDeregister, postDeregister No These attributes allow to specify methods to carry out operations before and after being registered or unregistered from the MBean server.

Properties attributes

Attribute name Required Description
field Yes The name of the component's field to expose.
rights No The domain of the managed object (i.e., the left part of the object name). This attribute must be compliant with the domain syntax, as described in the JMX specification. Example: "my.domain:type=myType,name=my.domain"
name No Specify the access permission of the exposed field. The accepted values are :
  • "r" : read-only access, the default value.
  • "w" : read and write access.
notification No Enable or disable attribute change notification sending for this property. If set to `true`, a notification is sent each time the value of the field changes.

Methods attributes

Attribute name Required Description
name Yes The name of the method to expose. If multiple methods have the same name, all of them are exposed.
description No The description of the exposed method, as it will appear in JMX.


In this part, we will give you a complete example of a component managed with JMX, using the JConsole provided by the SUN JDK.

Exposing Attributes

In first time we create a simple component named MyComponent. We have add two fields named mlevel (int) and mmessage (String).

public class MyComponent ... {
    // Exposed attributes
    private String m_message;
    private int m_level;

We expose now the attributes in the jmx:config tag in the metadata :

<?xml version="1.0" encoding="UTF-8"?>
<iPOJO xmlns:jmx="org.apache.felix.ipojo.handlers.jmx">
    <component className="...MyComponent"

    <!-- Exposed properties -->
    <jmx:property field="m_level"
          name="The level"
    <jmx:property field="m_message"
          name="The message"

Now, we could get and write the properties in the JConsole :

Exposing Methods

We could now add methods in the initial class :

Do something good
public void doSomethingGood() {

Do something bad
public void doSomethingBad() {

Do nothing
public void doNothing() {

We add corresponding tags in the metadata to expose these methods:

<!-- Exposed methods -->
<jmx:method name="doSomethingGood"
      description="Do something good."/>
<jmx:method name="doSomethingBad"
      description="Do something bad."/>
<jmx:method name="doNothing"
      description="Do absolutely nothing."/>

Now the three methods are exposed in the operations tab of the JConsole. We can invoked these methods :

Attribute Notifications:

You could subscribe to attribute notification by adding the notification attribute in property tag. In our example if we want to be notified when m_level is modified, we change the property line in the metatada like this:

<jmx:property field="m_level"
      name="The level"

So now if we change the string through JConsole (or in the VisualVM) or if the POJO is modified in other way, a notification will be sent to every listener. For example, we subscribe in the notification tab, and we get notification when the message changes :

Configuring the handler with annotations

It is possible to configure the handler with simple annotations available with iPOJO annotations. Here is an example of usage:

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.handlers.jmx.Config;
import org.apache.felix.ipojo.handlers.jmx.Method;
import org.apache.felix.ipojo.handlers.jmx.Property;

@Config(domain="my-domain", usesMOSGi=false)
public class JMXSimple {

    @Property(name="prop", notification=true, rights="w") // Field published in the MBean
    String m_foo;

    @Method(description="set the foo prop") // Method published in the MBean
    public void setFoo(String mes) {
        System.out.println("Set foo to " + mes);
        m_foo = mes;

    @Method(description="get the foo prop") // Method published in the MBean
    public String getFoo() {
        return m_foo;

The @org.apache.felix.ipojo.handlers.jmx.Config (@Config if the package it correctly imported) annotation is a type annotation (so placed on the class element. This annotation indicates that the instance will be exposed as an MBean. This annotation supports:

The @org.apache.felix.ipojo.handlers.jmx.Property (@Property) annotation is a field annotation indicating that the field is exposed in the MBean. The supported attributes are:

The @org.apache.felix.ipojo.handlers.jmx.Method annotation is a method annotation indicating that the method is exposed in the MBean. Only one attribute can be customized: