Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve Java interface
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 5 Apr 2015 17:35:55 +0000 (19:35 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 5 Apr 2015 17:36:03 +0000 (19:36 +0200)
- Rewrite some javadoc comments
- Reduce the visibility of fields that are not public

examples/java/bittorrent/Peer.java
examples/java/chord/Node.java
examples/java/cloud/Master.java
examples/java/cloud/Slave.java
examples/java/io/Client.java
examples/java/mutualExclusion/Node.java
examples/java/tracing/Receiver.java
examples/java/tracing/Sender.java
src/bindings/java/org/simgrid/msg/Process.java

index 6ce5a54..569e8b8 100644 (file)
@@ -201,7 +201,7 @@ public class Peer extends Process {
                                }
                        }                       
                }
-               this.hostname = host.getName();
+               this.hostname = getHost().getName();
        }
        /**
         * Retrieves the peer list from the tracker
index 27cb63a..9309923 100644 (file)
@@ -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));
        }
        /**
index 2cb86b5..a581aff 100644 (file)
@@ -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();
        
                }
index 7aaa48e..d97b0be 100644 (file)
@@ -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()+")");
                }
 
                
index 487878c..b8d718f 100644 (file)
@@ -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
index 0b622fe..55d91e3 100644 (file)
@@ -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();
index dab370f..0cd91d4 100644 (file)
@@ -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!");
     }
index 48a14c4..82930bd 100644 (file)
@@ -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!");
                                }
 }
index abfcef9..2e4eace 100644 (file)
@@ -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<String> 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();