#include "jmsg_host.h"
#include "jxbt_utilities.h"
#include "smx_context_java.h"
+#include "smx_context_cojava.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;
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_exit(JNIEnv *env, jobject jprocess) {
+ if (smx_factory_initializer_to_use == SIMIX_ctx_cojava_factory_init) {
+ m_process_t process = jprocess_to_native_process(jprocess, env);
+ smx_context_t context = MSG_process_get_smx_ctx(process);
+ smx_ctx_cojava_stop(context);
+ }
+}
jobject native_to_java_process(m_process_t process)
{
void jprocess_bind(jobject jprocess, m_process_t process, JNIEnv * env)
{
- (*env)->SetLongField(env, jprocess, jprocess_field_Process_bind, (jlong) (long) (process));
+ (*env)->SetLongField(env, jprocess, jprocess_field_Process_bind, (jlong)(process));
}
jlong jprocess_get_id(jobject jprocess, JNIEnv * env)
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 */
/*argc, argv, properties*/
0,NULL,NULL);
-
+ MSG_process_set_kill_time(process, (double)jkill);
MSG_process_set_data(process,&process);
/* bind the java process instance to the native process */
jprocess_bind(jprocess, process, env);
(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
double time = jmillis / 1000 + jnanos / 1000;
-
- MSG_error_t rv = MSG_process_sleep(time);
- jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
- bprintf("unexpected error , please report this bug"));
+ MSG_error_t rv;
+ TRY {
+ rv = MSG_process_sleep(time);
+ }
+ CATCH_ANONYMOUS {
+ return;
+ }
+ if (rv != MSG_OK) {
+ jmsg_throw_status(env,rv);
+ }
}
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
jdouble jseconds)
{
- m_process_t process = jprocess_to_native_process(jprocess, env);
-
- if (!process) {
- jxbt_throw_notbound(env, "process", jprocess);
- return;
+ MSG_error_t rv;
+ TRY {
+ rv = MSG_process_sleep((double)jseconds);
+ }
+ CATCH_ANONYMOUS {
+ return;
}
- MSG_error_t rv = MSG_process_sleep((double)jseconds);
if (rv != MSG_OK) {
-// smx_ctx_java_stop(smx_ctx_java_self());
+ XBT_INFO("Status NOK");
+ jmsg_throw_status(env,rv);
}
}
jxbt_throw_notbound(env, "process", jprocess);
return;
}
- /* Sets the "killed" flag to kill the process on the next unschedule */
- smx_ctx_java_t context = (smx_ctx_java_t)MSG_process_get_smx_ctx(process);
- context->killed = 1;
MSG_process_kill(process);
}
/* change the host java side */
(*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
}
+
+
+