Also, removed the mandatory "Host, String, String[], double, double" constructor and replaced it with the old "Host, String, String[]" mandatory constructor
for the classes (updated the examples if you need an example), since we can't know from MSG the start_time and the kill_time if we launch it from
deployment file.
src/jmsg_task.h
src/jmsg_synchro.c
src/jmsg_synchro.h
- src/jmsg_application_handler.c
- src/jmsg_application_handler.h
)
set(JMSG_JAVA_SRC
- org/simgrid/msg/ApplicationHandler.java
org/simgrid/msg/Host.java
org/simgrid/msg/HostFailureException.java
org/simgrid/msg/HostNotFoundException.java
public class Forwarder extends Process {
- public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Forwarder(Host host, String name, String[]args) {
+ super(host,name,args);
}
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
}
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
}
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
- }
+ public Forwarder(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
}
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
}
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
if (args.length < 1) {
import org.simgrid.msg.Process;
public class Master extends Process {
- public Master(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args, startTime, killTime);
- }
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 4) {
Msg.info("Master needs 4 arguments");
import org.simgrid.msg.*;
public class Slave extends org.simgrid.msg.Process {
- public Slave(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args, startTime, killTime);
- }
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 1) {
Msg.info("Slave needs 1 argument (its number)");
public class Coordinator extends Process {
- public Coordinator(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args, startTime, killTime);
- }
+ public Coordinator(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
- }
+ public Node(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void request(double CStime) throws MsgException {
RequestTask req = new RequestTask(this.name);
Msg.info("Send a request to the coordinator");
import org.simgrid.msg.Process;
public class Receiver extends Process {
- public Receiver(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
- }
+ public Receiver(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
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, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
+ public Sender(Host host, String name, String[] args) {
+ super(host,name,args);
}
private final double commSizeLat = 1;
final double commSizeBw = 100000000;
public class Master extends Process {
- public Master(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
- }
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
Msg.info("Hello!");
waitFor(10.0);
* Lazy Guy Slave, suspends itself ASAP
*/
public class Slave extends Process {
- public Slave(Host host, String name, String[]args, double startTime, double killTime) {
- super(host,name,args,startTime,killTime);
- }
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
Msg.info("Hello!");
waitFor(10.0);
+++ /dev/null
-/*
- * These are the upcalls used by the FleXML parser for application files
- *
- * Copyright 2006,2007,2010,2011 The SimGrid team.
- * All right reserved.
- *
- * This program is free software; you can redistribute
- * it and/or modify it under the terms of the license
- * (GNU LGPL) which comes with this package.
- */
-
-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 {
-
-
- /**
- * The vector which contains the arguments of the main function
- * of the process object.
- */
- public static Vector<String> args;
-
- /**
- *
- */
- public static Hashtable<String,String> properties;
-
- /**
- * The name of the host of the process.
- */
- private static String hostName;
-
- /**
- * 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,
- * and clear the vector containing the arguments of the
- * previouse process function if needed.
- *
- * @param hostName_
- * @param function_
- * @host The host of the process to create.
- * @function The function of the process to create.
- *
- */
- 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();
-
- if(!properties.isEmpty())
- properties.clear();
- }
- /**
- * This method is called by the startElement() handler.
- * It stores the argument of the function of the next
- * process to create in the vector of arguments.
- *
- * @param arg
- * @arg The argument to add.
- *
- */ public static void registerProcessArg(String arg) {
- args.add(arg);
- }
-
- /**
- *
- * @param id
- * @param value
- */
- public static void setProperty(String id, String value)
- {
- properties.put(id,value);
- }
-
- /**
- *
- * @return
- */
- public static String getHostName()
- {
- return hostName;
- }
-
- /**
- * Method called to create the process
- */
- @SuppressWarnings("unchecked")
- 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, 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();
-
- } catch(ClassNotFoundException e) {
- System.out.println(function +
- " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)");
- e.printStackTrace();
-
- } catch(InstantiationException e) {
- System.out.println("Unable to create the process. I got an instantiation exception");
- e.printStackTrace();
- } catch(IllegalAccessException e) {
- System.out.println("Unable to create the process. I got an illegal access exception");
- e.printStackTrace();
- }
-
- }
-
-
- /**
- *
- */
- public static void onStartDocument() {
- args = new Vector<String>();
- 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, String startTime, String killTime) {
- setProcessIdentity(hostName, function, startTime, killTime);
-
- }
- /**
- *
- * @param id
- * @param value
- */
- public static void onProperty(String id, String value) {
- setProperty(id, value);
- }
-
- /**
- *
- * @param arg
- */
- public static void onProcessArg(String arg) {
- registerProcessArg(arg);
- }
-
- /**
- *
- */
- public static void onEndProcess() {
- createProcess();
- }
-
- /**
- *
- */
- public static void onEndDocument() {
- }
-}
/**
* Start time of the process
*/
- public double startTime;
+ public double startTime = 0;
/**
* Kill time of the process
*/
- public double killTime;
+ public double killTime = -1;
public Hashtable<String,String> properties;
*
*/
public Process(String hostname, String name) throws HostNotFoundException {
- this(Host.getByName(hostname), name, null, 0, -1);
+ this(Host.getByName(hostname), name, null);
}
/**
* 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, 0, -1);
+ this(Host.getByName(hostname), name, args);
}
/**
* 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, 0, -1);
+ this(host, name, null);
}
+ /**
+ * 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 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;
+ if (name == null)
+ throw new NullPointerException("Process name cannot be NULL");
+ this.name = name;
+
+ this.args = new Vector<String>();
+ if (null != args)
+ this.args.addAll(Arrays.asList(args));
+
+ this.properties = new Hashtable<String,String>();
+ }
/**
* Constructs a new process from a host and his name, the arguments of here method function are
* specified by the parameter 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;
if (name == null)
* 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, double startTime, double killTime) throws HostNotFoundException;
+ protected native void create(String hostName) throws HostNotFoundException;
/**
* This method kills all running process of the simulation.
*
public final void start() throws HostNotFoundException {
if (!started) {
started = true;
- create(host.getName(), startTime, killTime);
+ create(host.getName());
}
}
#include "jmsg_host.h"
#include "jmsg_task.h"
-#include "jmsg_application_handler.h"
#include "jxbt_utilities.h"
#include "jmsg.h"
#endif
/* end of eclipse-mandated pimple */
+static int create_jprocess(int argc, char *argv[]);
+
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
static JavaVM *__java_vm = NULL;
const char *deploymentFile =
(*env)->GetStringUTFChars(env, jdeploymentFile, 0);
- surf_parse_reset_callbacks();
-
- surfxml_add_callback(STag_surfxml_process_cb_list,
- japplication_handler_on_begin_process);
-
- surfxml_add_callback(ETag_surfxml_argument_cb_list,
- japplication_handler_on_process_arg);
-
- surfxml_add_callback(STag_surfxml_prop_cb_list,
- japplication_handler_on_property);
-
- surfxml_add_callback(ETag_surfxml_process_cb_list,
- japplication_handler_on_end_process);
-
- surf_parse_open(deploymentFile);
-
- japplication_handler_on_start_document();
-
- if (surf_parse())
- jxbt_throw_jni(env, "surf_parse() failed");
-
- surf_parse_close();
-
- japplication_handler_on_end_document();
-
- (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);
+ SIMIX_function_register_default(create_jprocess);
+ MSG_launch_application(deploymentFile);
+}
+/**
+ * Function called when there is the need to create the java Process object
+ * (when we are using deployement files).
+ * it HAS to be executed on the process context, else really bad things will happen.
+ */
+static int create_jprocess(int argc, char *argv[]) {
+ JNIEnv *env = get_current_thread_env();
+ //Change the "." in class name for "/".
+ xbt_str_subst(argv[0],'.','/',0);
+ jclass class_Process = (*env)->FindClass(env, argv[0]);
+ xbt_str_subst(argv[0],'/','.',0);
+ //Retrieve the methodID for the constructor
+ xbt_assert((class_Process != NULL), "Class not found.");
+ jmethodID constructor_Process = (*env)->GetMethodID(env, class_Process, "<init>", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V");
+ xbt_assert((constructor_Process != NULL), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]);
+
+ //Retrieve the name of the process.
+ jstring jname = (*env)->NewStringUTF(env, argv[0]);
+ //Build the arguments
+ jobjectArray args = (jobjectArray)((*env)->NewObjectArray(env,argc - 1,
+ (*env)->FindClass(env,"java/lang/String"),
+ (*env)->NewStringUTF(env,"")));
+ int i;
+ for (i = 1; i < argc; i++)
+ (*env)->SetObjectArrayElement(env,args,i - 1,(*env)->NewStringUTF(env, argv[i]));
+ //Retrieve the host for the process.
+ jstring jhostName = (*env)->NewStringUTF(env, MSG_host_get_name(MSG_host_self()));
+ jobject jhost = Java_org_simgrid_msg_Host_getByName(env, NULL, jhostName);
+ //creates the process
+ jobject jprocess = (*env)->NewObject(env, class_Process, constructor_Process, jhost, jname, args);
+ xbt_assert((jprocess != NULL), "Process allocation failed.");
+ jprocess = (*env)->NewGlobalRef(env, jprocess);
+ //bind the process to the context
+ m_process_t process = MSG_process_self();
+ smx_ctx_java_t context = (smx_ctx_java_t)MSG_process_get_smx_ctx(process);
+ context->jprocess = jprocess;
+ /* sets the PID and the PPID of the process */
+ (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
+ (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
+
+ jprocess_bind(jprocess, process, env);
+
+ return 0;
}
+
+++ /dev/null
-/* Upcalls to the Java functions used as callback to the FleXML parser. */
-
-/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "jmsg_application_handler.h"
-
-#include "jmsg.h"
-
-#include "surf/surfxml_parse.h"
-#include "jxbt_utilities.h"
-void japplication_handler_on_start_document(void)
-{
- jclass cls;
- JNIEnv *env = get_current_thread_env();
- jmethodID id =
- jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
- "onStartDocument", "()V");
-
- if (!id
- || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
- return;
-
- (*env)->CallStaticVoidMethod(env, cls, id);
-}
-
-void japplication_handler_on_end_document(void)
-{
- jclass cls;
- JNIEnv *env = get_current_thread_env();
- jmethodID id =
- jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
- "onEndDocument", "()V");
-
- if (!id
- || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
- return;
-
- (*env)->CallStaticVoidMethod(env, cls, id);
-}
-
-void japplication_handler_on_begin_process(void)
-{
- 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;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);
-
- 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)
-{
- jstring jarg;
- jclass cls;
- JNIEnv *env = get_current_thread_env();
- jmethodID id =
- jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
- "onProcessArg", "(Ljava/lang/String;)V");
- if (!id
- || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
- return;
- jarg = (jstring) (*env)->NewStringUTF(env, A_surfxml_argument_value);
-
- (*env)->CallStaticVoidMethod(env, cls, id, jarg);
-}
-
-void japplication_handler_on_property(void)
-{
- jstring jid;
- jstring jvalue;
- jclass cls;
- JNIEnv *env = get_current_thread_env();
- jmethodID id =
- jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
- "onProperty",
- "(Ljava/lang/String;Ljava/lang/String;)V");
- if (!id
- || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
- return;
-
- jid = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_id);
- jvalue = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_value);
- (*env)->CallStaticVoidMethod(env, cls, id, jid, jvalue);
-}
-
-void japplication_handler_on_end_process(void)
-{
- JNIEnv *env = get_current_thread_env();
- jclass cls;
- jmethodID id =
- jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
- "onEndProcess", "()V");
- if (!id
- || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
- return;
- (*env)->CallStaticVoidMethod(env, cls, id);
-}
+++ /dev/null
-/* Upcalls to the Java functions used as callback to the FleXML parser. */
-
-/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef MSG_JAPPLICATION_HANDLER_H
-#define MSG_JAPPLICATION_HANDLER_H
-
-#include <jni.h>
-#include "msg/msg.h"
-void japplication_handler_on_start_document(void);
-void japplication_handler_on_end_document(void);
-void japplication_handler_on_begin_process(void);
-void japplication_handler_on_process_arg(void);
-void japplication_handler_on_property(void);
-void japplication_handler_on_end_process(void);
-
-#endif /* !MSG_JAPPLICATION_HANDLER_H */
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-static jfieldID jprocess_field_Process_bind;
-static jfieldID jprocess_field_Process_name;
-static jfieldID jprocess_field_Process_host;
-static jfieldID jprocess_field_Process_id;
-static jfieldID jprocess_field_Process_pid;
-static jfieldID jprocess_field_Process_ppid;
-
jobject native_to_java_process(m_process_t process)
{
return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
jprocess_field_Process_pid = jxbt_get_jfield(env, jprocess_class_Process, "pid", "I");
jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I");
jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;");
-
+ jprocess_field_Process_killTime = jxbt_get_jfield(env, jprocess_class_Process, "killTime", "D");
if (!jprocess_class_Process || !jprocess_field_Process_id || !jprocess_field_Process_name || !jprocess_field_Process_pid ||
!jprocess_field_Process_ppid || !jprocess_field_Process_host) {
jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
jobject jprocess_arg,
- jobject jhostname, jdouble jstartTime, jdouble jkillTime)
+ jobject jhostname)
{
name = (*env)->GetStringUTFChars(env, jname, 0);
name = xbt_strdup(name);
+ /* Retrieve the kill time from the process */
+ jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime);
/* Actually build the MSG process */
process = MSG_process_create_with_environment(name,
(xbt_main_func_t) jprocess,
- /*data*/ NULL,
+ /*data*/ jprocess,
host,
- (double)jkillTime, /* kill time */
+ (double)jkill, /* kill time */
/*argc, argv, properties*/
0,NULL,NULL);
#include <msg/msg.h>
#include <simgrid/simix.h>
+//Cached java fields
+jfieldID jprocess_field_Process_bind;
+jfieldID jprocess_field_Process_host;
+jfieldID jprocess_field_Process_killTime;
+jfieldID jprocess_field_Process_id;
+jfieldID jprocess_field_Process_name;
+jfieldID jprocess_field_Process_pid;
+jfieldID jprocess_field_Process_ppid;
+
+
jobject native_to_java_process(m_process_t process);
/**
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
jobject jprocess_arg,
- jobject jhostname, jdouble jstartTime, jdouble jkillTime);
+ jobject jhostname);
/*
* Class org_simgrid_msg_Process
void_pfn_smxprocess_t cleanup_func,
void* data)
{
- smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
-
+ smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
/* If the user provided a function for the process then use it
otherwise is the context for maestro */
if (code) {
- context->super.cleanup_func = cleanup_func;
- context->jprocess = (jobject) code;
- context->begin = xbt_os_sem_init(0);
- context->end = xbt_os_sem_init(0);
- context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
+ if (argc == 0) {
+ context->jprocess = (jobject) code;
+ }
+ else {
+ context->jprocess = NULL;
+ }
+ context->super.cleanup_func = cleanup_func;
+ context->begin = xbt_os_sem_init(0);
+ context->end = xbt_os_sem_init(0);
+
+ context->super.argc = argc;
+ context->super.argv = argv;
+ context->super.code = code;
+
+ context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
}
else {
context->thread = NULL;
context->jenv = get_current_thread_env();
//Wait for the first scheduling round to happen.
xbt_os_sem_acquire(context->begin);
+ //Create the "Process" object if needed.
+ if (context->super.argc > 0) {
+ (*(context->super.code))(context->super.argc, context->super.argv);
+ }
+ xbt_assert((context->jprocess != NULL), "Process not created...");
//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");