Search code examples
jbossjmxmbeans

Meaning of name attribute in JBoss MBean xml descriptor


JBoss 4/5 MBeans such as NamingAlias are defined in XML as follows

<mbean code="org.jboss.naming.NamingAlias" name=":service=NamingAlias,fromName=queue/original">
    <attribute name="ToName">queue/linked</attribute>
    <attribute name="FromName">queue/original</attribute>
</mbean>

Paying attention to the attributename=":service=NamingAlias,fromName=queue/original I see the parameters service and fromName.

Following the instructions to create a custom MBean here:

https://developer.jboss.org/wiki/ExampleHelloWorldService

The XML configuration for the MBean created is

<server>
  <mbean code="com.acme.HelloWorldService" name="acme.com:service=HelloWorld">
    <attribute name="Message">Hello World</attribute>
  </mbean>
</server>

I noticed only service is specified in the name attribute.

Is service mandatory for all the beans? What about adding additional parameters such as fromName? Can these values be used from within the class that implements the MBean or are those mandated?


Solution

  • The name attribute can be any valid (and unique) JMX ObjectName. The keys and values themselves do not have any special significance other than their subjective significance to the developer.

    In the first example, the ObjectName does not specify a domain (the value to the left of the colon) so the MBeanServer assumes the default domain, which in this case would be jboss so notionally:

    :service=NamingAlias,fromName=queue/original  ==  jboss:service=NamingAlias,fromName=queue/original
    

    The ObjectName (and it's embedded domain and key/values) can be used within the class. In standard JMX, one would typically make the impl implement MBeanRegistration which injects the MBeanServer and ObjectName when the bean is registered. However, the example you referenced is a specialized JBoss ServiceMBean which does this automatically and your implementation will store the ObjectName in the field called serviceName.