/*
* These are the upcalls used by the FleXML parser for application files
*
- * Copyright 2006,2007,2010 The SimGrid team.
+ * Copyright 2006,2007,2010,2011 The SimGrid team.
* All right reserved.
*
* This program is free software; you can redistribute
*/
package org.simgrid.msg;
-
import java.util.Hashtable;
import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
-/**
- *
- * @author lbobelin
- */
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,
* @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();
}
/**
- *
+ * 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();
properties = new Hashtable<String,String>();
hostName = null;
function = null;
+ startTime = 0;
+ killTime = -1;
}
/**
* @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);
}
/**
* @param value
*/
public static void onProperty(String id, String value) {
- setProperty(id, value);
+ setProperty(id, value);
}
/**
* @param arg
*/
public static void onProcessArg(String arg) {
- registerProcessArg(arg);
+ registerProcessArg(arg);
}
/**