Chapter 2. JMX 1.2 Explained

Table of Contents

javax.management.ObjectName changes
The getInstance() methods
The quote() and unquote() methods
Support for remote API
Overview
The javax.management.MBeanServer class inherits from javax.management.MBeanServerConnection
The javax.management.MBeanServerBuilder class
Introduction
How to use MX4J's MBeanServer implementation with Sun's JMX Reference Implementation.
How to "decorate" MBeanServer methods.
More complex MBeanServer "decorations".
Possible usages of MBeanServer "decorators"
The javax.management.MBeanServerInvocationHandler class
Introduction
MBeanServerInvocationHandler usage
Porting examples for mx4j.util.StandardMBeanProxy

javax.management.ObjectName changes

The getInstance() methods

JMX 1.2 introduced four overloaded static version of the getInstance() method:

public static ObjectName getInstance(String name)
public static ObjectName getInstance(ObjectName name)
public static ObjectName getInstance(String name, Hashtable properties)
public static ObjectName getInstance(String domain, String key, String value)

The first version is the preferred way to create ObjectNames, and should be used instead of using the new Java keyword.
Creating a new ObjectName from a string is expensive because require parsing of the string.
JMX implementations may use caching techniques to speed up creation of ObjectNames from strings. MX4J does this optimization both in this method and in the ObjectName's constructor; it is likely that other implementations perform the optimization in getInstance(), but not in the ObjectName's constructor, so choosing to use getInstance() ensure coherent behaviors.

The second version is mostly used to convert ObjectName subclasses to plain ObjectName.
This is useful in a secure environment where evil ObjectName subclasses can try to bypass security checks done when javax.management.MBeanPermissions are checked to see if access to the MBean with the given ObjectName is allowed or not.

The third and the fourth version are just a replacement for the usage of the new Java keyword, and offer mostly syntactic sugar to your code.

The quote() and unquote() methods

JMX 1.2 introduced a way to "quote" the value of ObjectName's properties that is, to allow special characters to be present in the properties values of an ObjectName.

A simple example of this feature is to specify an LDAP name as an ObjectName property value.
Since the comma is a reserved character that separates ObjectName properties, it would have been impossible to specify an LDAP name as an ObjectName property.

Let's suppose to have a distinguished name of 'uid=guest,ou=project,o=company', and to build an ObjectName with a property called 'dname' whose value is the distinguished name.
Without quoting, the ObjectName is:

:dname=uid=guest,ou=project,o=company

which leads to an invalid ObjectName.

Using quoting, instead, it becomes:

:dname="uid=guest,ou=project,o=company"

which leads to a valid ObjectName.

It is possible also to "unquote" the property value to obtain the original string.

The ObjectName class has no knowledge if a value should be quoted or not, so it is responsibility of the developer to quote and unquote property values.
It is a good practice to do so in those cases where the property value is chosen by users, for example by inputting it in a web form or in a swing gui.

Refer to the javadoc of the ObjectName class for further information.