From: Frederic Suter Date: Mon, 30 May 2016 21:02:56 +0000 (+0200) Subject: keep playing X-Git-Tag: v3_14~1091 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ae0c1ae47a768ce38aa143887e90e59cba6e74ca keep playing --- diff --git a/examples/java/app/bittorrent/Common.java b/examples/java/app/bittorrent/Common.java index 9a1cb29732..0eb1eaa0e1 100644 --- a/examples/java/app/bittorrent/Common.java +++ b/examples/java/app/bittorrent/Common.java @@ -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"); + } } diff --git a/examples/java/app/bittorrent/Connection.java b/examples/java/app/bittorrent/Connection.java index 2ead3a2bc5..3143889710 100644 --- a/examples/java/app/bittorrent/Connection.java +++ b/examples/java/app/bittorrent/Connection.java @@ -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; diff --git a/examples/java/app/bittorrent/MessageTask.java b/examples/java/app/bittorrent/MessageTask.java index 5a25dafe80..4ff0204a80 100644 --- a/examples/java/app/bittorrent/MessageTask.java +++ b/examples/java/app/bittorrent/MessageTask.java @@ -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); diff --git a/examples/java/app/bittorrent/Tracker.java b/examples/java/app/bittorrent/Tracker.java index 7873500d4c..f613bb9ca9 100644 --- a/examples/java/app/bittorrent/Tracker.java +++ b/examples/java/app/bittorrent/Tracker.java @@ -36,9 +36,9 @@ public class Tracker extends Process { //Retrieve the end time deadline = Double.valueOf(args[0]); //Building peers array - peersList = new ArrayList(); + peersList = new ArrayList<>(); - Msg.info("Tracker launched."); + Msg.info("Tracker launched."); while (Msg.getClock() < deadline) { if (commReceived == null) { commReceived = Task.irecv(Common.TRACKER_MAILBOX); diff --git a/examples/java/app/bittorrent/TrackerTask.java b/examples/java/app/bittorrent/TrackerTask.java index d3694fa9f9..d27a7d7d29 100644 --- a/examples/java/app/bittorrent/TrackerTask.java +++ b/examples/java/app/bittorrent/TrackerTask.java @@ -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 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 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(); + this.peers = new ArrayList<>(); } } diff --git a/examples/java/dht/chord/Common.java b/examples/java/dht/chord/Common.java index 25672cd466..66c9109a49 100644 --- a/examples/java/dht/chord/Common.java +++ b/examples/java/dht/chord/Common.java @@ -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"); + } } diff --git a/examples/java/process/migration/Main.java b/examples/java/process/migration/Main.java index f128e70f5c..66eb2b1687 100644 --- a/examples/java/process/migration/Main.java +++ b/examples/java/process/migration/Main.java @@ -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. */ diff --git a/examples/msg/platform-failures/platform-failures.c b/examples/msg/platform-failures/platform-failures.c index 4065d0f4ce..c337025c35 100644 --- a/examples/msg/platform-failures/platform-failures.c +++ b/examples/msg/platform-failures/platform-failures.c @@ -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) {