agresch commented on a change in pull request #3417:
URL: https://github.com/apache/storm/pull/3417#discussion_r732236032



##########
File path: storm-client/src/jvm/org/apache/storm/metric/SystemBolt.java
##########
@@ -63,33 +65,46 @@ public Long getValue() {
             }
         });
 
-        // newWorkerEvent: 1 when a worker is first started and 0 all other 
times.
-        // This can be used to tell when a worker has crashed and is restarted.
-        final IMetric newWorkerEvent = new IMetric() {
-            boolean doEvent = true;
 
-            @Override
-            public Object getValueAndReset() {
-                if (doEvent) {
-                    doEvent = false;
-                    return 1;
-                } else {
-                    return 0;
-                }
-            }
-        };
-        context.registerGauge("newWorkerEvent", new Gauge<Integer>() {
-            @Override
-            public Integer getValue() {
-                return (Integer) newWorkerEvent.getValueAndReset();
-            }
-        });
+        context.registerGauge("newWorkerEvent", new NewWorkerGauge());
 
         int bucketSize = 
ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
         registerMetrics(context, (Map<String, String>) 
topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
         registerMetrics(context, (Map<String, String>) 
topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
     }
 
+    // newWorkerEvent: 1 when a worker is first started and 0 all other times.
+    // This can be used to tell when a worker has crashed and is restarted.
+    private class NewWorkerImetric implements IMetric {
+        boolean doEvent = true;
+
+        @Override
+        public Object getValueAndReset() {
+            if (doEvent) {
+                doEvent = false;
+                return 1;
+            } else {
+                return 0;
+            }
+        }
+    }
+
+    // allow reporting new worker metric for multiple reporters if they 
support getValueForReporter().
+    private class NewWorkerGauge extends PerReporterGauge<Integer> {
+        private final NewWorkerImetric defaultValue = new NewWorkerImetric();
+        private final Map<Object, NewWorkerImetric> reporterValues = new 
HashMap<>();
+
+        @Override
+        public Integer getValue() {
+            return (Integer) defaultValue.getValueAndReset();
+        }

Review comment:
       getValueForReporter() should be called when possible, but reporters need 
to know that this gauge is of this class to do this.  So a codahale 
ConsoleReporter won't be calling this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@storm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to