...
Code Block |
---|
|
JMXService jmxSvc = Context.getService(JMXService.class);
jmxSvc.registerMBean("HelloWorld", null, new HelloWorldMBeanImpl());
|
And ...and unregister it when it shuts down, e.g.
Code Block |
---|
|
jmxSvc.unregisterMBean("HelloWorld", null);
|
Usually you will want to access OpenMRS services to get the values of your bean properties. This requires a valid OpenMRS session with the correct privileges for those service methods. To make this easier, the JMX module defines an annotation which will wrap the method call in a temporary OpenMRS session with the requested privileges, e.g.
Code Block |
---|
|
@MXBean
public interface HelloWorldMBean {
@WithSession({PrivilegeConstants.VIEW_ADMIN_FUNCTIONS})
public String getMessage();
}
|
Source code
Project code is hosted on github at https://github.com/rowanseymour/openmrs-module-jmx