Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
keep playing
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 30 May 2016 21:02:56 +0000 (23:02 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 30 May 2016 21:02:56 +0000 (23:02 +0200)
examples/java/app/bittorrent/Common.java
examples/java/app/bittorrent/Connection.java
examples/java/app/bittorrent/MessageTask.java
examples/java/app/bittorrent/Tracker.java
examples/java/app/bittorrent/TrackerTask.java
examples/java/dht/chord/Common.java
examples/java/process/migration/Main.java
examples/msg/platform-failures/platform-failures.c

index 9a1cb29..0eb1eaa 100644 (file)
@@ -25,4 +25,7 @@ class Common {
   public static final int MAX_UNCHOKED_PEERS = 4;  /* Number of peers that can be unchocked at a given time */
   public static final int UPDATE_CHOKED_INTERVAL = 30;  /* Interval between each update of the choked peers */
   public static final int MAX_PIECES = 1;  /* Number of pieces the peer asks for simultaneously */
+  private Common() {
+    throw new IllegalAccessError("Utility class");
+  }
 }
index 2ead3a2..3143889 100644 (file)
@@ -8,21 +8,21 @@ package app.bittorrent;
 import java.util.Arrays;
 
 public class Connection {
-  public int id;
-  public char bitfield[];
-  public String mailbox;
+  protected int id;
+  protected char bitfield[];
+  protected String mailbox;
   // Indicates if we are interested in something this peer has
-  public boolean amInterested = false;
+  protected boolean amInterested = false;
   // Indicates if the peer is interested in one of our pieces
-  public boolean interested = false;
+  protected boolean interested = false;
   // Indicates if the peer is choked for the current peer
-  public boolean chokedUpload = true;
+  protected boolean chokedUpload = true;
   // Indicates if the peer has choked the current peer
-  public boolean chokedDownload = true;
+  protected boolean chokedDownload = true;
   // Number of messages we have received from the peer
-  public int messagesCount = 0;
-  public double peerSpeed = 0;
-  public double lastUnchoke = 0;
+  protected int messagesCount = 0;
+  protected double peerSpeed = 0;
+  protected double lastUnchoke = 0;
 
   public Connection(int id) {
     this.id = id;
index 5a25daf..4ff0204 100644 (file)
@@ -18,17 +18,17 @@ public class MessageTask extends Task {
     BITFIELD,
     REQUEST,
     PIECE
-  };
+  }
 
-  public Type type;
-  public String issuerHostname;
-  public String mailbox;
-  public int peerId;
-  public char bitfield[];
-  public int index;
-  public int blockIndex;
-  public int blockLength;
-  public boolean stalled;
+  protected Type type;
+  protected String issuerHostname;
+  protected String mailbox;
+  protected int peerId;
+  protected char bitfield[];
+  protected int index;
+  protected int blockIndex;
+  protected int blockLength;
+  protected boolean stalled;
 
   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
     this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
index 7873500..f613bb9 100644 (file)
@@ -36,9 +36,9 @@ public class Tracker extends Process {
     //Retrieve the end time
     deadline = Double.valueOf(args[0]);
     //Building peers array
-    peersList = new ArrayList<Integer>();
+    peersList = new ArrayList<>();
 
-    Msg.info("Tracker launched.");    
+    Msg.info("Tracker launched.");
     while (Msg.getClock() < deadline) {
       if (commReceived == null) {
         commReceived = Task.irecv(Common.TRACKER_MAILBOX);
index d3694fa..d27a7d7 100644 (file)
@@ -14,17 +14,17 @@ public class TrackerTask extends Task {
   public enum Type {
     REQUEST,
     ANSWER
-  };
+  }
 
-  public Type type;
-  public String hostname;
-  public String mailbox;
-  public int peerId;
-  public int uploaded;
-  public int downloaded;
-  public int left;
-  public double interval;
-  public ArrayList<Integer> peers;
+  protected Type type;
+  protected String hostname;
+  protected String mailbox;
+  protected int peerId;
+  protected int uploaded;
+  protected int downloaded;
+  protected int left;
+  protected double interval;
+  protected ArrayList<Integer> peers;
 
   public TrackerTask(String hostname, String mailbox, int peerId) {
     this(hostname, mailbox, peerId, 0, 0, Common.FILE_SIZE);
@@ -39,6 +39,6 @@ public class TrackerTask extends Task {
     this.uploaded = uploaded;
     this.downloaded = downloaded;
     this.left = left;
-    this.peers = new ArrayList<Integer>();
+    this.peers = new ArrayList<>();
   }
 }
index 25672cd..66c9109 100644 (file)
@@ -18,4 +18,7 @@ public class Common {
   public final static int PERIODIC_FIX_FINGERS_DELAY = 120;
   public final static int PERIODIC_CHECK_PREDECESSOR_DELAY = 120;
   public final static int PERIODIC_LOOKUP_DELAY = 10;
+  private Common() {
+    throw new IllegalAccessError("Utility class");
+  }
 }
index f128e70..66eb2b1 100644 (file)
@@ -11,9 +11,9 @@ import org.simgrid.msg.Process;
 import org.simgrid.msg.NativeException;
 import org.simgrid.msg.HostNotFoundException;
 
-public class Main {
-  public static Mutex mutex;
-  public static Process processToMigrate = null;
+class Main {
+  protected static Mutex mutex;
+  protected static Process processToMigrate = null;
 
   public static void main(String[] args) throws NativeException {
     Msg.init(args);
@@ -34,7 +34,8 @@ public class Main {
         Emigrant emigrant   = new Emigrant("Jacquelin","emigrant");
         emigrant.start();
     } catch (HostNotFoundException e){
-      System.out.println("Create processes failed!");
+      Msg.error("Create processes failed!");
+      e.printStackTrace();
     }
 
     /*  execute the simulation. */
index 4065d0f..c337025 100644 (file)
@@ -23,7 +23,7 @@ static int master(int argc, char *argv[])
 
   for (i = 0; i < number_of_tasks; i++) {
     char mailbox[256];
-    sprintf(mailbox, "worker-%ld", i % workers_count);
+    snprintf(mailbox, 255, "worker-%ld", i % workers_count);
 
     msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, xbt_new0(double, 1));
     *((double *) task->data) = MSG_get_clock();
@@ -54,22 +54,20 @@ static int master(int argc, char *argv[])
   XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
   for (i = 0; i < workers_count; i++) {
     char mailbox[256];
-    sprintf(mailbox, "worker-%ld", i % workers_count);
+    snprintf(mailbox, 255, "worker-%ld", i % workers_count);
     msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
     int a = MSG_task_send_with_timeout(task,mailbox,1.0);
-    if (a == MSG_OK)
-      continue;
+    if (a != MSG_OK){
+      MSG_task_destroy(task);
+    }
     if (a == MSG_HOST_FAILURE) {
       XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
-      MSG_task_destroy(task);
       return 0;
     } else if (a == MSG_TRANSFER_FAILURE) {
       XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", mailbox);
-      MSG_task_destroy(task);
     } else if (a == MSG_TIMEOUT) {
       XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox);
-      MSG_task_destroy(task);
-    } else {
+    } else if (a != MSG_OK){
       XBT_INFO("Hey ?! What's up ? ");
       xbt_die("Unexpected behavior with '%s': %d", mailbox, a);
     }
@@ -86,15 +84,12 @@ static int worker(int argc, char *argv[])
 
   long id= xbt_str_parse_int(argv[1], "Invalid argument %s");
 
-  sprintf(mailbox, "worker-%ld", id);
+  snprintf(mailbox, 79,"worker-%ld", id);
 
   while (1) {
-    int a;
-    double time1, time2;
-
-    time1 = MSG_get_clock();
-    a = MSG_task_receive( &(task), mailbox);
-    time2 = MSG_get_clock();
+    double time1 = MSG_get_clock();
+    int a = MSG_task_receive( &(task), mailbox);
+    double time2 = MSG_get_clock();
     if (a == MSG_OK) {
       XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
       if (MSG_task_get_data(task) == FINALIZE) {