From: Samuel Lepetit Date: Wed, 16 May 2012 14:59:56 +0000 (+0200) Subject: Removed "ApplicationHandler" and "japplication_handler" and use MSG_launch_applicatio... X-Git-Tag: v3_9_90~569^2~19^2~75 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6068c9f0036786cdcbeb273d495e5aa378cb5f92?hp=72b87a2780383260b02c46d94d609579d606bb15 Removed "ApplicationHandler" and "japplication_handler" and use MSG_launch_application instead. 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 753e8a7c1c..f097deb049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,12 +88,9 @@ set(JMSG_C_SRC 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 diff --git a/examples/async/Forwarder.java b/examples/async/Forwarder.java index 35fb2e407b..29e9d1835b 100644 --- a/examples/async/Forwarder.java +++ b/examples/async/Forwarder.java @@ -14,8 +14,8 @@ import org.simgrid.msg.Process; 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) { diff --git a/examples/async/Master.java b/examples/async/Master.java index 971cd5f391..19e840cf49 100644 --- a/examples/async/Master.java +++ b/examples/async/Master.java @@ -19,8 +19,8 @@ import org.simgrid.msg.Task; 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) { diff --git a/examples/async/Slave.java b/examples/async/Slave.java index f271dc679b..d58910fd03 100644 --- a/examples/async/Slave.java +++ b/examples/async/Slave.java @@ -17,8 +17,8 @@ import org.simgrid.msg.TransferFailureException; 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) { diff --git a/examples/basic/Forwarder.java b/examples/basic/Forwarder.java index 6152da1463..e8faf39e5e 100644 --- a/examples/basic/Forwarder.java +++ b/examples/basic/Forwarder.java @@ -15,9 +15,9 @@ import org.simgrid.msg.Process; 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)"); diff --git a/examples/basic/Master.java b/examples/basic/Master.java index 5df6154f1a..dfb4a9b475 100644 --- a/examples/basic/Master.java +++ b/examples/basic/Master.java @@ -15,8 +15,8 @@ import org.simgrid.msg.Task; 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) { diff --git a/examples/basic/Slave.java b/examples/basic/Slave.java index 6f43f34ab4..dc216a4d46 100644 --- a/examples/basic/Slave.java +++ b/examples/basic/Slave.java @@ -16,8 +16,8 @@ import org.simgrid.msg.TransferFailureException; 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) { diff --git a/examples/commTime/Master.java b/examples/commTime/Master.java index cd68e14606..ea469638ee 100644 --- a/examples/commTime/Master.java +++ b/examples/commTime/Master.java @@ -17,9 +17,9 @@ import org.simgrid.msg.Task; 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"); diff --git a/examples/commTime/Slave.java b/examples/commTime/Slave.java index 52c10a02f3..0ada19e8e2 100644 --- a/examples/commTime/Slave.java +++ b/examples/commTime/Slave.java @@ -10,9 +10,9 @@ package commTime; 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)"); diff --git a/examples/mutualExclusion/centralized/Coordinator.java b/examples/mutualExclusion/centralized/Coordinator.java index dc4935a8c3..abd94bae40 100644 --- a/examples/mutualExclusion/centralized/Coordinator.java +++ b/examples/mutualExclusion/centralized/Coordinator.java @@ -18,9 +18,9 @@ import org.simgrid.msg.Process; 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 waitingQueue=new LinkedList(); int CsToServe; diff --git a/examples/mutualExclusion/centralized/Node.java b/examples/mutualExclusion/centralized/Node.java index d261b79d54..90ff40ff3a 100644 --- a/examples/mutualExclusion/centralized/Node.java +++ b/examples/mutualExclusion/centralized/Node.java @@ -15,9 +15,9 @@ import org.simgrid.msg.Task; 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"); diff --git a/examples/pingPong/Receiver.java b/examples/pingPong/Receiver.java index a0cb0ff781..05f50dcde8 100644 --- a/examples/pingPong/Receiver.java +++ b/examples/pingPong/Receiver.java @@ -15,9 +15,9 @@ import org.simgrid.msg.Task; 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; diff --git a/examples/pingPong/Sender.java b/examples/pingPong/Sender.java index 7e00cc08fc..0af72d0867 100644 --- a/examples/pingPong/Sender.java +++ b/examples/pingPong/Sender.java @@ -14,8 +14,8 @@ import org.simgrid.msg.MsgException; 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; diff --git a/examples/startKillTime/Master.java b/examples/startKillTime/Master.java index 1262850e7d..b71dd8f601 100644 --- a/examples/startKillTime/Master.java +++ b/examples/startKillTime/Master.java @@ -15,9 +15,9 @@ 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 TransferFailureException, HostFailureException, TimeoutException { Msg.info("Hello!"); waitFor(10.0); diff --git a/examples/startKillTime/Slave.java b/examples/startKillTime/Slave.java index 2120e905d3..2f5c82c11a 100644 --- a/examples/startKillTime/Slave.java +++ b/examples/startKillTime/Slave.java @@ -17,9 +17,9 @@ import org.simgrid.msg.Process; * 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); diff --git a/org/simgrid/msg/ApplicationHandler.java b/org/simgrid/msg/ApplicationHandler.java deleted file mode 100644 index b485d77313..0000000000 --- a/org/simgrid/msg/ApplicationHandler.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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 args; - - /** - * - */ - public static Hashtable 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 cls = (Class) Class.forName(function); - Constructor 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(); - properties = new Hashtable(); - 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() { - } -} diff --git a/org/simgrid/msg/Process.java b/org/simgrid/msg/Process.java index ea1f275735..5e1b4e6bac 100644 --- a/org/simgrid/msg/Process.java +++ b/org/simgrid/msg/Process.java @@ -75,11 +75,11 @@ public abstract class Process implements Runnable { /** * 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 properties; @@ -128,7 +128,7 @@ public abstract class Process implements Runnable { * */ 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 @@ -144,7 +144,7 @@ public abstract class Process implements Runnable { * */ 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 @@ -155,8 +155,29 @@ public abstract class Process implements Runnable { * */ 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(); + if (null != args) + this.args.addAll(Arrays.asList(args)); + + this.properties = new Hashtable(); + } /** * Constructs a new process from a host and his name, the arguments of here method function are * specified by the parameter args. @@ -169,7 +190,6 @@ public abstract class Process implements Runnable { * */ 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) @@ -189,7 +209,7 @@ public abstract class Process implements Runnable { * 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. * @@ -325,7 +345,7 @@ public abstract class Process implements Runnable { public final void start() throws HostNotFoundException { if (!started) { started = true; - create(host.getName(), startTime, killTime); + create(host.getName()); } } diff --git a/src/jmsg.c b/src/jmsg.c index 9f7490584f..1e02578f40 100644 --- a/src/jmsg.c +++ b/src/jmsg.c @@ -17,7 +17,6 @@ #include "jmsg_host.h" #include "jmsg_task.h" -#include "jmsg_application_handler.h" #include "jxbt_utilities.h" #include "jmsg.h" @@ -31,6 +30,8 @@ #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; @@ -165,30 +166,51 @@ Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, 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, "", "(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; } + diff --git a/src/jmsg_application_handler.c b/src/jmsg_application_handler.c deleted file mode 100644 index ac40766471..0000000000 --- a/src/jmsg_application_handler.c +++ /dev/null @@ -1,116 +0,0 @@ -/* 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); -} diff --git a/src/jmsg_application_handler.h b/src/jmsg_application_handler.h deleted file mode 100644 index 7d3a2159d3..0000000000 --- a/src/jmsg_application_handler.h +++ /dev/null @@ -1,21 +0,0 @@ -/* 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 -#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 */ diff --git a/src/jmsg_process.c b/src/jmsg_process.c index 9b3bb96d55..213b345fbc 100644 --- a/src/jmsg_process.c +++ b/src/jmsg_process.c @@ -14,13 +14,6 @@ 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; @@ -84,7 +77,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) { 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.")); @@ -93,7 +86,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) { JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jprocess_arg, - jobject jhostname, jdouble jstartTime, jdouble jkillTime) + jobject jhostname) { @@ -137,12 +130,14 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env, 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); diff --git a/src/jmsg_process.h b/src/jmsg_process.h index f917960736..a97c0ddd40 100644 --- a/src/jmsg_process.h +++ b/src/jmsg_process.h @@ -13,6 +13,16 @@ #include #include +//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); /** @@ -142,7 +152,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls); 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 diff --git a/src/smx_context_java.c b/src/smx_context_java.c index 8065420e00..10fa3ea4f5 100644 --- a/src/smx_context_java.c +++ b/src/smx_context_java.c @@ -66,16 +66,25 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, 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; @@ -96,6 +105,11 @@ static void* smx_ctx_java_thread_run(void *data) { 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");