From 032c962d1354ec38e3f71083d51e690bcfa348d1 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 6 Oct 2017 23:30:50 +0200 Subject: [PATCH] Reduce number of Sonar smells in Java examples. --- examples/java/dht/kademlia/Node.java | 4 +++- examples/java/trace/pingpong/Main.java | 14 ++++++++------ examples/java/trace/pingpong/Receiver.java | 11 ++++++----- examples/java/trace/pingpong/Sender.java | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/java/dht/kademlia/Node.java b/examples/java/dht/kademlia/Node.java index 841e9d1be8..a690a0177d 100644 --- a/examples/java/dht/kademlia/Node.java +++ b/examples/java/dht/kademlia/Node.java @@ -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); } diff --git a/examples/java/trace/pingpong/Main.java b/examples/java/trace/pingpong/Main.java index 782f68f633..37f866fbec 100644 --- a/examples/java/trace/pingpong/Main.java +++ b/examples/java/trace/pingpong/Main.java @@ -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(); diff --git a/examples/java/trace/pingpong/Receiver.java b/examples/java/trace/pingpong/Receiver.java index 4a1f26e55e..58e82b9b8a 100644 --- a/examples/java/trace/pingpong/Receiver.java +++ b/examples/java/trace/pingpong/Receiver.java @@ -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!"); } diff --git a/examples/java/trace/pingpong/Sender.java b/examples/java/trace/pingpong/Sender.java index 6af47fac5a..c97be48029 100644 --- a/examples/java/trace/pingpong/Sender.java +++ b/examples/java/trace/pingpong/Sender.java @@ -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); -- 2.20.1