0

I know I can have SimpleType values like SimpleType.INTEGER, SimpleType.STRING in a CompositeData. But I wonder how do I get another instance of CompositeData into CompositeData. E. g.:

CompositeType type = new CompositeType("My Type", "My Type", new String[]{"item1", "item2"}, new String[]{"item1", "item2"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING});
CompositeData data = new CompositeDataSupport(type, new String[]{"item1", "item2"}, new String[]{"item value 1", "item value 2"});

CompositeType compType = new CompositeType("compData", "compData", new String[]{"compItem1"}, new String[]{"compItem1"}, new OpenType[]{I_DONT_KNOW_WHAT_TO_PUT_HERE});
CompositeData compData = new CompositeDataSupport(compType, new String[]{"compData"}, data);

See the "I_DONT_KNOW_WHAT_TO_PUT_HERE" above, I could not find out how to pass an OpenType of CompositeData. And I have seen an examples of recursively getting the instances of nested CompositeData from CompositeData.

Some references:

http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/CompositeData.html http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/CompositeType.html http://docs.oracle.com/javase/6/docs/api/javax/management/openmbean/OpenType.html

dimir
  • 693
  • 6
  • 23

1 Answers1

1

The value of I_DONT_KNOW_WHAT_TO_PUT_HERE is type, but the 2nd argument in the constructor on code line 4 should have the string "compItem1", not "compData" since this represents the item name you defined in the 3rd parameter on code line 4.

Here's the full code:

    CompositeType type = new CompositeType("My Type", "My Type", new String[]{"item1", "item2"}, new String[]{"item1", "item2"}, new OpenType[]{SimpleType.STRING, SimpleType.STRING});
    CompositeData data = new CompositeDataSupport(type, new String[]{"item1", "item2"}, new String[]{"item value 1", "item value 2"});

    CompositeType compType = new CompositeType("compData", "compData", new String[]{"compItem1"}, new String[]{"compItem1"}, new OpenType[]{type});
    CompositeData compData = new CompositeDataSupport(compType, new String[]{"compItem1"}, new Object[]{data});

Have you considered using MXBeans ? Unless you really need all that additional meta-data, it's a much simpler (and maintainable) way to go for exposing complex attributes in JMX.

Nicholas
  • 15,916
  • 4
  • 42
  • 66
  • Thanks a lot, that helped! One additional question, is there anything I can do in the code to get rid of the warnings (I think it comes when nesting CompositeData): Note: com/example/MyMBean.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. – dimir Sep 07 '12 at 08:54
  • Yes, I have considered MXBeans but for my particular case I need explicitly to use MBeans. – dimir Sep 07 '12 at 08:55
  • 1
    Not sure. I did not get compiler warnings. Which javac version? Can you append the outputs? – Nicholas Sep 07 '12 at 09:15
  • Oh man, it was my other code that was causing those. Thanks again! :-) – dimir Sep 07 '12 at 09:19