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"
26 #include "msg/mailbox.h"
28 #include "surf/surfxml_parse.h"
31 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
33 static JavaVM *__java_vm = NULL;
35 static jobject native_to_java_process(m_process_t process);
37 JavaVM *get_java_VM(void)
42 JNIEnv *get_current_thread_env(void)
46 (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL);
51 static jobject native_to_java_process(m_process_t process)
53 return ((smx_ctx_java_t)
54 (process->simdata->s_process->context))->jprocess;
59 * The MSG process connected functions implementation.
62 JNIEXPORT void JNICALL
63 Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
64 jobject jprocess_arg, jobject jhost)
66 jobject jprocess; /* the global reference to the java process instance */
67 jstring jname; /* the name of the java process instance */
68 const char *name; /* the C name of the process */
69 m_process_t process; /* the native process to create */
70 char alias[MAX_ALIAS_NAME + 1] = { 0 };
71 msg_mailbox_t mailbox;
74 ("Java_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,jhost=%p)",
75 env, cls, jprocess_arg, jhost);
76 /* get the name of the java process */
77 jname = jprocess_get_name(jprocess_arg, env);
82 ("Internal error: Process name cannot be NULL"));
86 /* allocate the data of the simulation */
87 process = xbt_new0(s_m_process_t, 1);
88 process->simdata = xbt_new0(s_simdata_process_t, 1);
90 /* create a global java process instance */
91 jprocess = jprocess_new_global_ref(jprocess_arg, env);
94 free(process->simdata);
96 jxbt_throw_jni(env, "Can't get a global ref to the java process");
100 /* bind the java process instance to the native process */
101 jprocess_bind(jprocess, process, env);
103 /* build the C name of the process */
104 name = (*env)->GetStringUTFChars(env, jname, 0);
105 process->name = xbt_strdup(name);
106 (*env)->ReleaseStringUTFChars(env, jname, name);
108 process->simdata->m_host = jhost_get_native(env, jhost);
111 if (!(process->simdata->m_host)) { /* not binded */
112 free(process->simdata);
115 jxbt_throw_notbound(env, "host", jhost);
118 process->simdata->PID = msg_global->PID++;
120 /* create a new context */
122 ("fill in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p); env=%p",
123 process->name, process->simdata->m_host->name, process->simdata->PID,
124 process, process->simdata, process->simdata->m_host,
125 process->simdata->m_host->simdata, env);
127 process->simdata->s_process =
128 SIMIX_process_create(process->name, (xbt_main_func_t)jprocess,
129 /*data */ (void *) process,
130 process->simdata->m_host->simdata->smx_host->name,
133 DEBUG1("context created (s_process=%p)", process->simdata->s_process);
136 if (SIMIX_process_self()) { /* someone created me */
137 process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
139 process->simdata->PPID = -1;
142 process->simdata->last_errno = MSG_OK;
144 /* add the process to the list of the processes of the simulation */
145 xbt_fifo_unshift(msg_global->process_list, process);
147 sprintf(alias, "%s:%s", (process->simdata->m_host->simdata->smx_host)->name,
150 mailbox = MSG_mailbox_new(alias);
154 JNIEXPORT void JNICALL
155 Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
158 m_process_t process = jprocess_to_native_process(jprocess, env);
161 jxbt_throw_notbound(env, "process", jprocess);
165 /* try to suspend the process */
166 if (MSG_OK != MSG_process_suspend(process))
167 jxbt_throw_native(env, xbt_strdup("MSG_process_suspend() failed"));
170 JNIEXPORT void JNICALL
171 Java_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
174 m_process_t process = jprocess_to_native_process(jprocess, env);
177 jxbt_throw_notbound(env, "process", jprocess);
181 /* try to resume the process */
182 if (MSG_OK != MSG_process_resume(process))
183 jxbt_throw_native(env, xbt_strdup("MSG_process_resume() failed"));
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_native(env, xbt_strdup("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_native(env, xbt_strdup("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_native(env, xbt_strdup("MSG_process_self() failed"));
306 jprocess = native_to_java_process(process);
309 jxbt_throw_native(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
315 JNIEXPORT jint JNICALL
316 Java_simgrid_msg_MsgNative_processSelfPID(JNIEnv * env, jclass cls)
318 return (jint) MSG_process_self_PID();
322 JNIEXPORT jint JNICALL
323 Java_simgrid_msg_MsgNative_processSelfPPID(JNIEnv * env, jclass cls)
325 return (jint) MSG_process_self_PPID();
328 JNIEXPORT void JNICALL
329 Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv * env, jclass cls,
332 m_host_t host = jhost_get_native(env, jhost);
335 jxbt_throw_notbound(env, "host", jhost);
339 /* try to change the host of the process */
340 if (MSG_OK != MSG_process_change_host(host))
341 jxbt_throw_native(env, xbt_strdup("MSG_process_change_host() failed"));
344 JNIEXPORT void JNICALL
345 Java_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls,
348 if (MSG_OK != MSG_process_sleep((double) seconds))
349 jxbt_throw_native(env,
350 bprintf("MSG_process_change_host(%f) failed",
355 /***************************************************************************************
356 * The MSG host connected functions implementation. *
357 ***************************************************************************************/
359 JNIEXPORT jobject JNICALL
360 Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls,
363 m_host_t host; /* native host */
364 jobject jhost; /* global reference to the java host instance returned */
366 /* get the C string from the java string */
367 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
369 /* get the host by name (the hosts are created during the grid resolution) */
370 host = MSG_get_host_by_name(name);
371 DEBUG2("MSG gave %p as native host (simdata=%p)", host, host->simdata);
373 (*env)->ReleaseStringUTFChars(env, jname, name);
375 if (!host) { /* invalid name */
376 jxbt_throw_host_not_found(env, name);
380 if (!host->data) { /* native host not associated yet with java host */
382 /* instanciate a new java host */
383 jhost = jhost_new_instance(env);
386 jxbt_throw_jni(env, "java host instantiation failed");
390 /* get a global reference to the newly created host */
391 jhost = jhost_ref(env, jhost);
394 jxbt_throw_jni(env, "new global ref allocation failed");
398 /* bind the java host and the native host */
399 jhost_bind(jhost, host, env);
401 /* the native host data field is set with the global reference to the
402 * java host returned by this function
404 host->data = (void *) jhost;
407 /* return the global reference to the java host instance */
408 return (jobject) host->data;
411 JNIEXPORT jstring JNICALL
412 Java_simgrid_msg_MsgNative_hostGetName(JNIEnv * env, jclass cls,
415 m_host_t host = jhost_get_native(env, jhost);
418 jxbt_throw_notbound(env, "host", jhost);
422 return (*env)->NewStringUTF(env, host->name);
425 JNIEXPORT jint JNICALL
426 Java_simgrid_msg_MsgNative_hostGetNumber(JNIEnv * env, jclass cls)
428 return (jint) MSG_get_host_number();
431 JNIEXPORT jobject JNICALL
432 Java_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls)
436 m_host_t host = MSG_host_self();
439 /* the native host not yet associated with the java host instance */
441 /* instanciate a new java host instance */
442 jhost = jhost_new_instance(env);
445 jxbt_throw_jni(env, "java host instantiation failed");
449 /* get a global reference to the newly created host */
450 jhost = jhost_ref(env, jhost);
453 jxbt_throw_jni(env, "global ref allocation failed");
457 /* Bind & store it */
458 jhost_bind(jhost, host, env);
459 host->data = (void *) jhost;
461 jhost = (jobject) host->data;
467 JNIEXPORT jdouble JNICALL
468 Java_simgrid_msg_MsgNative_hostGetSpeed(JNIEnv * env, jclass cls,
471 m_host_t host = jhost_get_native(env, jhost);
474 jxbt_throw_notbound(env, "host", jhost);
478 return (jdouble) MSG_get_host_speed(host);
481 JNIEXPORT jint JNICALL
482 Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
485 m_host_t host = jhost_get_native(env, jhost);
488 jxbt_throw_notbound(env, "host", jhost);
492 return (jint) MSG_get_host_msgload(host);
496 JNIEXPORT jboolean JNICALL
497 Java_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
500 m_host_t host = jhost_get_native(env, jhost);
503 jxbt_throw_notbound(env, "host", jhost);
507 return (jboolean) MSG_host_is_avail(host);
511 /***************************************************************************************
512 * The MSG task connected functions implementation. *
513 ***************************************************************************************/
515 JNIEXPORT void JNICALL
516 Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, jobject jtask,
517 jstring jname, jdouble jcomputeDuration,
518 jdouble jmessageSize)
520 m_task_t task; /* the native task to create */
521 const char *name; /* the name of the task */
523 if (jcomputeDuration < 0) {
524 jxbt_throw_illegal(env,
525 bprintf("Task ComputeDuration (%f) cannot be negative",
526 (double) jcomputeDuration));
530 if (jmessageSize < 0) {
531 jxbt_throw_illegal(env,
532 bprintf("Task MessageSize (%f) cannot be negative",
533 (double) jmessageSize));
538 jxbt_throw_null(env, xbt_strdup("Task name cannot be null"));
542 /* get the C string from the java string */
543 name = (*env)->GetStringUTFChars(env, jname, 0);
545 /* create the task */
547 MSG_task_create(name, (double) jcomputeDuration, (double) jmessageSize,
550 (*env)->ReleaseStringUTFChars(env, jname, name);
552 /* bind & store the task */
553 jtask_bind(jtask, task, env);
555 /* allocate a new global reference to the java task instance */
556 task->data = (void *) jtask_new_global_ref(jtask, env);
559 jxbt_throw_jni(env, "global ref allocation failed");
563 JNIEXPORT void JNICALL
564 Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls,
565 jobject jtask, jstring jname,
568 jcomputeDurations_arg,
569 jdoubleArray jmessageSizes_arg)
572 m_task_t task; /* the native parallel task to create */
573 const char *name; /* the name of the task */
576 double *computeDurations;
577 double *messageSizes;
578 jdouble *jcomputeDurations;
579 jdouble *jmessageSizes;
585 if (!jcomputeDurations_arg) {
588 ("Parallel task compute durations cannot be null"));
592 if (!jmessageSizes_arg) {
594 xbt_strdup("Parallel task message sizes cannot be null"));
599 jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null"));
603 host_count = (int) (*env)->GetArrayLength(env, jhosts);
606 hosts = xbt_new0(m_host_t, host_count);
607 computeDurations = xbt_new0(double, host_count);
608 messageSizes = xbt_new0(double, host_count * host_count);
611 (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0);
612 jmessageSizes = (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0);
614 for (index = 0; index < host_count; index++) {
615 jhost = (*env)->GetObjectArrayElement(env, jhosts, index);
616 hosts[index] = jhost_get_native(env, jhost);
617 computeDurations[index] = jcomputeDurations[index];
619 for (index = 0; index < host_count * host_count; index++) {
620 messageSizes[index] = jmessageSizes[index];
623 (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg,
624 jcomputeDurations, 0);
625 (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes,
629 /* get the C string from the java string */
630 name = (*env)->GetStringUTFChars(env, jname, 0);
633 MSG_parallel_task_create(name, host_count, hosts, computeDurations,
636 (*env)->ReleaseStringUTFChars(env, jname, name);
638 /* associate the java task object and the native task */
639 jtask_bind(jtask, task, env);
641 task->data = (void *) jtask;
644 jxbt_throw_jni(env, "global ref allocation failed");
647 JNIEXPORT jobject JNICALL
648 Java_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls,
653 m_task_t task = jtask_to_native_task(jtask, env);
656 jxbt_throw_notbound(env, "task", jtask);
660 process = MSG_task_get_sender(task);
661 return (jobject) native_to_java_process(process);
664 JNIEXPORT jobject JNICALL
665 Java_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
669 m_task_t task = jtask_to_native_task(jtask, env);
672 jxbt_throw_notbound(env, "task", jtask);
676 host = MSG_task_get_source(task);
679 jxbt_throw_native(env, xbt_strdup("MSG_task_get_source() failed"));
683 return (jobject) host->data;
687 JNIEXPORT jstring JNICALL
688 Java_simgrid_msg_MsgNative_taskGetName(JNIEnv * env, jclass cls,
691 m_task_t task = jtask_to_native_task(jtask, env);
694 jxbt_throw_notbound(env, "task", jtask);
698 return (*env)->NewStringUTF(env, task->name);
701 JNIEXPORT void JNICALL
702 Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask)
704 m_task_t ptask = jtask_to_native_task(jtask, env);
707 jxbt_throw_notbound(env, "task", jtask);
711 if (MSG_OK != MSG_task_cancel(ptask))
712 jxbt_throw_native(env, xbt_strdup("MSG_task_cancel() failed"));
715 JNIEXPORT jdouble JNICALL
716 Java_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls,
719 m_task_t ptask = jtask_to_native_task(jtask, env);
722 jxbt_throw_notbound(env, "task", jtask);
725 return (jdouble) MSG_task_get_compute_duration(ptask);
728 JNIEXPORT jdouble JNICALL
729 Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, jclass cls,
732 m_task_t ptask = jtask_to_native_task(jtask, env);
735 jxbt_throw_notbound(env, "task", jtask);
738 return (jdouble) MSG_task_get_remaining_computation(ptask);
741 JNIEXPORT void JNICALL
742 Java_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls,
743 jobject jtask, jdouble priority)
745 m_task_t task = jtask_to_native_task(jtask, env);
748 jxbt_throw_notbound(env, "task", jtask);
751 MSG_task_set_priority(task, (double) priority);
754 JNIEXPORT void JNICALL
755 Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls,
759 /* get the native task */
760 m_task_t task = jtask_to_native_task(jtask_arg, env);
764 jxbt_throw_notbound(env, "task", task);
767 jtask = (jobject) task->data;
769 if (MSG_OK != MSG_task_destroy(task))
770 jxbt_throw_native(env, xbt_strdup("MSG_task_destroy() failed"));
772 /* delete the global reference to the java task object */
773 jtask_delete_global_ref(jtask, env);
776 JNIEXPORT void JNICALL
777 Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
780 m_task_t task = jtask_to_native_task(jtask, env);
783 jxbt_throw_notbound(env, "task", jtask);
787 if (MSG_OK != MSG_task_execute(task))
788 jxbt_throw_native(env, xbt_strdup("MSG_task_execute() failed"));
791 /***************************************************************************************
792 * Unsortable functions *
793 ***************************************************************************************/
796 JNIEXPORT jint JNICALL
797 Java_simgrid_msg_Msg_getErrCode(JNIEnv * env, jclass cls)
799 return (jint) MSG_get_errno();
802 JNIEXPORT jdouble JNICALL
803 Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
805 return (jdouble) MSG_get_clock();
809 JNIEXPORT void JNICALL
810 Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) {
818 argc = (int) (*env)->GetArrayLength(env, jargs);
821 argv = xbt_new0(char *, argc);
822 argv[0] = strdup("java");
824 for (index = 0; index < argc - 1; index++) {
825 jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index);
826 tmp = (*env)->GetStringUTFChars(env, jval, 0);
827 argv[index + 1] = strdup(tmp);
828 (*env)->ReleaseStringUTFChars(env, jval, tmp);
831 MSG_global_init(&argc, argv);
832 SIMIX_context_select_factory("java");
834 for (index = 0; index < argc; index++)
839 (*env)->GetJavaVM(env, &__java_vm);
842 JNIEXPORT void JNICALL
843 JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) {
844 xbt_fifo_item_t item = NULL;
845 m_host_t host = NULL;
849 if (MSG_OK != MSG_main()) {
850 jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
853 ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
855 DEBUG0("Clean java world");
856 /* Cleanup java hosts */
857 xbt_fifo_foreach(msg_global->host, item, host, m_host_t) {
858 jhost = (jobject) host->data;
861 jhost_unref(env, jhost);
864 DEBUG0("Clean native world");
865 /* cleanup native stuff */
866 if (MSG_OK != MSG_clean()){
867 jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
871 JNIEXPORT jint JNICALL
872 Java_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls,
875 return (jint) MSG_process_killall((int) jresetPID);
878 JNIEXPORT void JNICALL
879 Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
880 jstring jplatformFile)
883 const char *platformFile = (*env)->GetStringUTFChars(env, jplatformFile, 0);
885 MSG_create_environment(platformFile);
887 (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
890 JNIEXPORT void JNICALL
891 Java_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls,
895 m_process_t process = jprocess_to_native_process(jprocess, env);
898 jxbt_throw_notbound(env, "process", jprocess);
902 SIMIX_context_stop(SIMIX_process_self()->context);
905 JNIEXPORT void JNICALL
906 Java_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
908 const char *s = (*env)->GetStringUTFChars(env, js, 0);
910 (*env)->ReleaseStringUTFChars(env, js, s);
913 JNIEXPORT jobjectArray JNICALL
914 Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
922 int count = xbt_fifo_size(msg_global->host);
923 m_host_t *table = (m_host_t *) xbt_fifo_to_array(msg_global->host);
925 jclass cls = jxbt_get_class(env, "simgrid/msg/Host");
931 jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
934 jxbt_throw_jni(env, "Hosts table allocation failed");
938 for (index = 0; index < count; index++) {
940 jhost = (jobject) (host->data);
943 jname = (*env)->NewStringUTF(env, host->name);
945 jhost = Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname);
946 /* FIXME: leak of jname ? */
949 (*env)->SetObjectArrayElement(env, jtable, index, jhost);
956 JNIEXPORT void JNICALL
957 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,
963 /* get the C string from the java string */
964 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
967 SIMIX_context_select_factory(name);
969 errmsg = xbt_strdup(e.msg);
973 (*env)->ReleaseStringUTFChars(env, jname, name);
976 char *thrown = bprintf("xbt_select_context_factory() failed: %s", errmsg);
978 jxbt_throw_native(env, thrown);
982 JNIEXPORT void JNICALL
983 Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
984 jstring jalias, jobject jtask,
989 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
991 m_task_t task = jtask_to_native_task(jtask, env);
995 (*env)->ReleaseStringUTFChars(env, jalias, alias);
996 jxbt_throw_notbound(env, "task", jtask);
1000 rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
1002 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1005 jxbt_throw_native(env, xbt_strdup("MSG_task_send_with_timeout() failed"));
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);
1030 jxbt_throw_native(env, xbt_strdup("MSG_task_send_bounded() failed"));
1033 JNIEXPORT jobject JNICALL
1034 Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls,
1035 jstring jalias, jdouble jtimeout,
1039 m_task_t task = NULL;
1040 m_host_t host = NULL;
1044 host = jhost_get_native(env, jhost);
1047 jxbt_throw_notbound(env, "host", jhost);
1052 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1054 rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
1056 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1059 jxbt_throw_native(env, xbt_strdup("MSG_task_receive_ext() failed"));
1063 return (jobject) task->data;
1066 JNIEXPORT jboolean JNICALL
1067 Java_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls,
1074 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1076 rv = MSG_task_listen(alias);
1078 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1080 return (jboolean) rv;
1083 JNIEXPORT jint JNICALL
1084 Java_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls,
1085 jstring jalias, jobject jhost)
1091 m_host_t host = jhost_get_native(env, jhost);
1094 jxbt_throw_notbound(env, "host", jhost);
1098 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1100 rv = MSG_task_listen_from_host(alias, host);
1102 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1107 JNIEXPORT jint JNICALL
1108 Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls,
1113 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
1115 rv = MSG_task_listen_from(alias);
1117 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1122 JNIEXPORT void JNICALL
1123 Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
1124 jstring jdeploymentFile)
1127 const char *deploymentFile =
1128 (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
1130 surf_parse_reset_parser();
1132 surfxml_add_callback(STag_surfxml_process_cb_list,
1133 japplication_handler_on_begin_process);
1135 surfxml_add_callback(ETag_surfxml_argument_cb_list,
1136 japplication_handler_on_process_arg);
1138 surfxml_add_callback(STag_surfxml_prop_cb_list,
1139 japplication_handler_on_property);
1141 surfxml_add_callback(ETag_surfxml_process_cb_list,
1142 japplication_handler_on_end_process);
1144 surf_parse_open(deploymentFile);
1146 japplication_handler_on_start_document();
1149 jxbt_throw_native(env, xbt_strdup("surf_parse() failed"));
1153 japplication_handler_on_end_document();
1155 (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);