Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove some smells in Java
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 16 Jun 2016 09:00:52 +0000 (11:00 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 16 Jun 2016 09:00:52 +0000 (11:00 +0200)
examples/java/app/pingpong/Main.java
examples/java/app/pingpong/Receiver.java
examples/java/app/pingpong/Sender.java
examples/java/async/dsend/Main.java
examples/java/cloud/masterworker/Main.java
examples/java/cloud/masterworker/Master.java
examples/java/cloud/masterworker/cloud_masterworker.tesh
examples/java/energy/vm/EnergyVMRunner.java
examples/java/energy/vm/Main.java

index 9a049c2..d69dcec 100644 (file)
@@ -10,6 +10,10 @@ import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.NativeException;
  
 class Main {
 import org.simgrid.msg.NativeException;
  
 class Main {
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
+
   public static void main(String[] args) throws HostNotFoundException, NativeException{
     Msg.init(args);
     if(args.length < 1) {
   public static void main(String[] args) throws HostNotFoundException, NativeException{
     Msg.init(args);
     if(args.length < 1) {
index 4e59a48..80d832e 100644 (file)
@@ -13,8 +13,7 @@ import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
 public class Receiver extends Process {
 import org.simgrid.msg.HostNotFoundException;
 
 public class Receiver extends Process {
-  static final double COMM_SIZE_LAT = 1;
-  static final double COMM_SIZE_BW = 100000000;
+  private static final double COMM_SIZE_BW = 100000000;
   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
     super(hostname,name,args);
   }
   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
     super(hostname,name,args);
   }
@@ -32,7 +31,7 @@ public class Receiver extends Process {
 
     Msg.info("Got at time "+ timeGot);
     Msg.info("Was sent at time "+timeSent);
 
     Msg.info("Got at time "+ timeGot);
     Msg.info("Was sent at time "+timeSent);
-    time=timeSent;
+    time = timeSent;
 
     double communicationTime = timeGot - time;
     Msg.info("Communication time : " + communicationTime);
 
     double communicationTime = timeGot - time;
     Msg.info("Communication time : " + communicationTime);
index 03782b2..ab23c66 100644 (file)
@@ -13,8 +13,7 @@ import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
 public class Sender extends Process {
 import org.simgrid.msg.HostNotFoundException;
 
 public class Sender extends Process {
-  private final double commSizeLat = 1;
-  final double commSizeBw = 100000000;
+  private static final double COMM_SIZE_LAT = 1;
 
   public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
     super(hostname,name,args);
 
   public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
     super(hostname,name,args);
@@ -45,7 +44,7 @@ public class Sender extends Process {
 
       Msg.info("sender time: " + time);
 
 
       Msg.info("sender time: " + time);
 
-      task = new PingPongTask("no name",computeDuration,commSizeLat);
+      task = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT);
       task.setTime(time);
 
       task.send(mailboxes[pos]);
       task.setTime(time);
 
       task.send(mailboxes[pos]);
index 17cc8d2..02955ab 100644 (file)
@@ -12,6 +12,10 @@ import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
 class Main {
 import org.simgrid.msg.HostNotFoundException;
 
 class Main {
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
+
   public static void main(String[] args) throws NativeException, HostNotFoundException {
     Msg.init(args);
 
   public static void main(String[] args) throws NativeException, HostNotFoundException {
     Msg.init(args);
 
index 9b678b9..fb36463 100644 (file)
@@ -11,9 +11,14 @@ import org.simgrid.msg.Host;
 import org.simgrid.msg.MsgException;
 
 class Main {
 import org.simgrid.msg.MsgException;
 
 class Main {
-  public static final double task_comp_size = 10;
-  public static final double task_comm_size = 10;
-  public static final int hostNB = 2 ; 
+  public static final double TASK_COMP_SIZE = 10;
+  public static final double TASK_COMM_SIZE = 10;
+  public static final int NHOSTS = 2 ; 
+
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
+
   public static void main(String[] args) throws MsgException {
     Msg.init(args); 
 
   public static void main(String[] args) throws MsgException {
     Msg.init(args); 
 
@@ -26,12 +31,12 @@ class Main {
     /* Construct the platform */
     Msg.createEnvironment(args[0]);
     Host[] hosts = Host.all();
     /* Construct the platform */
     Msg.createEnvironment(args[0]);
     Host[] hosts = Host.all();
-    if (hosts.length < hostNB+1) {
-      Msg.info("I need at least "+ (hostNB+1) +"  hosts in the platform file, but " + args[0] + " contains only "
+    if (hosts.length < NHOSTS+1) {
+      Msg.info("I need at least "+ (NHOSTS+1) +"  hosts in the platform file, but " + args[0] + " contains only "
                + hosts.length + " hosts");
       System.exit(42);
     }
                + hosts.length + " hosts");
       System.exit(42);
     }
-    Msg.info("Start"+ hostNB +"  hosts");
+    Msg.info("Start "+ NHOSTS +" hosts");
     new Master(hosts[0],"Master",hosts).start();
     /* Execute the simulation */
     Msg.run();
     new Master(hosts[0],"Master",hosts).start();
     /* Execute the simulation */
     Msg.run();
index 586c910..c2b95d9 100644 (file)
@@ -24,7 +24,7 @@ public class Master extends Process {
   }
 
   public void main(String[] args) throws MsgException {
   }
 
   public void main(String[] args) throws MsgException {
-    int workersCount = Main.hostNB;
+    int workersCount = Main.NHOSTS;
     ArrayList<VM> vms = new ArrayList<>();
 
     // Create one VM per host and bind a process inside each one. 
     ArrayList<VM> vms = new ArrayList<>();
 
     // Create one VM per host and bind a process inside each one. 
@@ -86,7 +86,7 @@ public class Master extends Process {
 
   public void workBatch(int workersCount) throws MsgException {
     for (int i = 0; i < workersCount; i++) {
 
   public void workBatch(int workersCount) throws MsgException {
     for (int i = 0; i < workersCount; i++) {
-      Task task = new Task("Task0" + i, Main.task_comp_size, Main.task_comm_size);
+      Task task = new Task("Task0" + i, Main.TASK_COMP_SIZE, Main.TASK_COMM_SIZE);
       Msg.info("Sending to WRK0" + i);
       task.send("MBOX:WRK0" + i);
     }
       Msg.info("Sending to WRK0" + i);
       task.send("MBOX:WRK0" + i);
     }
index 2b38e95..acecc00 100644 (file)
@@ -4,7 +4,7 @@
 
 $ java -classpath ${classpath:=.} cloud/masterworker/Main ${srcdir:=.}/../platforms/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (0:maestro@) Using regular java threads.
 
 $ java -classpath ${classpath:=.} cloud/masterworker/Main ${srcdir:=.}/../platforms/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (0:maestro@) Using regular java threads.
-> [  0.000000] (0:maestro@) Start hosts
+> [  0.000000] (0:maestro@) Start 2 hosts
 > [  0.000000] (1:Master@Jacquelin) create VM00
 > [  0.000000] (1:Master@Jacquelin) Put Worker WRK00 on VM00
 > [  0.000000] (1:Master@Jacquelin) create VM01
 > [  0.000000] (1:Master@Jacquelin) create VM00
 > [  0.000000] (1:Master@Jacquelin) Put Worker WRK00 on VM00
 > [  0.000000] (1:Master@Jacquelin) create VM01
index d8ecb21..09e0a73 100644 (file)
@@ -10,7 +10,6 @@ import org.simgrid.msg.VM;
 import org.simgrid.msg.Host;
 import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 import org.simgrid.msg.Host;
 import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
-import org.simgrid.msg.MsgException;
 import org.simgrid.msg.HostFailureException;
 import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.TaskCancelledException;
 import org.simgrid.msg.HostFailureException;
 import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.TaskCancelledException;
index e4efa3e..385fe40 100644 (file)
@@ -10,7 +10,10 @@ import org.simgrid.msg.Host;
 import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.NativeException;
 
 import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.NativeException;
 
-public class Main {
+class Main {
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
 
   public static void main(String[] args) throws NativeException, HostNotFoundException {
     Msg.energyInit();
 
   public static void main(String[] args) throws NativeException, HostNotFoundException {
     Msg.energyInit();