eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-739] Fix eagle-metric checkstyle warnings
Date Wed, 09 Nov 2016 10:58:25 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 2f4df34cf -> 4df63def8


[EAGLE-739] Fix eagle-metric checkstyle warnings

[EAGLE-739]Fix eagle-metric checkstyle warnings

https://issues.apache.org/jira/browse/EAGLE-739

Author: koone <luokun1028@126.com>

Closes #637 from koone/EAGLE-739.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/4df63def
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/4df63def
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/4df63def

Branch: refs/heads/master
Commit: 4df63def83f1e33fd0899693d5ac751b24bf39a2
Parents: 2f4df34
Author: koone <luokun1028@126.com>
Authored: Wed Nov 9 18:58:18 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Wed Nov 9 18:58:18 2016 +0800

----------------------------------------------------------------------
 eagle-core/eagle-metric/pom.xml                      | 13 +++++++++++++
 .../eagle/metric/reportor/EagleCounterMetric.java    |  5 ++---
 .../eagle/metric/reportor/EagleGaugeMetric.java      |  3 ---
 .../eagle/metric/reportor/EagleMetricListener.java   |  3 ++-
 .../reportor/EagleServiceReporterMetricListener.java | 11 +++++------
 .../apache/eagle/metric/reportor/IEagleMetric.java   |  5 +++--
 .../eagle/metric/reportor/MetricEntityAdaptor.java   | 11 +++++------
 .../eagle/metric/reportor/MetricKeyCodeDecoder.java  | 15 ++++++++-------
 .../eagle-metric/src/test/resources/log4j.properties |  3 ---
 9 files changed, 38 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/pom.xml b/eagle-core/eagle-metric/pom.xml
index e4dee1a..225ecee 100644
--- a/eagle-core/eagle-metric/pom.xml
+++ b/eagle-core/eagle-metric/pom.xml
@@ -52,4 +52,17 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <failOnViolation>true</failOnViolation>
+                    <failsOnError>true</failsOnError>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleCounterMetric.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleCounterMetric.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleCounterMetric.java
index 0a7f70e..5251b46 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleCounterMetric.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleCounterMetric.java
@@ -44,7 +44,7 @@ public class EagleCounterMetric extends EagleMetric {
         for (EagleMetricListener listener : metricListeners) {
             EagleCounterMetric newEagleMetric = new EagleCounterMetric(this);
             newEagleMetric.name = MetricKeyCodeDecoder.addTimestampToMetricKey(trim(latestUserTimeClock),
newEagleMetric.name);
-            listener.onMetricFlushed(Arrays.asList((EagleMetric)newEagleMetric));
+            listener.onMetricFlushed(Arrays.asList((EagleMetric) newEagleMetric));
         }
     }
 
@@ -62,8 +62,7 @@ public class EagleCounterMetric extends EagleMetric {
                 LOG.warn("Something must be wrong, event should come in order of userTimeClock");
             }
             value.addAndGet(d);
-        }
-        else {
+        } else {
             flush(latestUserTimeClock);
             value.getAndSet(1);
             latestUserTimeClock = currentUserTimeClock;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleGaugeMetric.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleGaugeMetric.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleGaugeMetric.java
index e6fc098..3d75d32 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleGaugeMetric.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleGaugeMetric.java
@@ -22,9 +22,6 @@ package org.apache.eagle.metric.reportor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Arrays;
-import java.util.Map;
-
 public class EagleGaugeMetric extends EagleMetric {
 
     private static final Logger LOG = LoggerFactory.getLogger(EagleGaugeMetric.class);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleMetricListener.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleMetricListener.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleMetricListener.java
index d8fe7b2..f5d69f6 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleMetricListener.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleMetricListener.java
@@ -24,7 +24,8 @@ import java.util.List;
 public interface EagleMetricListener {
 
     /**
-     * The method should be called in thread-safe mode
+     * The method should be called in thread-safe mode.
+     *
      * @param metrics
      */
     void onMetricFlushed(List<EagleMetric> metrics);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleServiceReporterMetricListener.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleServiceReporterMetricListener.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleServiceReporterMetricListener.java
index 49a8cdc..6ebf473 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleServiceReporterMetricListener.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/EagleServiceReporterMetricListener.java
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
 import java.util.List;
 
-public class EagleServiceReporterMetricListener implements EagleMetricListener{
+public class EagleServiceReporterMetricListener implements EagleMetricListener {
 
     private EagleServiceClientImpl client;
     private static final Logger LOG = LoggerFactory.getLogger(EagleServiceReporterMetricListener.class);
@@ -50,13 +50,12 @@ public class EagleServiceReporterMetricListener implements EagleMetricListener{
         try {
             int total = entities.size();
             GenericServiceAPIResponseEntity<String> response = client.create(entities,
GenericMetricEntity.GENERIC_METRIC_SERVICE);
-            if(response.isSuccess()) {
+            if (response.isSuccess()) {
                 LOG.info("Wrote " + total + " entities to service");
-            }else{
-                LOG.error("Failed to write " + total + " entities to service, due to server
exception: "+ response.getException());
+            } else {
+                LOG.error("Failed to write " + total + " entities to service, due to server
exception: " + response.getException());
             }
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             LOG.error("Got exception while writing entities: ", ex);
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/IEagleMetric.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/IEagleMetric.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/IEagleMetric.java
index 43f8092..fa43081 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/IEagleMetric.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/IEagleMetric.java
@@ -23,7 +23,7 @@ import com.codahale.metrics.Gauge;
 
 /**
  * It's just a workaround to extends Gauge instead of Metric interface
- * For MetricRegistry's notifyListenerOfRemovedMetric method will throw exception on unknown
metric type
+ * For MetricRegistry's notifyListenerOfRemovedMetric method will throw exception on unknown
metric type.
  */
 
 public interface IEagleMetric extends Gauge<Double> {
@@ -31,7 +31,8 @@ public interface IEagleMetric extends Gauge<Double> {
     void registerListener(EagleMetricListener listener);
 
     /**
-     * return true if the metric need to be flushed, otherwise return false
+     * return true if the metric need to be flushed, otherwise return false.
+     *
      * @param value
      * @param userTimeClock
      * @return

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricEntityAdaptor.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricEntityAdaptor.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricEntityAdaptor.java
index e1f8154..65089d7 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricEntityAdaptor.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricEntityAdaptor.java
@@ -28,19 +28,18 @@ public class MetricEntityAdaptor {
         //TODO: add other type metric support
         EagleMetricKey metricName = MetricKeyCodeDecoder.decodeTSMetricKey(name);
         if (metric instanceof EagleCounterMetric) {
-            EagleCounterMetric counter = (EagleCounterMetric)metric;
+            EagleCounterMetric counter = (EagleCounterMetric) metric;
             GenericMetricEntity entity = new GenericMetricEntity();
             entity.setPrefix(metricName.metricName);
-            entity.setValue(new double[]{counter.getValue()});
+            entity.setValue(new double[] {counter.getValue()});
             entity.setTags(metricName.tags);
             entity.setTimestamp(metricName.timestamp);
             return entity;
-        }
-        else if (metric instanceof EagleGaugeMetric) {
-            EagleGaugeMetric gauge = (EagleGaugeMetric)metric;
+        } else if (metric instanceof EagleGaugeMetric) {
+            EagleGaugeMetric gauge = (EagleGaugeMetric) metric;
             GenericMetricEntity entity = new GenericMetricEntity();
             entity.setPrefix(metricName.metricName);
-            entity.setValue(new double[]{gauge.getValue()});
+            entity.setValue(new double[] {gauge.getValue()});
             entity.setTags(metricName.tags);
             entity.setTimestamp(metricName.timestamp);
             return entity;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricKeyCodeDecoder.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricKeyCodeDecoder.java
b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricKeyCodeDecoder.java
index 3ee55a3..1ad8063 100644
--- a/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricKeyCodeDecoder.java
+++ b/eagle-core/eagle-metric/src/main/java/org/apache/eagle/metric/reportor/MetricKeyCodeDecoder.java
@@ -25,19 +25,20 @@ import java.util.Map;
 /**
  * TODO: Refactor metric implementation, which is not very solid.
  *
- * metricKey = metricName[/[key=char|whitespace]*]*
+ * <p>metricKey = metricName[/[key=char|whitespace]*]*
  */
 @Deprecated
 public class MetricKeyCodeDecoder {
-    private final static String SEPERATOR = "/";
+    private static final String SEPERATOR = "/";
+
     public static String codeMetricKey(String metricName, Map<String, String> tags)
{
         StringBuilder sb = new StringBuilder();
         sb.append(metricName);
         for (Map.Entry<String, String> entry : tags.entrySet()) {
             String key = entry.getKey();
             String value = entry.getValue();
-            if(key.contains(SEPERATOR)||value.contains(SEPERATOR)){
-                throw new IllegalStateException("Invalid metric tag pair <"+key+":"+value+">
which contains reserved char: "+SEPERATOR);
+            if (key.contains(SEPERATOR) || value.contains(SEPERATOR)) {
+                throw new IllegalStateException("Invalid metric tag pair <" + key + ":"
+ value + "> which contains reserved char: " + SEPERATOR);
             }
             sb.append(SEPERATOR).append(key).append(":").append(value);
         }
@@ -45,7 +46,7 @@ public class MetricKeyCodeDecoder {
     }
 
     /**
-     * @param name metricName[/[key=char|whitespace]*]*
+     * @param name metricName[/[key=char|whitespace]*]*.
      * @return
      */
     public static EagleMetricKey decodeMetricKey(String name) {
@@ -55,10 +56,10 @@ public class MetricKeyCodeDecoder {
         metricName.tags = new HashMap<>();
         for (int i = 1; i < parts.length; i++) {
             String[] keyValue = parts[i].split(":");
-            if(keyValue.length >1) {
+            if (keyValue.length > 1) {
                 metricName.tags.put(keyValue[0], keyValue[1]);
             } else {
-                throw new IllegalStateException("Failed to decode metric name '"+name+"',
because '"+parts[i]+"' is invalid, expected in format: 'key:value'");
+                throw new IllegalStateException("Failed to decode metric name '" + name +
"', because '" + parts[i] + "' is invalid, expected in format: 'key:value'");
             }
         }
         return metricName;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4df63def/eagle-core/eagle-metric/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metric/src/test/resources/log4j.properties b/eagle-core/eagle-metric/src/test/resources/log4j.properties
index dccbc70..4b40fd4 100644
--- a/eagle-core/eagle-metric/src/test/resources/log4j.properties
+++ b/eagle-core/eagle-metric/src/test/resources/log4j.properties
@@ -12,16 +12,13 @@
 # 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.
-
 log4j.rootLogger=INFO, stdout
 #eagle.log.dir=./logs
 #eagle.log.file=eagle.log
-
 # standard output
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %p [%t] %c{2}[%L]: %m%n
-
 ## Daily Rolling File Appender
 #log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender
 #log4j.appender.DRFA.File=${eagle.log.dir}/${eagle.log.file}


Mime
View raw message