4 * Copyright 2006,2007 Martin Quinson, Malek Cherier All right reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package.
9 * This contains the implementation of the wrapper functions used to interface
10 * the java object with the native functions of the MSG API.
13 #include "msg/private.h"
14 #include "simix/private.h"
15 #include "simix/smx_context_java.h"
17 #include "jmsg_process.h"
18 #include "jmsg_host.h"
19 #include "jmsg_task.h"
20 #include "jmsg_application_handler.h"
21 #include "jxbt_utilities.h"
24 #include "msg/mailbox.h"
25 #include "surf/surfxml_parse.h"
27 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
29 static JavaVM *__java_vm = NULL;
31 static jobject native_to_java_process(m_process_t process);
33 JavaVM *get_java_VM(void)
38 JNIEnv *get_current_thread_env(void)
42 (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL);
47 static jobject native_to_java_process(m_process_t process)
49 return ((smx_ctx_java_t)
50 (process->simdata->s_process->context))->jprocess;
54 * The MSG process connected functions implementation.
57 JNIEXPORT void JNICALL
58 Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
59 jobject jprocess_arg, jobject jhost)
61 jobject jprocess; /* the global reference to the java process instance */
62 jstring jname; /* the name of the java process instance */
63 const char *name; /* the C name of the process */
64 m_process_t process; /* the native process to create */
65 char alias[MAX_ALIAS_NAME + 1] = { 0 };
66 msg_mailbox_t mailbox;
69 ("Java_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,jhost=%p)",
70 env, cls, jprocess_arg, jhost);
71 /* get the name of the java process */
72 jname = jprocess_get_name(jprocess_arg, env);
77 ("Internal error: Process name cannot be NULL"));
81 /* allocate the data of the simulation */
82 process = xbt_new0(s_m_process_t, 1);
83 process->simdata = xbt_new0(s_simdata_process_t, 1);
85 /* create a global java process instance */
86 jprocess = jprocess_new_global_ref(jprocess_arg, env);
89 free(process->simdata);
91 jxbt_throw_jni(env, "Can't get a global ref to the java process");
95 /* bind the java process instance to the native process */
96 jprocess_bind(jprocess, process, env);
98 /* build the C name of the process */
99 name = (*env)->GetStringUTFChars(env, jname, 0);
100 process->name = xbt_strdup(name);
101 (*env)->ReleaseStringUTFChars(env, jname, name);
103 process->simdata->m_host = jhost_get_native(env, jhost);
106 if (!(process->simdata->m_host)) { /* not binded */
107 free(process->simdata);
110 jxbt_throw_notbound(env, "host", jhost);
113 process->simdata->PID = msg_global->PID++;
115 /* create a new context */
117 ("fill in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p); env=%p",
118 process->name, process->simdata->m_host->name, process->simdata->PID,
119 process, process->simdata, process->simdata->m_host,
120 process->simdata->m_host->simdata, env);
122 process->simdata->s_process =
123 SIMIX_process_create(process->name, (xbt_main_func_t)jprocess,
124 /*data */ (void *) process,
125 process->simdata->m_host->simdata->smx_host->name,
128 DEBUG1("context created (s_process=%p)", process->simdata->s_process);
131 if (SIMIX_process_self()) { /* someone created me */
132 process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
134 process->simdata->PPID = -1;
137 process->simdata->last_errno = MSG_OK;
139 /* add the process to the list of the processes of the simulation */
140 xbt_fifo_unshift(msg_global->process_list, process);
142 sprintf(alias, "%s:%s", (process->simdata->m_host->simdata->smx_host)->name,
145 mailbox = MSG_mailbox_new(alias);
149 JNIEXPORT void JNICALL
150 Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
153 m_process_t process = jprocess_to_native_process(jprocess, env);
156 jxbt_throw_notbound(env, "process", jprocess);
160 /* try to suspend the process */
161 MSG_error_t rv = MSG_process_suspend(process);
163 jxbt_check_res("MSG_process_suspend()",rv,MSG_OK,
164 bprintf("unexpected error , please report this bug"));
168 JNIEXPORT void JNICALL
169 Java_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
172 m_process_t process = jprocess_to_native_process(jprocess, env);
175 jxbt_throw_notbound(env,"process", jprocess);
179 /* try to resume the process */
180 MSG_error_t rv = MSG_process_resume(process);
182 jxbt_check_res("MSG_process_resume()",rv,MSG_OK,
183 bprintf("unexpected error , please report this bug"));
186 JNIEXPORT jboolean JNICALL
187 Java_simgrid_msg_MsgNative_processIsSuspended(JNIEnv * env, jclass cls,
190 m_process_t process = jprocess_to_native_process(jprocess, env);
193 jxbt_throw_notbound(env, "process", jprocess);
197 /* true is the process is suspended, false otherwise */
198 return (jboolean) MSG_process_is_suspended(process);
201 JNIEXPORT void JNICALL
202 Java_simgrid_msg_MsgNative_processKill(JNIEnv * env, jclass cls,
205 /* get the native instances from the java ones */
206 m_process_t process = jprocess_to_native_process(jprocess, env);
209 jxbt_throw_notbound(env, "process", jprocess);
213 /* delete the global reference */
214 jprocess_delete_global_ref(native_to_java_process(process), env);
216 /* kill the native process (this wrapper is call by the destructor of the java
219 MSG_process_kill(process);
222 JNIEXPORT jobject JNICALL
223 Java_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls,
226 /* get the native instances from the java ones */
227 m_process_t process = jprocess_to_native_process(jprocess, env);
231 jxbt_throw_notbound(env, "process", jprocess);
235 host = MSG_process_get_host(process);
238 jxbt_throw_jni(env, "MSG_process_get_host() failed");
242 /* return the global reference to the java host instance */
243 return (jobject) host->data;
247 JNIEXPORT jobject JNICALL
248 Java_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls, jint PID)
250 m_process_t process = MSG_process_from_PID(PID);
253 jxbt_throw_process_not_found(env, bprintf("PID = %d", PID));
257 if (!native_to_java_process(process)) {
258 jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
262 return (jobject) (native_to_java_process(process));
266 JNIEXPORT jint JNICALL
267 Java_simgrid_msg_MsgNative_processGetPID(JNIEnv * env, jclass cls,
270 m_process_t process = jprocess_to_native_process(jprocess, env);
273 jxbt_throw_notbound(env, "process", jprocess);
277 return (jint) MSG_process_get_PID(process);
281 JNIEXPORT jint JNICALL
282 Java_simgrid_msg_MsgNative_processGetPPID(JNIEnv * env, jclass cls,
285 m_process_t process = jprocess_to_native_process(jprocess, env);
288 jxbt_throw_notbound(env, "process", jprocess);
292 return (jint) MSG_process_get_PPID(process);
295 JNIEXPORT jobject JNICALL
296 Java_simgrid_msg_MsgNative_processSelf(JNIEnv * env, jclass cls)
298 m_process_t process = MSG_process_self();
302 jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed"));
306 jprocess = native_to_java_process(process);
309 jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
314 JNIEXPORT void JNICALL
315 Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv * env, jclass cls,
318 m_host_t host = jhost_get_native(env, jhost);
321 jxbt_throw_notbound(env, "host", jhost);
325 /* try to change the host of the process */
326 MSG_error_t rv = MSG_process_change_host(host);
328 jxbt_check_res("MSG_process_change_host()",rv,MSG_OK,
329 bprintf("unexpected error , please report this bug"));
333 JNIEXPORT void JNICALL
334 Java_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls,
337 MSG_error_t rv= MSG_process_sleep((double) seconds);
339 jxbt_check_res("MSG_process_sleep()",rv, MSG_HOST_FAILURE,
340 bprintf("while process was waiting for %f seconds",(double)seconds));
345 /***************************************************************************************
346 * The MSG host connected functions implementation. *
347 ***************************************************************************************/
349 JNIEXPORT jobject JNICALL
350 Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls,
353 m_host_t host; /* native host */
354 jobject jhost; /* global reference to the java host instance returned */
356 /* get the C string from the java string */
357 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
359 /* get the host by name (the hosts are created during the grid resolution) */
360 host = MSG_get_host_by_name(name);
361 DEBUG2("MSG gave %p as native host (simdata=%p)", host, host->simdata);
363 (*env)->ReleaseStringUTFChars(env, jname, name);
365 if (!host) { /* invalid name */
366 jxbt_throw_host_not_found(env, name);
370 if (!host->data) { /* native host not associated yet with java host */
372 /* instanciate a new java host */
373 jhost = jhost_new_instance(env);
376 jxbt_throw_jni(env, "java host instantiation failed");
380 /* get a global reference to the newly created host */
381 jhost = jhost_ref(env, jhost);
384 jxbt_throw_jni(env, "new global ref allocation failed");
388 /* bind the java host and the native host */
389 jhost_bind(jhost, host, env);
391 /* the native host data field is set with the global reference to the
392 * java host returned by this function
394 host->data = (void *) jhost;
397 /* return the global reference to the java host instance */
398 return (jobject) host->data;
401 JNIEXPORT jstring JNICALL
402 Java_simgrid_msg_MsgNative_hostGetName(JNIEnv * env, jclass cls,
405 m_host_t host = jhost_get_native(env, jhost);
408 jxbt_throw_notbound(env, "host", jhost);
412 return (*env)->NewStringUTF(env, host->name);
415 JNIEXPORT jint JNICALL
416 Java_simgrid_msg_MsgNative_hostGetNumber(JNIEnv * env, jclass cls)
418 return (jint) MSG_get_host_number();
421 JNIEXPORT jobject JNICALL
422 Java_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls)
426 m_host_t host = MSG_host_self();
429 /* the native host not yet associated with the java host instance */
431 /* instanciate a new java host instance */
432 jhost = jhost_new_instance(env);
435 jxbt_throw_jni(env, "java host instantiation failed");
439 /* get a global reference to the newly created host */
440 jhost = jhost_ref(env, jhost);
443 jxbt_throw_jni(env, "global ref allocation failed");
447 /* Bind & store it */
448 jhost_bind(jhost, host, env);
449 host->data = (void *) jhost;
451 jhost = (jobject) host->data;
457 JNIEXPORT jdouble JNICALL
458 Java_simgrid_msg_MsgNative_hostGetSpeed(JNIEnv * env, jclass cls,
461 m_host_t host = jhost_get_native(env, jhost);
464 jxbt_throw_notbound(env, "host", jhost);
468 return (jdouble) MSG_get_host_speed(host);
471 JNIEXPORT jint JNICALL
472 Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
475 m_host_t host = jhost_get_native(env, jhost);
478 jxbt_throw_notbound(env, "host", jhost);
482 return (jint) MSG_get_host_msgload(host);
486 JNIEXPORT jboolean JNICALL
487 Java_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
490 m_host_t host = jhost_get_native(env, jhost);
493 jxbt_throw_notbound(env, "host", jhost);
497 return (jboolean) MSG_host_is_avail(host);
501 /***************************************************************************************
502 * The MSG task connected functions implementation. *
503 ***************************************************************************************/
505 JNIEXPORT void JNICALL
506 Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, jobject jtask,
507 jstring jname, jdouble jcomputeDuration,
508 jdouble jmessageSize)
510 m_task_t task; /* the native task to create */
511 const char *name=NULL; /* the name of the task */
513 if (jcomputeDuration < 0) {
514 jxbt_throw_illegal(env,
515 bprintf("Task ComputeDuration (%f) cannot be negative",
516 (double) jcomputeDuration));
520 if (jmessageSize < 0) {
521 jxbt_throw_illegal(env,
522 bprintf("Task MessageSize (%f) cannot be negative",
523 (double) jmessageSize));
528 /* get the C string from the java string */
529 name = (*env)->GetStringUTFChars(env, jname, 0);
533 /* create the task */
535 MSG_task_create(name, (double) jcomputeDuration, (double) jmessageSize,
539 (*env)->ReleaseStringUTFChars(env, jname, name);
541 /* bind & store the task */
542 jtask_bind(jtask, task, env);
544 /* allocate a new global reference to the java task instance */
545 task->data = (void *) jtask_new_global_ref(jtask, env);
548 jxbt_throw_jni(env, "global ref allocation failed");
552 JNIEXPORT void JNICALL
553 Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls,
554 jobject jtask, jstring jname,
557 jcomputeDurations_arg,
558 jdoubleArray jmessageSizes_arg)
561 m_task_t task; /* the native parallel task to create */
562 const char *name; /* the name of the task */
565 double *computeDurations;
566 double *messageSizes;
567 jdouble *jcomputeDurations;
568 jdouble *jmessageSizes;
574 if (!jcomputeDurations_arg) {
577 ("Parallel task compute durations cannot be null"));
581 if (!jmessageSizes_arg) {
583 xbt_strdup("Parallel task message sizes cannot be null"));
588 jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null"));
592 host_count = (int) (*env)->GetArrayLength(env, jhosts);
595 hosts = xbt_new0(m_host_t, host_count);
596 computeDurations = xbt_new0(double, host_count);
597 messageSizes = xbt_new0(double, host_count * host_count);
600 (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0);
601 jmessageSizes = (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0);
603 for (index = 0; index < host_count; index++) {
604 jhost = (*env)->GetObjectArrayElement(env, jhosts, index);
605 hosts[index] = jhost_get_native(env, jhost);
606 computeDurations[index] = jcomputeDurations[index];
608 for (index = 0; index < host_count * host_count; index++) {
609 messageSizes[index] = jmessageSizes[index];
612 (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg,
613 jcomputeDurations, 0);
614 (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes,
618 /* get the C string from the java string */
619 name = (*env)->GetStringUTFChars(env, jname, 0);
622 MSG_parallel_task_create(name, host_count, hosts, computeDurations,
625 (*env)->ReleaseStringUTFChars(env, jname, name);
627 /* associate the java task object and the native task */
628 jtask_bind(jtask, task, env);
630 task->data = (void *) jtask;
633 jxbt_throw_jni(env, "global ref allocation failed");
636 JNIEXPORT jobject JNICALL
637 Java_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls,
642 m_task_t task = jtask_to_native_task(jtask, env);
645 jxbt_throw_notbound(env, "task", jtask);
649 process = MSG_task_get_sender(task);
650 return (jobject) native_to_java_process(process);
653 JNIEXPORT jobject JNICALL
654 Java_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
658 m_task_t task = jtask_to_native_task(jtask, env);
661 jxbt_throw_notbound(env, "task", jtask);
665 host = MSG_task_get_source(task);
668 jxbt_throw_jni(env, "MSG_task_get_source() failed");
672 return (jobject) host->data;
676 JNIEXPORT jstring JNICALL
677 Java_simgrid_msg_MsgNative_taskGetName(JNIEnv * env, jclass cls,
680 m_task_t task = jtask_to_native_task(jtask, env);
683 jxbt_throw_notbound(env, "task", jtask);
687 return (*env)->NewStringUTF(env, task->name);
690 JNIEXPORT void JNICALL
691 Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask)
693 m_task_t ptask = jtask_to_native_task(jtask, env);
696 jxbt_throw_notbound(env, "task", jtask);
700 MSG_error_t rv = MSG_task_cancel(ptask);
702 jxbt_check_res("MSG_task_cancel()",rv,MSG_OK,
703 bprintf("unexpected error , please report this bug"));
706 JNIEXPORT jdouble JNICALL
707 Java_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls,
710 m_task_t ptask = jtask_to_native_task(jtask, env);
713 jxbt_throw_notbound(env, "task", jtask);
716 return (jdouble) MSG_task_get_compute_duration(ptask);
719 JNIEXPORT jdouble JNICALL
720 Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, jclass cls,
723 m_task_t ptask = jtask_to_native_task(jtask, env);
726 jxbt_throw_notbound(env, "task", jtask);
729 return (jdouble) MSG_task_get_remaining_computation(ptask);
732 JNIEXPORT void JNICALL
733 Java_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls,
734 jobject jtask, jdouble priority)
736 m_task_t task = jtask_to_native_task(jtask, env);
739 jxbt_throw_notbound(env, "task", jtask);
742 MSG_task_set_priority(task, (double) priority);
745 JNIEXPORT void JNICALL
746 Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls,
750 /* get the native task */
751 m_task_t task = jtask_to_native_task(jtask_arg, env);
755 jxbt_throw_notbound(env, "task", task);
758 jtask = (jobject) task->data;
760 MSG_error_t rv = MSG_task_destroy(task);
762 jxbt_check_res("MSG_task_destroy()",rv,MSG_OK,
763 bprintf("unexpected error , please report this bug"));
766 /* delete the global reference to the java task object */
767 jtask_delete_global_ref(jtask, env);
770 JNIEXPORT void JNICALL
771 Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
774 m_task_t task = jtask_to_native_task(jtask, env);
777 jxbt_throw_notbound(env, "task", jtask);
781 MSG_error_t rv = MSG_task_execute(task);
783 jxbt_check_res("MSG_task_execute()",rv,MSG_HOST_FAILURE|MSG_TASK_CANCELLED,
784 bprintf("while executing task %s", MSG_task_get_name(task)));
787 /***************************************************************************************
788 * Unsortable functions *
789 ***************************************************************************************/
792 JNIEXPORT jint JNICALL
793 Java_simgrid_msg_Msg_getErrCode(JNIEnv * env, jclass cls)
795 return (jint) MSG_get_errno();
798 JNIEXPORT jdouble JNICALL
799 Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
801 return (jdouble) MSG_get_clock();
805 JNIEXPORT void JNICALL
806 Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) {
814 argc = (int) (*env)->GetArrayLength(env, jargs);
817 argv = xbt_new0(char *, argc);
818 argv[0] = strdup("java");
820 for (index = 0; index < argc - 1; index++) {
821 jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index);
822 tmp = (*env)->GetStringUTFChars(env, jval, 0);
823 argv[index + 1] = strdup(tmp);
824 (*env)->ReleaseStringUTFChars(env, jval, tmp);
827 MSG_global_init(&argc, argv);
828 SIMIX_context_select_factory("java");
830 for (index = 0; index < argc; index++)
835 (*env)->GetJavaVM(env, &__java_vm);
838 JNIEXPORT void JNICALL
839 JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) {
841 int index;//xbt_fifo_item_t item = NULL;
847 jxbt_check_res("MSG_main()",rv,MSG_OK,
848 bprintf("unexpected error : MSG_main() failed .. please report this bug "));
851 ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
853 DEBUG0("Clean java world");
854 /* Cleanup java hosts */
855 hosts = MSG_get_host_table();
856 for (index=0;index<MSG_get_host_number()-1;index++)
858 jhost = (jobject)hosts[index]->data;
860 jhost_unref(env,jhost);
864 DEBUG0("Clean native world");
865 /* cleanup native stuff */
866 rv = MSG_OK != MSG_clean();
867 jxbt_check_res("MSG_clean()",rv,MSG_OK,
868 bprintf("unexpected error : MSG_clean() failed .. please report this bug "));
872 JNIEXPORT jint JNICALL
873 Java_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls,
876 return (jint) MSG_process_killall((int) jresetPID);
879 JNIEXPORT void JNICALL
880 Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
881 jstring jplatformFile)
884 const char *platformFile = (*env)->GetStringUTFChars(env, jplatformFile, 0);
886 MSG_create_environment(platformFile);
888 (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
891 JNIEXPORT void JNICALL
892 Java_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls,
896 m_process_t process = jprocess_to_native_process(jprocess, env);
899 jxbt_throw_notbound(env, "process", jprocess);
903 SIMIX_context_stop(SIMIX_process_self()->context);
906 JNIEXPORT void JNICALL
907 Java_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
909 const char *s = (*env)->GetStringUTFChars(env, js, 0);
911 (*env)->ReleaseStringUTFChars(env, js, s);
914 JNIEXPORT jobjectArray JNICALL
915 Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
923 int count = MSG_get_host_number();
924 m_host_t *table = MSG_get_host_table();
926 jclass cls = jxbt_get_class(env, "simgrid/msg/Host");
932 jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
935 jxbt_throw_jni(env, "Hosts table allocation failed");
939 for (index = 0; index < count; index++) {
941 jhost = (jobject) (host->data);
944 jname = (*env)->NewStringUTF(env, host->name);
946 jhost = Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname);
947 /* FIXME: leak of jname ? */
950 (*env)->SetObjectArrayElement(env, jtable, index, jhost);
957 JNIEXPORT void JNICALL
958 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,
964 /* get the C string from the java string */
965 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
968 SIMIX_context_select_factory(name);
970 errmsg = xbt_strdup(e.msg);
974 (*env)->ReleaseStringUTFChars(env, jname, name);
977 char *thrown = bprintf("xbt_select_context_factory() failed: %s", errmsg);
979 jxbt_throw_jni(env, thrown);
983 JNIEXPORT void JNICALL
984 Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
985 jstring jalias, jobject jtask,
990 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
992 m_task_t task = jtask_to_native_task(jtask, env);
996 (*env)->ReleaseStringUTFChars(env, jalias, alias);
997 jxbt_throw_notbound(env, "task", jtask);
1001 rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
1003 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1005 jxbt_check_res("MSG_task_send_with_timeout()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT,
1006 bprintf("while sending task %s to mailbox %s", MSG_task_get_name(task),alias));
1009 JNIEXPORT void JNICALL
1010 Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
1011 jstring jalias, jobject jtask,
1014 m_task_t task = jtask_to_native_task(jtask, env);
1019 jxbt_throw_notbound(env, "task", jtask);
1023 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1025 rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
1027 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1029 jxbt_check_res("MSG_task_send_bounded()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT,
1030 bprintf("while sending task %s to mailbox %s with max rate %f", MSG_task_get_name(task),alias,(double)jmaxRate));
1034 JNIEXPORT jobject JNICALL
1035 Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls,
1036 jstring jalias, jdouble jtimeout,
1040 m_task_t task = NULL;
1041 m_host_t host = NULL;
1045 host = jhost_get_native(env, jhost);
1048 jxbt_throw_notbound(env, "host", jhost);
1053 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1055 rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
1057 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1059 jxbt_check_res("MSG_task_receive_ext()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT,
1060 bprintf("while receiving from mailbox %s",alias));
1062 return (jobject) task->data;
1065 JNIEXPORT jboolean JNICALL
1066 Java_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls,
1073 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1075 rv = MSG_task_listen(alias);
1077 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1079 return (jboolean) rv;
1082 JNIEXPORT jint JNICALL
1083 Java_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls,
1084 jstring jalias, jobject jhost)
1089 m_host_t host = jhost_get_native(env, jhost);
1092 jxbt_throw_notbound(env, "host", jhost);
1095 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1097 rv = MSG_task_listen_from_host(alias, host);
1099 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1104 JNIEXPORT jint JNICALL
1105 Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls,
1110 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
1112 rv = MSG_task_listen_from(alias);
1114 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1119 JNIEXPORT void JNICALL
1120 Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
1121 jstring jdeploymentFile)
1124 const char *deploymentFile =
1125 (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
1127 surf_parse_reset_parser();
1129 surfxml_add_callback(STag_surfxml_process_cb_list,
1130 japplication_handler_on_begin_process);
1132 surfxml_add_callback(ETag_surfxml_argument_cb_list,
1133 japplication_handler_on_process_arg);
1135 surfxml_add_callback(STag_surfxml_prop_cb_list,
1136 japplication_handler_on_property);
1138 surfxml_add_callback(ETag_surfxml_process_cb_list,
1139 japplication_handler_on_end_process);
1141 surf_parse_open(deploymentFile);
1143 japplication_handler_on_start_document();
1146 jxbt_throw_jni(env,"surf_parse() failed");
1150 japplication_handler_on_end_document();
1152 (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);