You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2018/01/06 16:41:14 UTC

[incubator-plc4x] branch master updated: SONAR Some further fixing of issues sonarqube reported

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

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new 464d125  SONAR Some further fixing of issues sonarqube reported
464d125 is described below

commit 464d1254770a9149fbdb7264b756bc6e98366d0d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Jan 6 17:41:10 2018 +0100

    SONAR
    Some further fixing of issues sonarqube reported
---
 applications/iotree/pom.xml                             |  5 +++++
 .../apache/plc4x/java/applications/iotree/IoTree.java   | 17 ++++++++++-------
 applications/plclogger/pom.xml                          |  5 +++++
 .../plc4x/java/applications/plclogger/PlcLogger.java    | 16 +++++++++-------
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/applications/iotree/pom.xml b/applications/iotree/pom.xml
index 0199d2d..b1139db 100644
--- a/applications/iotree/pom.xml
+++ b/applications/iotree/pom.xml
@@ -54,6 +54,11 @@
       <artifactId>edgent-providers-direct</artifactId>
       <version>1.2.0</version>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.25</version>
+    </dependency>
 
     <!-- Required driver implementation -->
     <dependency>
diff --git a/applications/iotree/src/main/java/org/apache/plc4x/java/applications/iotree/IoTree.java b/applications/iotree/src/main/java/org/apache/plc4x/java/applications/iotree/IoTree.java
index f43bfb0..d3591f6 100644
--- a/applications/iotree/src/main/java/org/apache/plc4x/java/applications/iotree/IoTree.java
+++ b/applications/iotree/src/main/java/org/apache/plc4x/java/applications/iotree/IoTree.java
@@ -24,12 +24,17 @@ import org.apache.edgent.topology.TStream;
 import org.apache.edgent.topology.Topology;
 import org.apache.plc4x.edgent.PlcConnectionAdapter;
 import org.apache.plc4x.edgent.PlcFunctions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class IoTree {
 
+    private static final Logger logger = LoggerFactory.getLogger(IoTree.class);
+
     private final PlcConnectionAdapter plcAdapter;
 
     private AtomicInteger internalVariables;
@@ -49,7 +54,7 @@ public class IoTree {
         digitalOutput = new AtomicInteger(0);
     }
 
-    private void run() throws Exception {
+    private void run() throws InterruptedException, IOException {
         DirectProvider dp = new DirectProvider();
         Topology top = dp.newTopology();
         // Automatically update the internal variable values ...
@@ -79,7 +84,6 @@ public class IoTree {
             System.out.println(String.format("Internal Variables: %d Digital In: %d Analog In: %d Amplifictaion: %d Max Value: %d Digital Out: %d",
                 internalVariables.get(), digitalInput.get(), analogInput.get(), amplification.get(), maxValue.get(), digitalOutput.get()));
         }
-        System.exit(0);
     }
 
     public static void main(String[] args) {
@@ -92,14 +96,13 @@ public class IoTree {
         try (PlcConnectionAdapter plcAdapter = new PlcConnectionAdapter(args[0])) {
             // Initialize the tree itself
             IoTree tree = new IoTree(plcAdapter);
+
             // Start the tree ...
             tree.run();
-            // Yeah ... well prevent the application from exiting ;-)
-            while (true) {
-                Thread.sleep(1000);
-            }
+
+            System.exit(0);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("Caught exception", e);
         }
     }
 
diff --git a/applications/plclogger/pom.xml b/applications/plclogger/pom.xml
index 4520abd..0607945 100644
--- a/applications/plclogger/pom.xml
+++ b/applications/plclogger/pom.xml
@@ -54,6 +54,11 @@
       <artifactId>edgent-providers-direct</artifactId>
       <version>1.2.0</version>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.25</version>
+    </dependency>
 
     <!-- Required driver implementation -->
     <dependency>
diff --git a/applications/plclogger/src/main/java/org/apache/plc4x/java/applications/plclogger/PlcLogger.java b/applications/plclogger/src/main/java/org/apache/plc4x/java/applications/plclogger/PlcLogger.java
index f8e79ea..6d97297 100644
--- a/applications/plclogger/src/main/java/org/apache/plc4x/java/applications/plclogger/PlcLogger.java
+++ b/applications/plclogger/src/main/java/org/apache/plc4x/java/applications/plclogger/PlcLogger.java
@@ -29,9 +29,13 @@ import org.apache.edgent.topology.TStream;
 import org.apache.edgent.topology.Topology;
 import org.apache.plc4x.edgent.PlcConnectionAdapter;
 import org.apache.plc4x.edgent.PlcFunctions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class PlcLogger {
 
+    private static final Logger logger = LoggerFactory.getLogger(PlcLogger.class);
+
     private final PlcConnectionAdapter plcAdapter;
     private final String addressStr;
     private final int interval;
@@ -42,16 +46,12 @@ public class PlcLogger {
         this.interval = interval;
     }
 
-    private void run() throws Exception {
+    private void run() {
         AtomicInteger counter = new AtomicInteger(0);
         AtomicLong totalTime = new AtomicLong(0);
         DirectProvider dp = new DirectProvider();
         Topology top = dp.newTopology();
-        // normally would just do the following
-        //   TStream<Byte> source = top.poll(
-        //       PlcFunctions.byteSupplier(adapter, addressStr),
-        //       interval, TimeUnit.MILLISECONDS);
-        // but in this case we want to make some timing measurements
+
         Supplier<Byte> plcSupplier = PlcFunctions.byteSupplier(plcAdapter, addressStr);
         TStream<Byte> source = top.poll(() -> {
             long start = Calendar.getInstance().getTimeInMillis();
@@ -90,8 +90,10 @@ public class PlcLogger {
             while (System.in.available() == 0) {
                 Thread.sleep(1000);
             }
+
+            System.exit(0);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("Caught exception", e);
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].