Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a straightforward implementation of start_time and kill_time. This change the...
[simgrid.git] / org / simgrid / msg / ApplicationHandler.java
index 4f0951b..b485d77 100644 (file)
  */
 
 package org.simgrid.msg;
-
 import java.util.Hashtable;
 import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 
 public final class ApplicationHandler {
 
@@ -37,7 +38,14 @@ public final class ApplicationHandler {
                 * The function of the process.
                 */
                private  static String function;
-               
+               /**
+                * Start time of the process
+                */
+               private static double startTime;
+               /**
+                * Kill time of the process
+                */
+               private static double killTime;
                /**
                 * This method is called by the start element handler.
                 * It sets the host and the function of the process to create,
@@ -50,9 +58,11 @@ public final class ApplicationHandler {
                 * @function                    The function of the process to create.
                 *
                 */
-               public  static void setProcessIdentity(String hostName_, String function_) {
-                       hostName = hostName_;    
-                       function = function_;
+               public  static void setProcessIdentity(String hostName, String function, String startTime, String killTime) {
+                       ApplicationHandler.hostName = hostName;    
+                       ApplicationHandler.function = function;
+                       ApplicationHandler.startTime = Double.valueOf(startTime);
+                       ApplicationHandler.killTime = Double.valueOf(killTime);
 
                        if (!args.isEmpty())
                                args.clear();
@@ -92,29 +102,25 @@ public final class ApplicationHandler {
                 }
 
          /**
-          *
+          * Method called to create the process
           */
          @SuppressWarnings("unchecked")
                 public  static void createProcess() {
                         try {
                                 Class<Process> cls = (Class<Process>) Class.forName(function);
-
-                                Process process = cls.newInstance();
-                                process.name = function;
-                                process.id = org.simgrid.msg.Process.nextProcessId++;
-                                Host host = Host.getByName(hostName);
-
-                                MsgNative.processCreate(process, host);
-                                Vector<String> args_ = args;
-                                int size = args_.size();
-
-                                for (int index = 0; index < size; index++)
-                                        process.args.add(args_.get(index));
-
-                                process.properties = properties;
-                                properties = new Hashtable<String,String>();
-
-                        } catch(HostNotFoundException e) {
+                                Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class, double.class, double.class});
+                                String[] args_ = args.toArray(new String[args.size()]);
+                                Process process = constructor.newInstance(Host.getByName(hostName), function, args_, startTime, killTime);
+                                process.start();
+                        } 
+                        catch (NoSuchMethodException e) {
+                                throw new RuntimeException("Can't find the correct constructor for the class " + function + ". \n" +
+                                "Is there a constructor with the signature: \"Host host, String name, String[]args, double startTime, double killTime\" in the class ?");
+                        }
+                        catch (InvocationTargetException e) {
+                                e.printStackTrace();
+                        }
+                        catch(HostNotFoundException e) {
                                 System.out.println(e.toString());
                                 e.printStackTrace();
 
@@ -142,6 +148,8 @@ public final class ApplicationHandler {
                        properties = new Hashtable<String,String>();
                        hostName = null;
                        function = null;
+                       startTime = 0;
+                       killTime = -1;
        }
 
          /**
@@ -149,8 +157,8 @@ public final class ApplicationHandler {
           * @param hostName
           * @param function
           */
-         public  static void onBeginProcess(String hostName, String function) {
-               setProcessIdentity(hostName, function);
+         public  static void onBeginProcess(String hostName, String function, String startTime, String killTime) {
+               setProcessIdentity(hostName, function, startTime, killTime);
                
        }
     /**
@@ -159,7 +167,7 @@ public final class ApplicationHandler {
      * @param value
      */
     public  static void onProperty(String id, String value) {
-               setProperty(id, value);
+       setProperty(id, value);
        }
 
     /**
@@ -167,7 +175,7 @@ public final class ApplicationHandler {
      * @param arg
      */
     public  static void onProcessArg(String arg) {
-               registerProcessArg(arg);
+       registerProcessArg(arg);
        }
 
     /**