jmx - Java MXBean custom types -
i trying create mxbean custom attribute, javax.management.notcompliantmbeanexception ijmsdestinationmbean.getattributes has parameter or homecoming type cannot translated open type
i have read mxbean attributes have opentype compatible. how create attribute work way? classes below in same package.
class jmsdestinationmbean implements ijmsdestinationmbean{ protected jmsdestinationattributes attributes = new jmsdestinationattributes(); @override public jmsdestinationattributes getattributes() { homecoming this.attributes; } } @mxbean interface ijmsdestinationmbean { jmsdestinationattributes getattributes() } class jmsdestinationattributes { protected string name protected int messagescurrentcount protected int consumerscurrentcount string getname() { this.name; } int getmessagescurrentcount() { this.messagescurrentcount; } int getconsumerscurrentcount() { this.consumerscurrentcount; } }
the problem interface ijmsdestinationmbean. returns type jmsdestinationattributes not open type. here's rules-of-thumb follow when doing this:
the actual registered mbean (which has complex typed attribute) called foo , it's management interface called foomxbean. the complex type (the attribute of foo called bar , has management interface called barmbean. guy cannot homecoming values not open types or other exposed complex types.so (for example) "host" mbean needs mxbean in order back upwards complex types , , complex type needs have interface called <classname>mbean. note 1 has m*x*bean interface, , other has mbean interface.
here's example:
jmsdestination implements jmsdestinationmxbean jmsdestinationattributes implements jmsdestinationattributesmbean...apologies loose case standard. it's on fly example.
here jmsdestination code, main create , register. using user name property provide name.:
public class jmsdestination implements jmsdestinationmxbean { protected jmsdestinationattributes attrs = new jmsdestinationattributes(system.getproperty("user.name")); public jmsdestinationattributes getattributes() { homecoming attrs; } public static void main(string[] args) { jmsdestination impl = new jmsdestination(); seek { managementfactory.getplatformmbeanserver().registermbean(impl, new objectname("org.jms.impl.test:name=" + impl.attrs.getname())); thread.currentthread().join(); } grab (exception ex) { ex.printstacktrace(system.err); } } } the jmsdestinationmxbean code:
public interface jmsdestinationmxbean { public jmsdestinationattributes getattributes(); } the jmsdestinationattributes code uses same name , random numbers values:
public class jmsdestinationattributes implements jmsdestinationattributesmbean { protected final string name; protected final random random = new random(system.currenttimemillis()); public jmsdestinationattributes(string name) { this.name = name; } public string getname() { homecoming name; } public int getmessagescurrentcount() { homecoming math.abs(random.nextint(100)); } public int getconsumerscurrentcount() { homecoming math.abs(random.nextint(10)); } } .... , jmsdestinationattributesmbean:
public interface jmsdestinationattributesmbean { public string getname(); public int getmessagescurrentcount(); public int getconsumerscurrentcount(); } the jconsole view looks this:
the jconsole view of mxbean's attributes looks this:
make sense ?
java jmx mbeans
No comments:
Post a Comment