Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Smelly code, smelly code, how are they writing you
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 27 May 2016 10:14:10 +0000 (12:14 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 27 May 2016 10:14:10 +0000 (12:14 +0200)
Smelly code, smelly code it's not your fault...

13 files changed:
examples/java/app/bittorrent/Common.java
examples/java/app/centralizedmutex/Coordinator.java
examples/java/app/centralizedmutex/Main.java
examples/java/app/centralizedmutex/Node.java
examples/java/app/masterworker/Main.java
examples/java/app/masterworker/Master.java
examples/java/app/masterworker/Worker.java
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
src/bindings/java/org/simgrid/msg/Process.java

index 3f2f3ad..9a1cb29 100644 (file)
@@ -7,7 +7,7 @@
 package app.bittorrent;
 
 /* Common constants for use in the simulation */
 package app.bittorrent;
 
 /* Common constants for use in the simulation */
-public class Common {
+class Common {
   public static final String TRACKER_MAILBOX = "tracker_mailbox";
   public static final int FILE_SIZE = 5120;
   public static final int FILE_PIECE_SIZE = 512;
   public static final String TRACKER_MAILBOX = "tracker_mailbox";
   public static final int FILE_SIZE = 5120;
   public static final int FILE_PIECE_SIZE = 512;
index f89fef9..1931293 100644 (file)
@@ -14,16 +14,17 @@ import org.simgrid.msg.Process;
 import org.simgrid.msg.MsgException;
 
 public class Coordinator extends Process {
 import org.simgrid.msg.MsgException;
 
 public class Coordinator extends Process {
+  LinkedList<RequestTask> waitingQueue=new LinkedList<>();
+  int csToServe;
+
   public Coordinator(Host host, String name, String[]args) {
     super(host,name,args);
   }
   public Coordinator(Host host, String name, String[]args) {
     super(host,name,args);
   }
-  LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
-  int CsToServe;
 
   public void main(String[] args) throws MsgException {
 
   public void main(String[] args) throws MsgException {
-    CsToServe = Integer.parseInt(args[0]);
+    csToServe = Integer.parseInt(args[0]);
     Task task;
     Task task;
-    while (CsToServe >0) {
+    while (csToServe >0) {
       task = Task.receive("coordinator");
       if (task instanceof RequestTask) {
         RequestTask t = (RequestTask) task;
       task = Task.receive("coordinator");
       if (task instanceof RequestTask) {
         RequestTask t = (RequestTask) task;
@@ -40,8 +41,8 @@ public class Coordinator extends Process {
           GrantTask tosend = new GrantTask();
           tosend.send(req.from);
         }
           GrantTask tosend = new GrantTask();
           tosend.send(req.from);
         }
-        CsToServe--;
-        if (waitingQueue.isEmpty() && CsToServe==0) {
+        csToServe--;
+        if (waitingQueue.isEmpty() && csToServe==0) {
           Msg.info("we should shutdown the simulation now");
         }
       }
           Msg.info("we should shutdown the simulation now");
         }
       }
index 7a8a7ac..6d8c6d1 100644 (file)
@@ -9,7 +9,7 @@ package app.centralizedmutex;
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.NativeException;
 
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.NativeException;
 
-public class Main {
+class Main {
   public static void main(String[] args) throws NativeException {
     Msg.init(args);
 
   public static void main(String[] args) throws NativeException {
     Msg.init(args);
 
index b8fd1d1..511a95d 100644 (file)
@@ -18,10 +18,11 @@ public class Node extends Process {
   }
   public void request(double CStime) throws MsgException {
     RequestTask req = new RequestTask(getName());
   }
   public void request(double CStime) throws MsgException {
     RequestTask req = new RequestTask(getName());
+    GrantTask grant= new GrantTask();;
     Msg.info("Send a request to the coordinator");
     req.send("coordinator");
     Msg.info("Wait for a grant from the coordinator");
     Msg.info("Send a request to the coordinator");
     req.send("coordinator");
     Msg.info("Wait for a grant from the coordinator");
-    Task.receive(getName()); // FIXME: ensure that this is a grant
+    grant.receive(getName());
     Task compute = new Task("CS", CStime, 0);
     compute.execute();
     ReleaseTask release = new ReleaseTask();
     Task compute = new Task("CS", CStime, 0);
     compute.execute();
     ReleaseTask release = new ReleaseTask();
index acca06a..cc24eed 100644 (file)
@@ -11,7 +11,7 @@ import java.io.File;
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.NativeException;
 
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.NativeException;
 
-public class Main {
+class Main {
   public static final int TASK_COMP_SIZE = 10000000;
   public static final int TASK_COMM_SIZE = 10000000;
   /* This only contains the launcher. If you do nothing more than than you can run java simgrid.msg.Msg
   public static final int TASK_COMP_SIZE = 10000000;
   public static final int TASK_COMM_SIZE = 10000000;
   /* This only contains the launcher. If you do nothing more than than you can run java simgrid.msg.Msg
index 6c2b872..08abb74 100644 (file)
@@ -23,17 +23,17 @@ public class Master extends Process {
       System.exit(1);
     }
 
       System.exit(1);
     }
 
-    int tasksCount = Integer.valueOf(args[0]).intValue();
-    double taskComputeSize = Double.valueOf(args[1]).doubleValue();
-    double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
+    int tasksCount = Integer.parseInt(args[0]);
+    double taskComputeSize = Double.parseDouble(args[1]);
+    double taskCommunicateSize = Double.parseDouble(args[2]);
 
 
-    int workersCount = Integer.valueOf(args[3]).intValue();
+    int workersCount = Integer.parseInt(args[3]);
 
     Msg.info("Hello! Got "+  workersCount + " workers and "+tasksCount+" tasks to process");
 
     for (int i = 0; i < tasksCount; i++) {
       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
 
     Msg.info("Hello! Got "+  workersCount + " workers and "+tasksCount+" tasks to process");
 
     for (int i = 0; i < tasksCount; i++) {
       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
-      //Msg.info("Sending \"" + task.getName()+ "\" to \"worker_" + i % workersCount + "\"");
+      Msg.debug("Sending \"" + task.getName()+ "\" to \"worker_" + i % workersCount + "\"");
       task.send("worker_"+(i%workersCount));
     }
 
       task.send("worker_"+(i%workersCount));
     }
 
index ff68aac..4236ebd 100644 (file)
@@ -25,8 +25,8 @@ public class Worker extends Process {
       System.exit(1);
     }
 
       System.exit(1);
     }
 
-    int num = Integer.valueOf(args[0]).intValue();
-    //Msg.info("Receiving on 'worker_"+num+"'");
+    int num = Integer.parseInt(args[0]);
+    Msg.debug("Receiving on 'worker_"+num+"'");
 
     while(true) {  
       Task task = Task.receive("worker_"+num);
 
     while(true) {  
       Task task = Task.receive("worker_"+num);
@@ -37,7 +37,9 @@ public class Worker extends Process {
       Msg.info("Received \"" + task.getName() +  "\". Processing it.");
       try {
         task.execute();
       Msg.info("Received \"" + task.getName() +  "\". Processing it.");
       try {
         task.execute();
-      } catch (TaskCancelledException e) {}
+      } catch (TaskCancelledException e) {
+        e.printStackTrace();
+      }
     }
 
     Msg.info("Received Finalize. I'm done. See you!");
     }
 
     Msg.info("Received Finalize. I'm done. See you!");
index cce0555..3352474 100644 (file)
@@ -6,11 +6,11 @@
 
 package app.pingpong;
 import org.simgrid.msg.Msg;
 
 package app.pingpong;
 import org.simgrid.msg.Msg;
-import org.simgrid.msg.MsgException;
+import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.NativeException;
  
 import org.simgrid.msg.NativeException;
  
-public class Main {
-  public static void main(String[] args) throws MsgException, NativeException{
+class Main {
+  public static void main(String[] args) throws HostNotFoundException,NativeException{
     Msg.init(args);
     if(args.length < 1) {
       Msg.info("Usage   : Main platform_file");
     Msg.init(args);
     if(args.length < 1) {
       Msg.info("Usage   : Main platform_file");
index 7bb0d29..e4469b3 100644 (file)
@@ -6,7 +6,6 @@
 
 package app.pingpong;
 import org.simgrid.msg.Msg;
 
 package app.pingpong;
 import org.simgrid.msg.Msg;
-import org.simgrid.msg.Host;
 import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 import org.simgrid.msg.MsgException;
 import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 import org.simgrid.msg.MsgException;
@@ -14,15 +13,14 @@ 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 {
-  final double commSizeLat = 1;
-  final double commSizeBw = 100000000;
+  static final double commSizeLat = 1;
+  static final double commSizeBw = 100000000;
   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
     super(hostname,name,args);
   }
 
   public void main(String[] args) throws MsgException {
     Msg.info("hello!");
   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
     super(hostname,name,args);
   }
 
   public void main(String[] args) throws MsgException {
     Msg.info("hello!");
-    double communicationTime=0;
 
     double time = Msg.getClock();
 
 
     double time = Msg.getClock();
 
@@ -36,7 +34,7 @@ public class Receiver extends Process {
     Msg.info("Was sent at time "+timeSent);
     time=timeSent;
 
     Msg.info("Was sent at time "+timeSent);
     time=timeSent;
 
-    communicationTime=timeGot - time;
+    double communicationTime = timeGot - time;
     Msg.info("Communication time : " + communicationTime);
     Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
     Msg.info("goodbye!");
     Msg.info("Communication time : " + communicationTime);
     Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
     Msg.info("goodbye!");
index 9644b4d..03782b2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2014, 2016. The SimGrid Team.
+       /* Copyright (c) 2006-2014, 2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -35,8 +35,8 @@ public class Sender extends Process {
       try {
         mailboxes[pos] = Host.getByName(args[pos]).getName();
       } catch (HostNotFoundException e) {
       try {
         mailboxes[pos] = Host.getByName(args[pos]).getName();
       } catch (HostNotFoundException e) {
+        e.printStackTrace();
         Msg.info("Invalid deployment file: " + e.toString());
         Msg.info("Invalid deployment file: " + e.toString());
-        System.exit(1);
       }
     }
 
       }
     }
 
index 09d441a..17cc8d2 100644 (file)
@@ -11,7 +11,7 @@ import org.simgrid.msg.Host;
 import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
 import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
-public class Main {
+class Main {
   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 c241c78..9b678b9 100644 (file)
@@ -10,7 +10,7 @@ import org.simgrid.msg.Msg;
 import org.simgrid.msg.Host;
 import org.simgrid.msg.MsgException;
 
 import org.simgrid.msg.Host;
 import org.simgrid.msg.MsgException;
 
-public class Main {
+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 hostNB = 2 ; 
index 42d1276..291ab60 100644 (file)
@@ -354,7 +354,7 @@ public abstract class Process implements Runnable {
         */
        public abstract void main(String[]args) throws MsgException;
 
         */
        public abstract void main(String[]args) throws MsgException;
 
-       public native void exit();    
+       public native void exit();
        /**
         * Class initializer, to initialize various JNI stuff
         */
        /**
         * Class initializer, to initialize various JNI stuff
         */