Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
deperlify the Java process creation: no need to pass the hostname where we can use...
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 04b5e03..15cd7e5 100644 (file)
@@ -48,7 +48,6 @@ public abstract class Process implements Runnable {
         */
        private long bind = 0;
        /** Indicates if the process is started */
-       boolean started;
        /**
         * Even if this attribute is public you must never access to it.
         * It is used to compute the id of an MSG process.
@@ -79,17 +78,11 @@ public abstract class Process implements Runnable {
        /** The arguments of the method function of the process. */
        private ArrayList<String> args = new ArrayList<>();
 
-
-       /**  Default constructor */
-       protected Process() {
-               this.id = nextProcessId++;
-       }
-
        /**
         * Constructs a new process from the name of a host and his name. The method
         * function of the process doesn't have argument.
         *
-        * @param hostname              The name of the host of the process to create.
+        * @param hostname              Where to create the process.
         * @param name                  The name of the process.
         *
         * @exception                   HostNotFoundException  if no host with this name exists.
@@ -103,7 +96,7 @@ public abstract class Process implements Runnable {
         * Constructs a new process from the name of a host and his name. The arguments
         * of the method function of the process are specified by the parameter args.
         *
-        * @param hostname              The name of the host of the process to create.
+        * @param hostname              Where to create the process.
         * @param name                  The name of the process.
         * @param args                  The arguments of the main function of the process.
         *
@@ -117,7 +110,7 @@ public abstract class Process implements Runnable {
         * Constructs a new process from a host and his name. The method function of the 
         * process doesn't have argument.
         *
-        * @param host                  The host of the process to create.
+        * @param host                  Where to create the process.
         * @param name                  The name of the process.
         *
         */
@@ -128,17 +121,19 @@ public abstract class Process implements Runnable {
         * Constructs a new process from a host and his name, the arguments of here method function are
         * specified by the parameter args.
         *
-        * @param host                  The host of the process to create.
+        * @param host                  Where to create the process.
         * @param name                  The name of the process.
         * @param args                  The arguments of main method of the process.
         */     
-       public Process(Host host, String name, String[]args) {
-               this();
-               this.host = host;
+       public Process(Host host, String name, String[]args) 
+       {
                if (host == null)
-                       throw new NullPointerException("Host cannot be NULL");
+                       throw new NullPointerException("Cannot create a process on the null host");
                if (name == null)
-                       throw new NullPointerException("Process name cannot be NULL");
+                       throw new NullPointerException("Process name cannot be null");
+               
+               this.id = nextProcessId++;
+               this.host = host;
                this.name = name;
 
                this.args = new ArrayList<>();
@@ -149,7 +144,7 @@ public abstract class Process implements Runnable {
         * Constructs a new process from a host and his name, the arguments of here method function are
         * specified by the parameter args.
         *
-        * @param host                  The host of the process to create.
+        * @param host                  Where to create the process.
         * @param name                  The name of the process.
         * @param args                  The arguments of main method of the process.
         * @param startTime             Start time of the process
@@ -162,10 +157,11 @@ public abstract class Process implements Runnable {
                this.killTime = killTime;
        }
        /**
-        * The natively implemented method to create an MSG process.
-        * @param hostName    A valid (bound) host where create the process.
+        * The native method to create an MSG process.
+        * @param host    where to create the process.
         */
-       protected native void create(String hostName) throws HostNotFoundException;
+       protected native void create(Host host);
+       
        /**
         * This method kills all running process of the simulation.
         *
@@ -304,13 +300,11 @@ public abstract class Process implements Runnable {
         * @throws HostNotFoundException
         */
        public final void start() throws HostNotFoundException {
-               if (!started) {
-                       started = true;
-                       create(host.getName());
-               }
+               if (bind == 0)
+                        create(host);
        }
 
-       /** This method runs the process. Il calls the method function that you must overwrite. */
+       /** This method runs the process. It calls the method function that you must overwrite. */
        @Override
        public void run() {