Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce number of Sonar smells in Java examples.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 Oct 2017 21:30:50 +0000 (23:30 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 9 Oct 2017 19:14:47 +0000 (21:14 +0200)
examples/java/dht/kademlia/Node.java
examples/java/trace/pingpong/Main.java
examples/java/trace/pingpong/Receiver.java
examples/java/trace/pingpong/Sender.java

index 841e9d1be8c86956b9689eec31c1db0fb5d4d52b..a690a0177d2cce5bc4a2d525c93006c3a054b6c4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2014, 2016. The SimGrid Team.
+/* Copyright (c) 2012-2014, 2016-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -77,6 +77,7 @@ public class Node extends Process {
         }
       }
       catch (Exception e) {
+        Msg.debug("Caught exception: " + e);
       }
     }
     Msg.info(findNodeSuccedded + "/"  + (findNodeSuccedded + findNodeFailed) + " FIND_NODE have succedded.");
@@ -256,6 +257,7 @@ public class Node extends Process {
         waitFor(1);
       }
       catch (Exception ex) {
+        Msg.debug("Caught exception: " + ex);
       }
     } while (Msg.getClock() < timeout && !destinationFound);
   }
index 782f68f6335bbf519abfda95495fbb24615ccb95..37f866fbec4490303f7e0ebfb858deb2ed812402 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2007, 2012-2014, 2016. The SimGrid Team.
+/* Copyright (c) 2006-2007, 2012-2014, 2016-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -10,6 +10,8 @@ import org.simgrid.msg.MsgException;
 import org.simgrid.trace.Trace;
 
 public class Main  {
+  public static final String PM_STATE = "PM_STATE";
+
   private Main() {
     throw new IllegalAccessError("Utility class");
   }
@@ -29,11 +31,11 @@ public class Main  {
     new Receiver ("Tremblay", "Receiver", null).start();
 
     /* Initialize some state for the hosts */
-    Trace.hostStateDeclare ("PM_STATE"); 
-    Trace.hostStateDeclareValue ("PM_STATE", "waitingPing", "0 0 1");
-    Trace.hostStateDeclareValue ("PM_STATE", "sendingPong", "0 1 0");
-    Trace.hostStateDeclareValue ("PM_STATE", "sendingPing", "0 1 1");
-    Trace.hostStateDeclareValue ("PM_STATE", "waitingPong", "1 0 0");
+    Trace.hostStateDeclare (PM_STATE);
+    Trace.hostStateDeclareValue (PM_STATE, "waitingPing", "0 0 1");
+    Trace.hostStateDeclareValue (PM_STATE, "sendingPong", "0 1 0");
+    Trace.hostStateDeclareValue (PM_STATE, "sendingPing", "0 1 1");
+    Trace.hostStateDeclareValue (PM_STATE, "waitingPong", "1 0 0");
 
     /*  execute the simulation. */
     Msg.run();
index 4a1f26e55ef87f8b4d7af749019e827373373f23..58e82b9b8a9a5ebb69bb0db1115c74aa80cb4287 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2007, 2012-2014, 2016. The SimGrid Team.
+/* Copyright (c) 2006-2007, 2012-2014, 2016-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -15,6 +15,7 @@ import org.simgrid.trace.Trace;
 public class Receiver extends Process {
   private static final double COMM_SIZE_LAT = 1;
   private static final double COMM_SIZE_BW = 100000000;
+  private static final String PM_STATE = Main.PM_STATE;
 
   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException {
     super(hostname,name,args);
@@ -22,7 +23,7 @@ public class Receiver extends Process {
 
   public void main(String[] args) throws MsgException {
     Msg.info("hello!");
-    Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing");
+    Trace.hostPushState (getHost().getName(), PM_STATE, "waitingPing");
 
     /* Wait for the ping */ 
     Msg.info("try to get a task");
@@ -41,15 +42,15 @@ public class Receiver extends Process {
     Msg.info(" --- bw "+ COMM_SIZE_BW/communicationTime + " ----");
 
     /* Send the pong */
-    Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPong");
+    Trace.hostPushState (getHost().getName(), PM_STATE, "sendingPong");
     double computeDuration = 0;
     PingPongTask pong = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT);
     pong.setTime(time);
     pong.send(ping.getSource().getName());
 
     /* Pop the two states */
-    Trace.hostPopState (getHost().getName(), "PM_STATE");
-    Trace.hostPopState (getHost().getName(), "PM_STATE");
+    Trace.hostPopState (getHost().getName(), PM_STATE);
+    Trace.hostPopState (getHost().getName(), PM_STATE);
 
     Msg.info("goodbye!");
   }
index 6af47fac5aabf82aafe51e8c371baa59c4d9c6c5..c97be48029d4701596090843c3c3a92cec46bc2a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2014, 2016. The SimGrid Team.
+/* Copyright (c) 2006-2014, 2016-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -16,7 +16,7 @@ import org.simgrid.trace.Trace;
 public class Sender extends Process {
   private static final double COMM_SIZE_LAT = 1;
   private static final double COMM_SIZE_BW = 100000000;
-  private static final String PM_STATE = "PM_STATE";
+  private static final String PM_STATE = Main.PM_STATE;
 
   public Sender(String hostname, String name, String[] args) throws HostNotFoundException {
     super(hostname,name,args);