Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
java: kill obscure NativeException
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index d9b3b6e..4f29954 100644 (file)
@@ -46,7 +46,7 @@ public abstract class Process implements Runnable {
         * a native process. Even if this attribute is public you must never
         * access to it. It is set automatically during the build of the object.
         */
-       private long bind;
+       private long bind = 0;
        /** Indicates if the process is started */
        boolean started;
        /**
@@ -70,25 +70,21 @@ public abstract class Process implements Runnable {
         */
        private double killTime = -1;
 
-       private String name;
+       private String name = null;
        
        private int pid = -1;
        private int ppid = -1;
        private Host host = null;
 
-       /** The arguments of the method function of the process. */     
-       public ArrayList<String> args;
+       /** The arguments of the method function of the process. */
+       private ArrayList<String> args = new ArrayList<>();
 
 
        /**  Default constructor */
        protected Process() {
                this.id = nextProcessId++;
-               this.name = null;
-               this.bind = 0;
-               this.args = new ArrayList<>();
        }
 
-
        /**
         * Constructs a new process from the name of a host and his name. The method
         * function of the process doesn't have argument.
@@ -112,11 +108,9 @@ public abstract class Process implements Runnable {
         * @param args                  The arguments of the main function of the process.
         *
         * @exception                   HostNotFoundException  if no host with this name exists.
-        *                      NativeException
-        * @throws NativeException
         *
         */ 
-       public Process(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
+       public Process(String hostname, String name, String[] args) throws HostNotFoundException {
                this(Host.getByName(hostname), name, args);
        }
        /**
@@ -163,18 +157,7 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(Host host, String name, String[]args, double startTime, double killTime) {
-               this();
-               this.host = host;
-               if (host == null)
-                       throw new NullPointerException("Process name cannot be NULL");
-               if (name == null)
-                       throw new NullPointerException("Process name cannot be NULL");
-               this.name = name;
-
-               this.args = new ArrayList<>();
-               if (null != args)
-                       this.args.addAll(Arrays.asList(args));
-
+               this(host, name, args);
                this.startTime = startTime;
                this.killTime = killTime;
        }
@@ -200,6 +183,9 @@ public abstract class Process implements Runnable {
         * 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();
+       public static void kill(Process p) {
+               p.kill();
+       }
        
        /** Suspends the process. See {@link #resume()} to resume it afterward */
        public native void suspend();
@@ -212,6 +198,9 @@ public abstract class Process implements Runnable {
         */
        public native boolean isSuspended();
        
+       /** Yield the current process. All other processes that are ready at the same timestamp will be executed first */
+       public static native void yield();
+       
        /**
         * Specify whether the process should restart when its host restarts after a failure
         * 
@@ -240,10 +229,8 @@ public abstract class Process implements Runnable {
         * @param PID                   The process identifier of the process to get.
         *
         * @return                              The process with the specified PID.
-        *
-        * @exception                   NativeException on error in the native SimGrid code
         */ 
-       public static native Process fromPID(int PID) throws NativeException;
+       public static native Process fromPID(int PID);
        /**
         * This method returns the PID of the process.
         *
@@ -288,7 +275,7 @@ public abstract class Process implements Runnable {
         */
        public native void migrate(Host host);  
        /**
-        * Makes the current process sleep until millis millisecondes have elapsed.
+        * Makes the current process sleep until millis milliseconds have elapsed.
         * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds.
         * FIXME: Not optimal, maybe we should have two native functions.
         * @param millis the length of time to sleep in milliseconds.
@@ -303,7 +290,7 @@ public abstract class Process implements Runnable {
         * milliseconds and nanoseconds.
         * Overloads Thread.sleep.
         * @param millis the length of time to sleep in milliseconds.
-        * @param nanos additionnal nanoseconds to sleep.
+        * @param nanos additional nanoseconds to sleep.
         */
        public static native void sleep(long millis, int nanos) throws HostFailureException;
        /**
@@ -336,14 +323,15 @@ public abstract class Process implements Runnable {
                        }
 
                        this.main(args);
-               } catch(MsgException e) {
+               }
+               catch(MsgException e) {
                        e.printStackTrace();
                        Msg.info("Unexpected behavior. Stopping now");
                        System.exit(1);
                }
                catch(ProcessKilledError pk) {
+                       /* The process was killed before its end. With a kill() or something. */
                }       
-               exit();
        }
 
        /**
@@ -354,7 +342,10 @@ public abstract class Process implements Runnable {
         */
        public abstract void main(String[]args) throws MsgException;
 
-       public native void exit();
+       /** Stops the execution of the current actor */
+       public void exit() {
+               this.kill();
+       }
        /**
         * Class initializer, to initialize various JNI stuff
         */
@@ -368,6 +359,6 @@ public abstract class Process implements Runnable {
         *
         * @return                      The count of the running processes
         */ 
-       public native static int getCount();
+       public static native int getCount();
 
 }