|
|
@ -39,19 +39,26 @@ public class Monitoring { |
|
|
|
* Register a MBean with the platform MBean server |
|
|
|
* Register a MBean with the platform MBean server |
|
|
|
* |
|
|
|
* |
|
|
|
* @param mbean |
|
|
|
* @param mbean |
|
|
|
* the mbean interface to register |
|
|
|
* the mbean object to register |
|
|
|
* @param metricName |
|
|
|
* @param metricName |
|
|
|
* name of the JGit metric, will be prefixed with |
|
|
|
* name of the JGit metric, will be prefixed with |
|
|
|
* "org.eclipse.jgit/" |
|
|
|
* "org.eclipse.jgit/" |
|
|
|
* @return the registered mbean's object instance |
|
|
|
* @return the registered mbean's object instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static @Nullable ObjectInstance registerMBean(Class mbean, |
|
|
|
public static @Nullable ObjectInstance registerMBean(Object mbean, |
|
|
|
String metricName) { |
|
|
|
String metricName) { |
|
|
|
boolean register; |
|
|
|
boolean register = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
register = SystemReader.getInstance().getUserConfig().getBoolean( |
|
|
|
Class<?> interfaces[] = mbean.getClass().getInterfaces(); |
|
|
|
|
|
|
|
for (Class<?> i : interfaces) { |
|
|
|
|
|
|
|
register = SystemReader.getInstance().getUserConfig() |
|
|
|
|
|
|
|
.getBoolean( |
|
|
|
ConfigConstants.CONFIG_JMX_SECTION, |
|
|
|
ConfigConstants.CONFIG_JMX_SECTION, |
|
|
|
mbean.getSimpleName(), false); |
|
|
|
i.getSimpleName(), false); |
|
|
|
|
|
|
|
if (register) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} catch (IOException | ConfigInvalidException e) { |
|
|
|
} catch (IOException | ConfigInvalidException e) { |
|
|
|
LOG.error(e.getMessage(), e); |
|
|
|
LOG.error(e.getMessage(), e); |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -61,7 +68,7 @@ public class Monitoring { |
|
|
|
} |
|
|
|
} |
|
|
|
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
|
|
|
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
ObjectName mbeanName = objectName(mbean, metricName); |
|
|
|
ObjectName mbeanName = objectName(mbean.getClass(), metricName); |
|
|
|
if (server.isRegistered(mbeanName)) { |
|
|
|
if (server.isRegistered(mbeanName)) { |
|
|
|
server.unregisterMBean(mbeanName); |
|
|
|
server.unregisterMBean(mbeanName); |
|
|
|
} |
|
|
|
} |
|
|
|