public class Forwarder extends Process {
- public Forwarder(Host host, String name, String[]args) {
- super(host,name,args);
+ public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
public void main(String[] args) throws MsgException {
if (args.length < 3) {
import org.simgrid.msg.Process;;
public class Master extends Process {
- public Master(Host host, String name, String[]args) {
- super(host,name,args);
+ public Master(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
public void main(String[] args) throws MsgException {
if (args.length < 4) {
import org.simgrid.msg.Process;
public class Slave extends Process {
- public Slave(Host host, String name, String[]args) {
- super(host,name,args);
+ public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
if (args.length < 1) {
public class Forwarder extends Process {
- public Forwarder(Host host, String name, String[]args) {
- super(host,name,args);
- }
+ public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 3) {
Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
import org.simgrid.msg.Process;;
public class Master extends Process {
- public Master(Host host, String name, String[]args) {
- super(host,name,args);
- }
+ public Master(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 4) {
Msg.info("Master needs 4 arguments");
import org.simgrid.msg.Process;
public class Slave extends Process {
- public Slave(Host host, String name, String[]args) {
- super(host,name,args);
+ public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
if (args.length < 1) {
</process>
<!-- The slave process (with no argument) -->
<process host="Jacquelin" function="basic.Slave"><argument value="0"/></process>
- <process host="Boivin" function="basic.Slave"><argument value="1"/></process>
+ <process host="Boivin" function="basic.Slave" start_time="5"><argument value="1"/></process>
<!-- <process host="Jean_Yves" function="Slave"><argument value="2"/></process>
<process host="TeX" function="Slave"><argument value="3"/></process>
<process host="Geoff" function="Slave"><argument value="4"/></process>
import org.simgrid.msg.Process;
public class Master extends Process {
- public Master(Host host, String name, String[]args) {
- super(host,name,args);
+ public Master(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args, startTime, killTime);
}
public void main(String[] args) throws MsgException {
if (args.length < 4) {
import org.simgrid.msg.*;
public class Slave extends org.simgrid.msg.Process {
- public Slave(Host host, String name, String[]args) {
- super(host,name,args);
+ public Slave(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args, startTime, killTime);
}
public void main(String[] args) throws MsgException {
if (args.length < 1) {
public class Coordinator extends Process {
- public Coordinator(Host host, String name, String[]args) {
- super(host,name,args);
+ public Coordinator(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args, startTime, killTime);
}
LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
int CsToServe;
import org.simgrid.msg.Process;
public class Node extends Process {
- public Node(Host host, String name, String[]args) {
- super(host,name,args);
+ public Node(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
public void request(double CStime) throws MsgException {
RequestTask req = new RequestTask(this.name);
import org.simgrid.msg.Process;
public class Receiver extends Process {
- public Receiver(Host host, String name, String[]args) {
- super(host,name,args);
+ public Receiver(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
final double commSizeLat = 1;
final double commSizeBw = 100000000;
import org.simgrid.msg.Process;
public class Sender extends Process {
- public Sender(Host host, String name, String[]args) {
- super(host,name,args);
+ public Sender(Host host, String name, String[]args, double startTime, double killTime) {
+ super(host,name,args,startTime,killTime);
}
private final double commSizeLat = 1;
final double commSizeBw = 100000000;
* 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();
public static void createProcess() {
try {
Class<Process> cls = (Class<Process>) Class.forName(function);
- Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class});
+ 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_);
+ 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\" in the class ?");
+ "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();
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);
}
/**
* access to it. It is set automatically during the build of the object.
*/
public long bind;
-
+ /**
+ * 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.
*/
public static long nextProcessId = 0;
-
+
/**
* Even if this attribute is public you must never access to it.
* It is compute automatically during the creation of the object.
* The native functions use this identifier to synchronize the process.
*/
public long id;
+
+ /**
+ * Start time of the process
+ */
+ public double startTime;
+ /**
+ * Kill time of the process
+ */
+ public double killTime;
public Hashtable<String,String> properties;
/** The arguments of the method function of the process. */
public Vector<String> args;
+
/**
* Default constructor (used in ApplicationHandler to initialize it)
*
*/
public Process(String hostname, String name) throws HostNotFoundException {
- this(Host.getByName(hostname), name, null);
+ this(Host.getByName(hostname), name, null, 0, -1);
}
/**
* Constructs a new process from the name of a host and his name. The arguments
*
*/
public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException {
- this(Host.getByName(hostname), name, args);
+ this(Host.getByName(hostname), name, args, 0, -1);
}
/**
* Constructs a new process from a host and his name. The method function of the
*
*/
public Process(Host host, String name) {
- this(host, name, null);
+ this(host, name, null, 0, -1);
}
/**
* Constructs a new process from a host and his name, the arguments of here method function are
* @param host The host of the process to create.
* @param name The name of the process.
* @param args The arguments of main method of the process.
+ * @param startTime Start time of the process
+ * @param killTime Kill time of the process
*
*/
- public Process(Host host, String name, String[]args) {
+ public Process(Host host, String name, String[]args, double startTime, double killTime) {
/* This is the constructor called by all others */
this();
this.host = host;
this.properties = new Hashtable<String,String>();
+ this.startTime = startTime;
+ this.killTime = killTime;
}
/**
* The natively implemented method to create an MSG process.
* @param host A valid (binded) host where create the process.
*/
- protected native void create(String hostName) throws HostNotFoundException;
+ protected native void create(String hostName, double startTime, double killTime) throws HostNotFoundException;
/**
* This method kills all running process of the simulation.
*
}
/**
* This method actually creates and run the process.
+ * It is a noop if the process is already launched.
* @throws HostNotFoundException
*/
- public void start() throws HostNotFoundException {
- create(host.getName());
+ public final void start() throws HostNotFoundException {
+ if (!started) {
+ started = true;
+ create(host.getName(), startTime, killTime);
+ }
}
/**
System.exit(1);
}
catch(ProcessKilledError pk) {
-
+
}
}
{
jstring jhostName;
jstring jfunction;
+ jstring jstartTime, jkillTime;
jclass cls;
JNIEnv *env = get_current_thread_env();
jmethodID id =
jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
"onBeginProcess",
- "(Ljava/lang/String;Ljava/lang/String;)V");
+ "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
if (!id
|| !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
return;
jhostName = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_host);
jfunction =
(jstring) (*env)->NewStringUTF(env, A_surfxml_process_function);
- (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction);
+
+ jstartTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_start_time);
+ jkillTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_kill_time);
+
+
+ (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction, jstartTime, jkillTime);
}
void japplication_handler_on_process_arg(void)
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
jobject jprocess_arg,
- jobject jhostname)
+ jobject jhostname, jdouble jstartTime, jdouble jkillTime)
{
(xbt_main_func_t) jprocess,
/*data*/ NULL,
host,
- /* kill_time */-1,
+ (double)jkillTime, /* kill time */
/*argc, argv, properties*/
0,NULL,NULL);
*/
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
- jobject jprocess, jobject jhost);
+ jobject jprocess_arg,
+ jobject jhostname, jdouble jstartTime, jdouble jkillTime);
/*
* Class org_simgrid_msg_Process
context->jenv = get_current_thread_env();
//Wait for the first scheduling round to happen.
xbt_os_sem_acquire(context->begin);
+ //wait for the process to be able to begin
+ //TODO: Cache it
+ jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");
+ jdouble startTime = (*env)->GetDoubleField(env, context->jprocess, jprocess_field_Process_startTime);
+ if (startTime > MSG_get_clock()) {
+ MSG_process_sleep(startTime - MSG_get_clock());
+ }
//Execution of the "run" method.
jmethodID id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "run", "()V");
xbt_assert( (id != NULL), "Method not found...");