package com.mongodb.internal.management.jmx;
import com.mongodb.diagnostics.logging.Logger;
import com.mongodb.diagnostics.logging.Loggers;
import com.mongodb.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
public class JMXMBeanServer implements MBeanServer {
private static final Logger LOGGER = Loggers.getLogger("management");
@Override
public void registerMBean(final Object mBean, final String mBeanName) {
try {
server.registerMBean(mBean, new ObjectName(mBeanName));
} catch (Exception e) {
LOGGER.warn("Unable to register MBean " + mBeanName, e);
}
}
@Override
public void unregisterMBean(final String mBeanName) {
try {
ObjectName objectName = new ObjectName(mBeanName);
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
} catch (Exception e) {
LOGGER.warn("Unable to unregister MBean " + mBeanName, e);
}
}
private final javax.management.MBeanServer server = ManagementFactory.getPlatformMBeanServer();
}