lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [lucene-solr] branch jira/solr-14691 updated: SOLR-14691: Lazily init the jmxAttributes map.
Date Wed, 07 Oct 2020 11:16:21 GMT
This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-14691
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/jira/solr-14691 by this push:
     new c9687b8  SOLR-14691: Lazily init the jmxAttributes map.
c9687b8 is described below

commit c9687b875c9b14a6b443a70972852b34bf0ff02b
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Wed Oct 7 13:15:53 2020 +0200

    SOLR-14691: Lazily init the jmxAttributes map.
---
 .../java/org/apache/solr/metrics/MetricsMap.java   | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/metrics/MetricsMap.java b/solr/core/src/java/org/apache/solr/metrics/MetricsMap.java
index d2e0cec..9566262 100644
--- a/solr/core/src/java/org/apache/solr/metrics/MetricsMap.java
+++ b/solr/core/src/java/org/apache/solr/metrics/MetricsMap.java
@@ -62,7 +62,7 @@ public class MetricsMap implements Gauge<Map<String,Object>>,
MapWriter, Dynamic
 
   private BiConsumer<Boolean, Map<String, Object>> mapInitializer;
   private MapWriter initializer;
-  private Map<String, String> jmxAttributes = new HashMap<>();
+  private Map<String, String> jmxAttributes;
   private volatile Map<String,Object> cachedValue;
 
   /**
@@ -101,13 +101,22 @@ public class MetricsMap implements Gauge<Map<String,Object>>,
MapWriter, Dynamic
     return getValue().toString();
   }
 
+  // lazy init
+  private synchronized void initJmxAttributes() {
+    if (jmxAttributes == null) {
+      jmxAttributes = new HashMap<>();
+    }
+  }
+
   @Override
   public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException,
ReflectionException {
     Object val;
     // jmxAttributes override any real values
-    val = jmxAttributes.get(attribute);
-    if (val != null) {
-      return val;
+    if (jmxAttributes != null) {
+      val = jmxAttributes.get(attribute);
+      if (val != null) {
+        return val;
+      }
     }
     Map<String,Object> stats = null;
     if (useCachedStatsBetweenGetMBeanInfoCalls) {
@@ -137,6 +146,7 @@ public class MetricsMap implements Gauge<Map<String,Object>>,
MapWriter, Dynamic
 
   @Override
   public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException {
+    initJmxAttributes();
     jmxAttributes.put(attribute.getName(), String.valueOf(attribute.getValue()));
   }
 
@@ -170,13 +180,15 @@ public class MetricsMap implements Gauge<Map<String,Object>>,
MapWriter, Dynamic
     if (useCachedStatsBetweenGetMBeanInfoCalls) {
       cachedValue = stats;
     }
-    jmxAttributes.forEach((k, v) -> {
-      attrInfoList.add(new MBeanAttributeInfo(k, String.class.getName(),
-          null, true, false, false));
-    });
+    if (jmxAttributes != null) {
+      jmxAttributes.forEach((k, v) -> {
+        attrInfoList.add(new MBeanAttributeInfo(k, String.class.getName(),
+            null, true, false, false));
+      });
+    }
     try {
       stats.forEach((k, v) -> {
-        if (jmxAttributes.containsKey(k)) {
+        if (jmxAttributes != null && jmxAttributes.containsKey(k)) {
           return;
         }
         @SuppressWarnings({"rawtypes"})


Mime
View raw message