Skip to content

Instantly share code, notes, and snippets.

@rangalo
Last active August 29, 2015 14:19
Show Gist options
  • Save rangalo/ee934ee3b0c2b906c8a9 to your computer and use it in GitHub Desktop.
Save rangalo/ee934ee3b0c2b906c8a9 to your computer and use it in GitHub Desktop.
Registering jmx
@PostConstruct
public void registerInJMX() {
try {
objectName = new ObjectName("Scope1:type=" + this.getClass().getName());
platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
platformMBeanServer.registerMBean(sc.getBusinessObject(HealthMonitor.class), objectName);
} catch (IllegalStateException | InstanceAlreadyExistsException | MBeanRegistrationException | MalformedObjectNameException | NotCompliantMBeanException e) {
throw new IllegalStateException("Problem during registration of Monitoring into JMX:" + e);
}
}
@PreDestroy
public void unregisterFromJMX() {
try {
platformMBeanServer.unregisterMBean(this.objectName);
} catch (InstanceNotFoundException | MBeanRegistrationException e) {
throw new IllegalStateException("Problem during unregistration of Monitoring into JMX:" + e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment