kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject [kafka] branch trunk updated: MINOR: Fix JMX serialization by reverting lazy computation of JMX attributes (#5114)
Date Sat, 02 Jun 2018 20:15:17 GMT
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new adec6d6  MINOR: Fix JMX serialization by reverting lazy computation of JMX attributes
(#5114)
adec6d6 is described below

commit adec6d6e47e18882ba012ae4f1fa8793c18bd0e1
Author: Robert Yokota <rayokota@gmail.com>
AuthorDate: Sat Jun 2 13:14:55 2018 -0700

    MINOR: Fix JMX serialization by reverting lazy computation of JMX attributes (#5114)
    
    This reverts commit c9ec292135f26d1d70a (#5011). That
    commit introduces an anonymous inner class which retains a
    reference to the non-serializable outer class `KafkaMbean`
    breaking Serialization. This means that reading JMX metrics
    via JConsole or JmxTool no longer works since RMI relies
    on Java Serialization.
    
    Reviewers: Jason Gustafson <jason@confluent.io>, Dong Lin <lindong28@gmail.com>,
Ismael Juma <ismael@juma.me.uk>
---
 .../apache/kafka/common/metrics/JmxReporter.java   | 33 ++++++-------
 .../apache/kafka/common/metrics/LazyMBeanInfo.java | 57 ----------------------
 2 files changed, 14 insertions(+), 76 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java b/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
index 17d15be..063fb3b 100644
--- a/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
+++ b/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
@@ -214,25 +214,20 @@ public class JmxReporter implements MetricsReporter {
 
         @Override
         public MBeanInfo getMBeanInfo() {
-            return new LazyMBeanInfo(this.getClass().getName(), "", null, null, null) {
-                @Override
-                protected MBeanAttributeInfo[] buildAttributes() {
-                    MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()];
-                    int i = 0;
-                    for (Map.Entry<String, KafkaMetric> entry : metrics.entrySet())
{
-                        String attribute = entry.getKey();
-                        KafkaMetric metric = entry.getValue();
-                        attrs[i] = new MBeanAttributeInfo(attribute,
-                            double.class.getName(),
-                            metric.metricName().description(),
-                            true,
-                            false,
-                            false);
-                        i += 1;
-                    }
-                    return attrs;
-                }
-            };
+            MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()];
+            int i = 0;
+            for (Map.Entry<String, KafkaMetric> entry : this.metrics.entrySet()) {
+                String attribute = entry.getKey();
+                KafkaMetric metric = entry.getValue();
+                attrs[i] = new MBeanAttributeInfo(attribute,
+                                                  double.class.getName(),
+                                                  metric.metricName().description(),
+                                                  true,
+                                                  false,
+                                                  false);
+                i += 1;
+            }
+            return new MBeanInfo(this.getClass().getName(), "", attrs, null, null, null);
         }
 
         @Override
diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/LazyMBeanInfo.java b/clients/src/main/java/org/apache/kafka/common/metrics/LazyMBeanInfo.java
deleted file mode 100644
index 3827349..0000000
--- a/clients/src/main/java/org/apache/kafka/common/metrics/LazyMBeanInfo.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.kafka.common.metrics;
-
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanConstructorInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanOperationInfo;
-
-
-/**
- * an MBeanInfo subclass that lazily calculates attributes
- */
-public abstract class LazyMBeanInfo extends MBeanInfo {
-    private volatile MBeanAttributeInfo[] lazyAttrs = null;
-
-    public LazyMBeanInfo(
-        String className,
-        String description,
-        MBeanConstructorInfo[] constructors,
-        MBeanOperationInfo[] operations,
-        MBeanNotificationInfo[] notifications
-    ) throws IllegalArgumentException {
-        super(className, description, null, constructors, operations, notifications);
-    }
-
-    @Override
-    public MBeanAttributeInfo[] getAttributes() {
-        MBeanAttributeInfo[] val = lazyAttrs;
-        if (val != null) {
-            return val.clone(); //match upstream behaviour
-        }
-        val = buildAttributes();
-        if (val == null) {
-            val = new MBeanAttributeInfo[0];
-        }
-        lazyAttrs = val;
-        return val.clone();
-    }
-
-    protected abstract MBeanAttributeInfo[] buildAttributes();
-}

-- 
To stop receiving notification emails like this one, please contact
ijuma@apache.org.

Mime
View raw message