SOLR-13712: JMX MBeans are not exposed because of race condition between creating platform mbean server and registering mbeans

This commit is contained in:
Shalin Shekhar Mangar 2019-09-29 10:09:58 +05:30
parent 0dfbf557ba
commit 2ba61c8fb9
4 changed files with 11 additions and 7 deletions

View File

@ -246,6 +246,9 @@ Bug Fixes
* SOLR-13417: Handle stats aggregation on date and string fields in SolrJ's JSON facet response processing
(Jason Gerlowski, Munendra S N)
* SOLR-13712: JMX MBeans are not exposed because of race condition between creating platform mbean server and
registering mbeans. (shalin)
Other Changes
----------------------

View File

@ -70,7 +70,7 @@ public class SolrJmxReporter extends FilteringSolrMetricReporter {
protected synchronized void doInit() {
if (serviceUrl != null && agentId != null) {
mBeanServer = JmxUtil.findFirstMBeanServer();
log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured, using first MBeanServer instead of configuration.",
log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured, using first MBeanServer {} instead of configuration.",
serviceUrl, agentId, mBeanServer);
} else if (serviceUrl != null) {
// reuse existing services

View File

@ -28,7 +28,6 @@ import javax.management.Query;
import javax.management.QueryExp;
import java.io.Closeable;
import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -157,9 +156,6 @@ public class JmxMetricsReporter implements Reporter, Closeable {
}
public JmxMetricsReporter build() {
if (mBeanServer == null) {
mBeanServer = ManagementFactory.getPlatformMBeanServer();
}
if (tag == null) {
tag = Integer.toHexString(this.hashCode());
}

View File

@ -23,6 +23,7 @@ import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.List;
/**
@ -31,12 +32,16 @@ import java.util.List;
public final class JmxUtil {
/**
* Retrieve the first MBeanServer found.
* Retrieve the first MBeanServer found and if not found return the platform mbean server
*
* @return the first MBeanServer found
*/
public static MBeanServer findFirstMBeanServer() {
return findMBeanServerForAgentId(null);
MBeanServer mBeanServer = findMBeanServerForAgentId(null);
if (mBeanServer == null) {
return ManagementFactory.getPlatformMBeanServer();
}
return mBeanServer;
}
/**