kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject git commit: kafka-1304; unregistered mbean exception in new producer; reviewed by Jay Kreps
Date Tue, 18 Mar 2014 17:55:24 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk cc859dcca -> 74e220925


kafka-1304; unregistered mbean exception in new producer; reviewed by Jay Kreps


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/74e22092
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/74e22092
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/74e22092

Branch: refs/heads/trunk
Commit: 74e22092519270428c067a5209ec3028e0745bea
Parents: cc859dc
Author: Jun Rao <junrao@gmail.com>
Authored: Tue Mar 18 10:55:19 2014 -0700
Committer: Jun Rao <junrao@gmail.com>
Committed: Tue Mar 18 10:55:19 2014 -0700

----------------------------------------------------------------------
 .../kafka/common/metrics/JmxReporter.java       | 32 +++++++++++---------
 1 file changed, 18 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/74e22092/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java
----------------------------------------------------------------------
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 c867c8d..3950eb1 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
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
 public class JmxReporter implements MetricsReporter {
 
     private static final Logger log = LoggerFactory.getLogger(JmxReporter.class);
-
+    private static final Object lock = new Object();
     private final String prefix;
     private final Map<String, KafkaMbean> mbeans = new HashMap<String, KafkaMbean>();
 
@@ -57,18 +57,21 @@ public class JmxReporter implements MetricsReporter {
     }
 
     @Override
-    public synchronized void init(List<KafkaMetric> metrics) {
-        for (KafkaMetric metric : metrics)
-            addAttribute(metric);
-        for (KafkaMbean mbean : mbeans.values())
-            reregister(mbean);
-
+    public void init(List<KafkaMetric> metrics) {
+        synchronized (lock) {
+            for (KafkaMetric metric : metrics)
+                addAttribute(metric);
+            for (KafkaMbean mbean : mbeans.values())
+                reregister(mbean);
+        }
     }
 
     @Override
-    public synchronized void metricChange(KafkaMetric metric) {
-        KafkaMbean mbean = addAttribute(metric);
-        reregister(mbean);
+    public void metricChange(KafkaMetric metric) {
+        synchronized (lock) {
+            KafkaMbean mbean = addAttribute(metric);
+            reregister(mbean);
+        }
     }
 
     private KafkaMbean addAttribute(KafkaMetric metric) {
@@ -85,10 +88,11 @@ public class JmxReporter implements MetricsReporter {
         }
     }
 
-    public synchronized void close() {
-        for (KafkaMbean mbean : this.mbeans.values())
-            unregister(mbean);
-
+    public void close() {
+        synchronized (lock) {
+            for (KafkaMbean mbean : this.mbeans.values())
+                unregister(mbean);
+        }
     }
 
     private void unregister(KafkaMbean mbean) {


Mime
View raw message