You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by sr...@apache.org on 2019/07/04 17:59:37 UTC

[storm] branch master updated: STORM-3445: metrics: fix all checkstyle warnings

This is an automated email from the ASF dual-hosted git repository.

srdo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git


The following commit(s) were added to refs/heads/master by this push:
     new fceb59a  STORM-3445: metrics: fix all checkstyle warnings
     new 2e9d2a3  Merge pull request #3060 from krichter722/checkstyle-metrics
fceb59a is described below

commit fceb59af05b672540b223ef9ed1308eafe9e5ae9
Author: Karl-Philipp Richter <kr...@posteo.de>
AuthorDate: Mon Jul 1 20:24:52 2019 +0200

    STORM-3445: metrics: fix all checkstyle warnings
---
 external/storm-metrics/pom.xml                     |  2 +-
 .../metrics/hdrhistogram/HistogramMetric.java      | 24 +++++-----
 .../org/apache/storm/metrics/sigar/CPUMetric.java  | 51 ++++++++++++----------
 3 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/external/storm-metrics/pom.xml b/external/storm-metrics/pom.xml
index bc7c4d0..5cb3ec3 100644
--- a/external/storm-metrics/pom.xml
+++ b/external/storm-metrics/pom.xml
@@ -102,7 +102,7 @@
         <artifactId>maven-checkstyle-plugin</artifactId>
         <!--Note - the version would be inherited-->
         <configuration>
-          <maxAllowedViolations>32</maxAllowedViolations>
+          <maxAllowedViolations>0</maxAllowedViolations>
         </configuration>
       </plugin>
       <plugin>
diff --git a/external/storm-metrics/src/main/java/org/apache/storm/metrics/hdrhistogram/HistogramMetric.java b/external/storm-metrics/src/main/java/org/apache/storm/metrics/hdrhistogram/HistogramMetric.java
index 7f58a3d..99b21c6 100644
--- a/external/storm-metrics/src/main/java/org/apache/storm/metrics/hdrhistogram/HistogramMetric.java
+++ b/external/storm-metrics/src/main/java/org/apache/storm/metrics/hdrhistogram/HistogramMetric.java
@@ -15,17 +15,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.storm.metrics.hdrhistogram;
 
-import org.apache.storm.metric.api.IMetric;
 import org.HdrHistogram.Histogram;
+import org.apache.storm.metric.api.IMetric;
 
 /**
  * A metric wrapping an HdrHistogram.
  */
 public class HistogramMetric implements IMetric {
-    private final Histogram _histo;
-
+    private final Histogram histo;
 
     public HistogramMetric(final int numberOfSignificantValueDigits) {
         this(null, numberOfSignificantValueDigits);
@@ -57,23 +57,27 @@ public class HistogramMetric implements IMetric {
     public HistogramMetric(Long lowestDiscernibleValue, Long highestTrackableValue,
                      final int numberOfSignificantValueDigits) {
         boolean autoResize = false;
-        if (lowestDiscernibleValue == null) lowestDiscernibleValue = 1L;
+        if (lowestDiscernibleValue == null) {
+            lowestDiscernibleValue = 1L;
+        }
         if (highestTrackableValue == null) {
             highestTrackableValue = 2 * lowestDiscernibleValue;
             autoResize = true;
         }
-        _histo = new Histogram(lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits);
-        if (autoResize) _histo.setAutoResize(true);
+        histo = new Histogram(lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits);
+        if (autoResize) {
+            histo.setAutoResize(true);
+        }
     }
 
     public void recordValue(long val) {
-        _histo.recordValue(val);
+        histo.recordValue(val);
     }
 
     @Override
     public Object getValueAndReset() {
-          Histogram copy = _histo.copy();
-          _histo.reset();
-          return copy;
+        Histogram copy = histo.copy();
+        histo.reset();
+        return copy;
     }
 }
diff --git a/external/storm-metrics/src/main/java/org/apache/storm/metrics/sigar/CPUMetric.java b/external/storm-metrics/src/main/java/org/apache/storm/metrics/sigar/CPUMetric.java
index 7c6d75e..59dac42 100644
--- a/external/storm-metrics/src/main/java/org/apache/storm/metrics/sigar/CPUMetric.java
+++ b/external/storm-metrics/src/main/java/org/apache/storm/metrics/sigar/CPUMetric.java
@@ -15,46 +15,49 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.storm.metrics.sigar;
 
-import org.hyperic.sigar.Sigar;
-import org.hyperic.sigar.ProcCpu;
+import java.util.HashMap;
 
 import org.apache.storm.metric.api.IMetric;
 
-import java.util.HashMap;
+import org.hyperic.sigar.ProcCpu;
+import org.hyperic.sigar.Sigar;
 
 /**
  * A metric using Sigar to get User and System CPU utilization for a worker.
  */
+@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
 public class CPUMetric implements IMetric {
-    private long _prevUser = 0;
-    private long _prevSys = 0;
-    private final Sigar _sigar;
-    private final long _pid;
+    private long prevUser = 0;
+    private long prevSys = 0;
+    private final Sigar sigar;
+    private final long pid;
 
     public CPUMetric() {
-        _sigar = new Sigar();
-        _pid = _sigar.getPid();
+        sigar = new Sigar();
+        pid = sigar.getPid();
     }
 
     @Override
     public Object getValueAndReset() {
         try {
-          ProcCpu cpu = _sigar.getProcCpu(_pid);
-          long userTotal = cpu.getUser();
-          long sysTotal = cpu.getSys();
-          long user = userTotal - _prevUser;
-          long sys = sysTotal - _prevSys;
-          _prevUser = userTotal;
-          _prevSys = sysTotal;
-
-          HashMap<String, Long> ret = new HashMap<String, Long>();
-          ret.put("user-ms", user);
-          ret.put("sys-ms", sys);
-          return ret;
-      } catch (Exception e) {
-          throw new RuntimeException(e);
-      }
+            ProcCpu cpu = sigar.getProcCpu(pid);
+            long userTotal = cpu.getUser();
+            long sysTotal = cpu.getSys();
+            long user = userTotal - prevUser;
+            @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
+            long sys = sysTotal - prevSys;
+            prevUser = userTotal;
+            prevSys = sysTotal;
+
+            HashMap<String, Long> ret = new HashMap<String, Long>();
+            ret.put("user-ms", user);
+            ret.put("sys-ms", sys);
+            return ret;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 }