java - JMXBean entries are not showing up -
implementation of jmxbean
performancemetadata jmxbean = new performancemetadata(); responsedocument = (document) serviceoperation.invoke(servicecomponent,requestdocument); jmxbean.setnumofrequests(1);
jmxbean class:
public class performancemetadata implements performancemetadatambean{ private int numofrequests; public int getnumofrequests() { return numofrequests; } public void setnumofrequests(int numofrequests) { this.numofrequests = numofrequests; }
class registering jmxbean: call class while booting server.
public class jmxbeans { public void registerjmxbeans() { mbeanserver mbs = null; performancemetadata metadataobj = null; objectname name; try { metadataobj = new performancemetadata(); mbs = managementfactory.getplatformmbeanserver(); name = new objectname("test.performace:type=performancemetadatambean"); mbs.registermbean(metadataobj, name); }
but don't see value jmxbean.numberofrequests
the issue here instance of bean being registered not same instance setting values on. need coordinate passing around same instance registered (optionally implementing singleton) or update mbean using jmx operation. complexity of executing jmx operation can simplified creating proxy invoker. suggest approach:
change numofrequests field atomicinteger since want make mbean thread-safe[er]. ie.
your mbean , interface should have attribute accessor (a getter) , incrementor.
interface
public int getnumofrequests(); public void incrementnumofrequests(int requests);
implementation
private final atomicinteger numofrequests = new atomicinteger(0); public int getnumofrequests() { return numofrequests.get(); } public void incrementnumofrequests(int requests) { numofrequests.addandget(requests); }
now can register bean instance once, , update through jmx proxies can generate on fly. done using mbeanserverinvocationhandler.
performancemetadatambean proxy = (performancemetadatambean)mbeanserverinvocationhandler.newproxyinstance(managementfactory.getplatformmbeanserver(), new objectname("test.performace:type=performancemetadatambean"), performancemetadatambean.class, false);
now, when invoke proxy.incrementnumofrequests(14)
, under covers, invoking bean's incrementnumofrequests operation.
give spin.