Browse Source
* stable-5.2: Fix API problem filters Fix unclosed resource warning in SmartOutputStream JschConfigSessionFactory: fix boxing warning SshSupport#runSshCommand: don't throw exception in finally block Don't override already managed maven-compiler-plugin version Remove unused import from CreateFileSnapshotBenchmark Remove duplicate ignore_optional_problems entry in .classpath Update maven-site-plugin used by benchmark module to 3.8.2 Add dependency to enable site generation for benchmark module Ignore warnings for generated source code in org.eclipse.jgit.benchmark Fix MBean registration Enhance WindowCache statistics Change-Id: I67a07d92718188bdf7f8a13b83e9f538ecf4b22f Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>stable-5.3
Matthias Sohn
5 years ago
14 changed files with 606 additions and 85 deletions
@ -1,11 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|
||||||
<component id="org.eclipse.jgit.lfs" version="2"> |
|
||||||
<resource path="META-INF/MANIFEST.MF"> |
|
||||||
<filter id="924844039"> |
|
||||||
<message_arguments> |
|
||||||
<message_argument value="5.2.3"/> |
|
||||||
<message_argument value="5.2.0"/> |
|
||||||
</message_arguments> |
|
||||||
</filter> |
|
||||||
</resource> |
|
||||||
</component> |
|
@ -0,0 +1,89 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2019 Matthias Sohn <matthias.sohn@sap.com> |
||||||
|
* |
||||||
|
* This program and the accompanying materials are made available under the |
||||||
|
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||||
|
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
* |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
package org.eclipse.jgit.util; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.management.ManagementFactory; |
||||||
|
|
||||||
|
import javax.management.InstanceAlreadyExistsException; |
||||||
|
import javax.management.InstanceNotFoundException; |
||||||
|
import javax.management.MBeanRegistrationException; |
||||||
|
import javax.management.MBeanServer; |
||||||
|
import javax.management.MalformedObjectNameException; |
||||||
|
import javax.management.NotCompliantMBeanException; |
||||||
|
import javax.management.ObjectInstance; |
||||||
|
import javax.management.ObjectName; |
||||||
|
|
||||||
|
import org.eclipse.jgit.annotations.Nullable; |
||||||
|
import org.eclipse.jgit.errors.ConfigInvalidException; |
||||||
|
import org.eclipse.jgit.lib.ConfigConstants; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
/** |
||||||
|
* Enables monitoring JGit via JMX |
||||||
|
* |
||||||
|
* @since 5.1.13 |
||||||
|
*/ |
||||||
|
public class Monitoring { |
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(Monitoring.class); |
||||||
|
|
||||||
|
/** |
||||||
|
* Register a MBean with the platform MBean server |
||||||
|
* |
||||||
|
* @param mbean |
||||||
|
* the mbean object to register |
||||||
|
* @param metricName |
||||||
|
* name of the JGit metric, will be prefixed with |
||||||
|
* "org.eclipse.jgit/" |
||||||
|
* @return the registered mbean's object instance |
||||||
|
*/ |
||||||
|
public static @Nullable ObjectInstance registerMBean(Object mbean, |
||||||
|
String metricName) { |
||||||
|
boolean register = false; |
||||||
|
try { |
||||||
|
Class<?> interfaces[] = mbean.getClass().getInterfaces(); |
||||||
|
for (Class<?> i : interfaces) { |
||||||
|
register = SystemReader.getInstance().getUserConfig() |
||||||
|
.getBoolean( |
||||||
|
ConfigConstants.CONFIG_JMX_SECTION, |
||||||
|
i.getSimpleName(), false); |
||||||
|
if (register) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (IOException | ConfigInvalidException e) { |
||||||
|
LOG.error(e.getMessage(), e); |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (!register) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
||||||
|
try { |
||||||
|
ObjectName mbeanName = objectName(mbean.getClass(), metricName); |
||||||
|
if (server.isRegistered(mbeanName)) { |
||||||
|
server.unregisterMBean(mbeanName); |
||||||
|
} |
||||||
|
return server.registerMBean(mbean, mbeanName); |
||||||
|
} catch (MalformedObjectNameException | InstanceAlreadyExistsException |
||||||
|
| MBeanRegistrationException | NotCompliantMBeanException |
||||||
|
| InstanceNotFoundException e) { |
||||||
|
LOG.error(e.getMessage(), e); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static ObjectName objectName(Class mbean, String metricName) |
||||||
|
throws MalformedObjectNameException { |
||||||
|
return new ObjectName(String.format("org.eclipse.jgit/%s:type=%s", //$NON-NLS-1$
|
||||||
|
metricName, mbean.getSimpleName())); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue