From: Martin Quinson Date: Sun, 5 Apr 2015 17:35:55 +0000 (+0200) Subject: improve Java interface X-Git-Tag: v3_12~738^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dcfc5e64fe6bd50e160375dcdc5b480cba75217f improve Java interface - Rewrite some javadoc comments - Reduce the visibility of fields that are not public --- diff --git a/examples/java/bittorrent/Peer.java b/examples/java/bittorrent/Peer.java index 6ce5a5473d..569e8b88b8 100644 --- a/examples/java/bittorrent/Peer.java +++ b/examples/java/bittorrent/Peer.java @@ -201,7 +201,7 @@ public class Peer extends Process { } } } - this.hostname = host.getName(); + this.hostname = getHost().getName(); } /** * Retrieves the peer list from the tracker diff --git a/examples/java/chord/Node.java b/examples/java/chord/Node.java index 27cb63a522..93099237ae 100644 --- a/examples/java/chord/Node.java +++ b/examples/java/chord/Node.java @@ -151,7 +151,7 @@ public class Node extends Process { // is my successor the successor? if (isInInterval(fTask.requestId, this.id + 1, fingers[0])) { //Msg.info("Send the request to " + fTask.answerTo + " with answer " + fingers[0]); - FindSuccessorAnswerTask answer = new FindSuccessorAnswerTask(host.getName(), mailbox, fingers[0]); + FindSuccessorAnswerTask answer = new FindSuccessorAnswerTask(getHost().getName(), mailbox, fingers[0]); answer.dsend(fTask.answerTo); } else { @@ -164,7 +164,7 @@ public class Node extends Process { else if (task instanceof GetPredecessorTask) { GetPredecessorTask gTask = (GetPredecessorTask)(task); Msg.debug("Receiving a 'Get Predecessor' request from " + gTask.issuerHostName); - GetPredecessorAnswerTask answer = new GetPredecessorAnswerTask(host.getName(), mailbox, predId); + GetPredecessorAnswerTask answer = new GetPredecessorAnswerTask(getHost().getName(), mailbox, predId); answer.dsend(gTask.answerTo); } else if (task instanceof NotifyTask) { @@ -240,7 +240,7 @@ public class Node extends Process { boolean stop = false; Msg.debug("Sending a 'Get Predecessor' request to " + askTo); String mailboxTo = Integer.toString(askTo); - GetPredecessorTask sendTask = new GetPredecessorTask(host.getName(), this.mailbox); + GetPredecessorTask sendTask = new GetPredecessorTask(getHost().getName(), this.mailbox); try { sendTask.send(mailboxTo, Common.TIMEOUT); try { @@ -294,7 +294,7 @@ public class Node extends Process { int successor = -1; boolean stop = false; String mailbox = Integer.toString(askTo); - Task sendTask = new FindSuccessorTask(host.getName(), this.mailbox, id); + Task sendTask = new FindSuccessorTask(getHost().getName(), this.mailbox, id); Msg.debug("Sending a 'Find Successor' request to " + mailbox + " for id " + id); try { sendTask.send(mailbox, Common.TIMEOUT); @@ -374,7 +374,7 @@ public class Node extends Process { */ void remoteNotify(int notifyId, int predecessorCandidateId) { Msg.debug("Sending a 'Notify' request to " + notifyId); - Task sentTask = new NotifyTask(host.getName(), this.mailbox, predecessorCandidateId); + Task sentTask = new NotifyTask(getHost().getName(), this.mailbox, predecessorCandidateId); sentTask.dsend(Integer.toString(notifyId)); } /** diff --git a/examples/java/cloud/Master.java b/examples/java/cloud/Master.java index 2cb86b5613..a581aff8cc 100644 --- a/examples/java/cloud/Master.java +++ b/examples/java/cloud/Master.java @@ -34,7 +34,7 @@ public class Master extends Process { vm.start(); vms.add(vm); Slave slave = new Slave(vm,i); - Msg.info("Put Worker "+slave.msgName()+ " on "+vm.getName()); + Msg.info("Put Worker "+slave.getName()+ " on "+vm.getName()); slave.start(); } diff --git a/examples/java/cloud/Slave.java b/examples/java/cloud/Slave.java index 7aaa48e10f..d97b0be612 100644 --- a/examples/java/cloud/Slave.java +++ b/examples/java/cloud/Slave.java @@ -19,7 +19,7 @@ public class Slave extends Process { this.number = number; } public void main(String[] args) throws MsgException { - Msg.info(this.msgName() +" is listenning on MBOX:WRK0"+ number); + Msg.info(this.getName() +" is listenning on MBOX:WRK0"+ number); while(true) { Task task; try { @@ -38,7 +38,7 @@ public class Slave extends Process { } catch (MsgException e) { } - Msg.info(this.msgName() +" executed task (" + task.getName()+")"); + Msg.info(this.getName() +" executed task (" + task.getName()+")"); } diff --git a/examples/java/io/Client.java b/examples/java/io/Client.java index 487878c11d..b8d718f277 100644 --- a/examples/java/io/Client.java +++ b/examples/java/io/Client.java @@ -36,7 +36,7 @@ public class Client extends Process { public void main(String[] args) throws MsgException { // Retrieve all mount points of current host - Storage[] storages = host.getMountedStorage(); + Storage[] storages = getHost().getMountedStorage(); for (int i = 0; i < storages.length; i++) { // For each disk mounted on host diff --git a/examples/java/mutualExclusion/Node.java b/examples/java/mutualExclusion/Node.java index 0b622fe3e6..55d91e3ffe 100644 --- a/examples/java/mutualExclusion/Node.java +++ b/examples/java/mutualExclusion/Node.java @@ -17,11 +17,11 @@ public class Node extends Process { super(host,name,args); } public void request(double CStime) throws MsgException { - RequestTask req = new RequestTask(this.name); + RequestTask req = new RequestTask(getName()); Msg.info("Send a request to the coordinator"); req.send("coordinator"); Msg.info("Wait for a grant from the coordinator"); - Task.receive(this.name); // FIXME: ensure that this is a grant + Task.receive(getName()); // FIXME: ensure that this is a grant Task compute = new Task("CS", CStime, 0); compute.execute(); ReleaseTask release = new ReleaseTask(); diff --git a/examples/java/tracing/Receiver.java b/examples/java/tracing/Receiver.java index dab370f233..0cd91d4baa 100644 --- a/examples/java/tracing/Receiver.java +++ b/examples/java/tracing/Receiver.java @@ -24,7 +24,7 @@ public class Receiver extends Process { public void main(String[] args) throws MsgException { Msg.info("hello!"); - Trace.hostPushState (host.getName(), "PM_STATE", "waitingPing"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing"); double communicationTime=0; double time = Msg.getClock(); @@ -46,15 +46,15 @@ public class Receiver extends Process { Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); /* Send the pong */ - Trace.hostPushState (host.getName(), "PM_STATE", "sendingPong"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPong"); double computeDuration = 0; PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat); pong.setTime(time); pong.send(ping.getSource().getName()); /* Pop the two states */ - Trace.hostPopState (host.getName(), "PM_STATE"); - Trace.hostPopState (host.getName(), "PM_STATE"); + Trace.hostPopState (getHost().getName(), "PM_STATE"); + Trace.hostPopState (getHost().getName(), "PM_STATE"); Msg.info("goodbye!"); } diff --git a/examples/java/tracing/Sender.java b/examples/java/tracing/Sender.java index 48a14c4184..82930bdcb8 100644 --- a/examples/java/tracing/Sender.java +++ b/examples/java/tracing/Sender.java @@ -26,7 +26,7 @@ public class Sender extends Process { public void main(String[] args) throws MsgException { Msg.info("hello !"); - Trace.hostPushState (host.getName(), "PM_STATE", "sendingPing"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPing"); int hostCount = args.length; Msg.info("host count: " + hostCount); @@ -51,7 +51,7 @@ public class Sender extends Process { ping.setTime(time); ping.send(mailboxes[pos]); - Trace.hostPushState (host.getName(), "PM_STATE", "waitingPong"); + Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPong"); pong = (PingPongTask)Task.receive(getHost().getName()); double timeGot = Msg.getClock(); double timeSent = ping.getTime(); @@ -67,11 +67,11 @@ public class Sender extends Process { Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); /* Pop the last state (going back to sending ping) */ - Trace.hostPopState (host.getName(), "PM_STATE"); + Trace.hostPopState (getHost().getName(), "PM_STATE"); } /* Pop the sendingPong state */ - Trace.hostPopState (host.getName(), "PM_STATE"); + Trace.hostPopState (getHost().getName(), "PM_STATE"); Msg.info("goodbye!"); } } diff --git a/src/bindings/java/org/simgrid/msg/Process.java b/src/bindings/java/org/simgrid/msg/Process.java index abfcef99d6..2e4eace031 100644 --- a/src/bindings/java/org/simgrid/msg/Process.java +++ b/src/bindings/java/org/simgrid/msg/Process.java @@ -62,33 +62,22 @@ public abstract class Process implements Runnable { * It is compute automatically during the creation of the object. * The native functions use this identifier to synchronize the process. */ - public long id; + private long id; - /** - * Start time of the process - */ - public double startTime = 0; - /** + /** Time at which the process should be created */ + protected double startTime = 0; + /** Time at which th * Kill time of the process + * + * Set at creation, and used internally by SimGrid */ - public double killTime = -1; + private double killTime = -1; - /** - * The name of the process. - */ - protected String name; - /** - * The PID of the process - */ - protected int pid = -1; - /** - * The PPID of the process - */ - protected int ppid = -1; - /** - * The host of the process - */ - protected Host host = null; + private String name; + + private int pid = -1; + private int ppid = -1; + private Host host = null; /** The arguments of the method function of the process. */ public Vector args; @@ -207,49 +196,35 @@ public abstract class Process implements Runnable { */ public static native int killAll(int resetPID); - /** - * This method kill a process. + /** Simply kills the receiving process. * + * SimGrid sometimes have issues when you kill processes that are currently communicating and such. We are working on it to fix the issues. */ public native void kill(); - /** - * Suspends the process by suspending the task on which it was - * waiting for the completion. - */ + + /** Suspends the process. See {@link #resume()} to resume it afterward */ public native void suspend(); - /** - * Suspends the process by suspending the task on which it was - * waiting for the completion. - * DEPRECATED: use suspend instead. - */ - @Deprecated - public void pause() { - suspend(); - } - /** - * Sets the "auto-restart" flag of the process. - */ - public native void setAutoRestart(boolean autoRestart); - /** - * Restarts the process from the beginning - */ - public native void restart(); - /** - * Resumes a suspended process by resuming the task on which it was - * waiting for the completion. - */ + /** Resume a process that was suspended by {@link #suspend()}. */ public native void resume(); - /** - * Tests if a process is suspended. + /** Tests if a process is suspended. * - * @return The method returns true if the process is suspended. - * Otherwise the method returns false. + * @see {@link #suspend()} and {@link #resume()} */ public native boolean isSuspended(); + + /** + * Specify whether the process should restart when its host restarts after a failure + * + * A process naturally stops when its host stops. It starts again only if autoRestart is set to true. + * Otherwise, it just disappears when the host stops. + */ + public native void setAutoRestart(boolean autoRestart); + /** Restarts the process from the beginning */ + public native void restart(); /** * Returns the name of the process */ - public String msgName() { + public String getName() { return this.name; } /** @@ -335,16 +310,6 @@ public abstract class Process implements Runnable { * @param seconds The time the current process must sleep. */ public native void waitFor(double seconds) throws HostFailureException; - /** - * - */ - public void showArgs() { - Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" + - this.args.size()); - for (int i = 0; i < this.args.size(); i++) - Msg.info("[" + this.msgName() + "/" + this.getHost().getName() + - "] args[" + i + "]=" + this.args.get(i)); - } /** * This method actually creates and run the process. * It is a noop if the process is already launched. @@ -394,7 +359,7 @@ public abstract class Process implements Runnable { /** * Class initializer, to initialize various JNI stuff */ - public static native void nativeInit(); + private static native void nativeInit(); static { Msg.nativeInit(); nativeInit();