Does CompositeData have no keys () method?

I am using JMX to save some diagnostic information from a remote process. Looking at the interface in jconsole, it is shown that the return type is CompositeData (the data is actually returned as CompositeDataSupport ). I want to display all the key / value pairs associated with this object.

The problem is that the interface seems to have a "values ​​()" method, not being able to get the keys. Am I missing something? Is there any other way to get closer to this task?

Thanks!

+5
source share
2 answers

If I'm not mistaken, you could do

Set< String > keys = cData.getCompositeType().keySet();

(, cData CompositeData)

http://java.sun.com/j2se/1.5.0/docs/api/javax/management/openmbean/CompositeType.html#keySet()

+8

, JVM MBeans

:

StringBuffer writeCompositeData(StringBuffer buffer, 
            String prefix, String name, CompositeData data) {
        if (data == null)
            return writeSimple(buffer,prefix,name,null,true);
        writeSimple(buffer,prefix,name,"CompositeData("+
                data.getCompositeType().getTypeName()+")",true);
        buffer.append(prefix).append("{").append("\n");
        final String fieldprefix = prefix + " ";
        for (String key : data.getCompositeType().keySet()) {
            write(buffer,fieldprefix,name+"."+key,data.get(key));
        }
        buffer.append(prefix).append("}").append("\n");
        return buffer;
    }

:

for (String key : data.getCompositeType().keySet()) {
    [...] data.get(key) [...];
}

- , .

+2

All Articles