List of usage examples for javax.management MBeanServer registerMBean
public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException;
Registers a pre-existing object as an MBean with the MBean server.
From source file:com.frameworkset.commons.dbcp2.BasicDataSource.java
private void jmxRegister() { // Return immediately if this DataSource has already been registered if (registeredJmxName != null) { return;//w w w . j a v a 2s . com } // Return immediately if no JMX name has been specified String requestedName = getJmxName(); if (requestedName == null) { return; } ObjectName oname; try { oname = new ObjectName(requestedName); } catch (MalformedObjectNameException e) { log.warn("The requested JMX name [" + requestedName + "] was not valid and will be ignored."); return; } MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { mbs.registerMBean(this, oname); } catch (InstanceAlreadyExistsException e) { log.warn("Failed to complete JMX registration", e); } catch (MBeanRegistrationException e) { log.warn("Failed to complete JMX registration", e); } catch (NotCompliantMBeanException e) { log.warn("Failed to complete JMX registration", e); } }