Hi Dave,

I'm not sure this is quite a good idea because
order doesn't count when comparing ObjectNames.

So the folder analogy would just be a lure:
/a/b/c would be equal to /a/c/b

That said - I can see value in trying to get rid
of the legacy Hashtable - so adding a new method
that takes a Map<String,String> wouldn't necessarily
be a bad thing :-)

A work around for your use case would be to use:

 static ObjectName getInstance(String name)

instead of

 static ObjectName getInstance(String domain
                               Hashtable<String,String> table)

An object name has both a string representation
and a canonical representation.
IIRC we did try to preserve the original string
representation, even if it's not canonical.
It's also preserved in the serial form.

See:
https://docs.oracle.com/javase/8/docs/api/javax/management/ObjectName.html#getKeyPropertyListString--

Hope this helps,

-- daniel


On 24/02/17 00:17, Dave Brosius wrote:
Greetings. the method

public static ObjectName getInstance(String domain,
Hashtable<String,String> table)
        throws MalformedObjectNameException {
        return new ObjectName(domain, table);
    }

in javax.management.ObjectName allows for a provided Hashtable to
specify properties for the objectname.

The semantics of an ObjectName don't consider the order of these
properties, however certain tools like jconsole (when used as a name for
a jmx property) does consider the order.

If you wish to create a folder structure to report metrics in jmx, you
need to use this properties map to specify the folder names. JConsole,
then, uses order of iteration to determine the order of the folder
hierarchy.

Suppose you want a folder hierarchy similar to a package name, you may
specify properties like

table.put("a0", "com");
table.put("a1", "acme");
table.put("name", "MyMetric");

in hopes of producing a metric in JConsole in the folder structure,
com/acme/MyMetric.

The problem is of course, that the argument is a Hashtable, not a Map,
and so the items are not ordered at all, yet JConsole uses iteration
order to build the path, so you may get

acme/ao/MyMetric or MyMetric/acme/ao or .....

This means if you really want to have ordered packages, you have to
derive from Hashtable, and override the entrySet() method, including
that set's iterator() to return the values in the order you wish to have
them shown.

That is really janky.

I'm proposing that the interface for getInstance be softened to

public static ObjectName getInstance(String domain,
                                         Map<String,String> table)

as well as

public ObjectName(String domain, Map<String, String> table)

thoughts?


Reply via email to