Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added example of using @WithSession

...

Code Block
languagejava
JMXService jmxSvc = Context.getService(JMXService.class);
jmxSvc.registerMBean("HelloWorld", null, new HelloWorldMBeanImpl());

And ...and unregister it when it shuts down, e.g.

Code Block
languagejava
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
languagejava

@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