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=NULL; /* 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 /* get the C string from the java string */
539 name = (*env)->GetStringUTFChars(env, jname, 0);
543 /* create the task */
545 MSG_task_create(name, (double) jcomputeDuration, (double) jmessageSize,
549 (*env)->ReleaseStringUTFChars(env, jname, name);
551 /* bind & store the task */
552 jtask_bind(jtask, task, env);
554 /* allocate a new global reference to the java task instance */
555 task->data = (void *) jtask_new_global_ref(jtask, env);
558 jxbt_throw_jni(env, "global ref allocation failed");
562 JNIEXPORT void JNICALL
563 Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls,
564 jobject jtask, jstring jname,
567 jcomputeDurations_arg,
568 jdoubleArray jmessageSizes_arg)
571 m_task_t task; /* the native parallel task to create */
572 const char *name; /* the name of the task */
575 double *computeDurations;
576 double *messageSizes;
577 jdouble *jcomputeDurations;
578 jdouble *jmessageSizes;
584 if (!jcomputeDurations_arg) {
587 ("Parallel task compute durations cannot be null"));
591 if (!jmessageSizes_arg) {
593 xbt_strdup("Parallel task message sizes cannot be null"));
598 jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null"));
602 host_count = (int) (*env)->GetArrayLength(env, jhosts);
605 hosts = xbt_new0(m_host_t, host_count);
606 computeDurations = xbt_new0(double, host_count);
607 messageSizes = xbt_new0(double, host_count * host_count);
610 (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0);
611 jmessageSizes = (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0);
613 for (index = 0; index < host_count; index++) {
614 jhost = (*env)->GetObjectArrayElement(env, jhosts, index);
615 hosts[index] = jhost_get_native(env, jhost);
616 computeDurations[index] = jcomputeDurations[index];
618 for (index = 0; index < host_count * host_count; index++) {
619 messageSizes[index] = jmessageSizes[index];
622 (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg,
623 jcomputeDurations, 0);
624 (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes,
628 /* get the C string from the java string */
629 name = (*env)->GetStringUTFChars(env, jname, 0);
632 MSG_parallel_task_create(name, host_count, hosts, computeDurations,
635 (*env)->ReleaseStringUTFChars(env, jname, name);
637 /* associate the java task object and the native task */
638 jtask_bind(jtask, task, env);
640 task->data = (void *) jtask;
643 jxbt_throw_jni(env, "global ref allocation failed");
646 JNIEXPORT jobject JNICALL
647 Java_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls,
652 m_task_t task = jtask_to_native_task(jtask, env);
655 jxbt_throw_notbound(env, "task", jtask);
659 process = MSG_task_get_sender(task);
660 return (jobject) native_to_java_process(process);
663 JNIEXPORT jobject JNICALL
664 Java_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
668 m_task_t task = jtask_to_native_task(jtask, env);
671 jxbt_throw_notbound(env, "task", jtask);
675 host = MSG_task_get_source(task);
678 jxbt_throw_native(env, xbt_strdup("MSG_task_get_source() failed"));
682 return (jobject) host->data;
686 JNIEXPORT jstring JNICALL
687 Java_simgrid_msg_MsgNative_taskGetName(JNIEnv * env, jclass cls,
690 m_task_t task = jtask_to_native_task(jtask, env);
693 jxbt_throw_notbound(env, "task", jtask);
697 return (*env)->NewStringUTF(env, task->name);
700 JNIEXPORT void JNICALL
701 Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask)
703 m_task_t ptask = jtask_to_native_task(jtask, env);
706 jxbt_throw_notbound(env, "task", jtask);
710 if (MSG_OK != MSG_task_cancel(ptask))
711 jxbt_throw_native(env, xbt_strdup("MSG_task_cancel() failed"));
714 JNIEXPORT jdouble JNICALL
715 Java_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls,
718 m_task_t ptask = jtask_to_native_task(jtask, env);
721 jxbt_throw_notbound(env, "task", jtask);
724 return (jdouble) MSG_task_get_compute_duration(ptask);
727 JNIEXPORT jdouble JNICALL
728 Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, jclass cls,
731 m_task_t ptask = jtask_to_native_task(jtask, env);
734 jxbt_throw_notbound(env, "task", jtask);
737 return (jdouble) MSG_task_get_remaining_computation(ptask);
740 JNIEXPORT void JNICALL
741 Java_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls,
742 jobject jtask, jdouble priority)
744 m_task_t task = jtask_to_native_task(jtask, env);
747 jxbt_throw_notbound(env, "task", jtask);
750 MSG_task_set_priority(task, (double) priority);
753 JNIEXPORT void JNICALL
754 Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls,
758 /* get the native task */
759 m_task_t task = jtask_to_native_task(jtask_arg, env);
763 jxbt_throw_notbound(env, "task", task);
766 jtask = (jobject) task->data;
768 if (MSG_OK != MSG_task_destroy(task))
769 jxbt_throw_native(env, xbt_strdup("MSG_task_destroy() failed"));
771 /* delete the global reference to the java task object */
772 jtask_delete_global_ref(jtask, env);
775 JNIEXPORT void JNICALL
776 Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
779 m_task_t task = jtask_to_native_task(jtask, env);
782 jxbt_throw_notbound(env, "task", jtask);
786 if (MSG_OK != MSG_task_execute(task))
787 jxbt_throw_native(env, xbt_strdup("MSG_task_execute() failed"));
790 /***************************************************************************************
791 * Unsortable functions *
792 ***************************************************************************************/
795 JNIEXPORT jint JNICALL
796 Java_simgrid_msg_Msg_getErrCode(JNIEnv * env, jclass cls)
798 return (jint) MSG_get_errno();
801 JNIEXPORT jdouble JNICALL
802 Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
804 return (jdouble) MSG_get_clock();
808 JNIEXPORT void JNICALL
809 Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) {
817 argc = (int) (*env)->GetArrayLength(env, jargs);
820 argv = xbt_new0(char *, argc);
821 argv[0] = strdup("java");
823 for (index = 0; index < argc - 1; index++) {
824 jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index);
825 tmp = (*env)->GetStringUTFChars(env, jval, 0);
826 argv[index + 1] = strdup(tmp);
827 (*env)->ReleaseStringUTFChars(env, jval, tmp);
830 MSG_global_init(&argc, argv);
831 SIMIX_context_select_factory("java");
833 for (index = 0; index < argc; index++)
838 (*env)->GetJavaVM(env, &__java_vm);
841 JNIEXPORT void JNICALL
842 JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) {
843 xbt_fifo_item_t item = NULL;
844 m_host_t host = NULL;
848 if (MSG_OK != MSG_main()) {
849 jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
852 ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
854 DEBUG0("Clean java world");
855 /* Cleanup java hosts */
856 xbt_fifo_foreach(msg_global->host, item, host, m_host_t) {
857 jhost = (jobject) host->data;
860 jhost_unref(env, jhost);
863 DEBUG0("Clean native world");
864 /* cleanup native stuff */
865 if (MSG_OK != MSG_clean()){
866 jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
870 JNIEXPORT jint JNICALL
871 Java_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls,
874 return (jint) MSG_process_killall((int) jresetPID);
877 JNIEXPORT void JNICALL
878 Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
879 jstring jplatformFile)
882 const char *platformFile = (*env)->GetStringUTFChars(env, jplatformFile, 0);
884 MSG_create_environment(platformFile);
886 (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
889 JNIEXPORT void JNICALL
890 Java_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls,
894 m_process_t process = jprocess_to_native_process(jprocess, env);
897 jxbt_throw_notbound(env, "process", jprocess);
901 SIMIX_context_stop(SIMIX_process_self()->context);
904 JNIEXPORT void JNICALL
905 Java_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
907 const char *s = (*env)->GetStringUTFChars(env, js, 0);
909 (*env)->ReleaseStringUTFChars(env, js, s);
912 JNIEXPORT jobjectArray JNICALL
913 Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
921 int count = xbt_fifo_size(msg_global->host);
922 m_host_t *table = (m_host_t *) xbt_fifo_to_array(msg_global->host);
924 jclass cls = jxbt_get_class(env, "simgrid/msg/Host");
930 jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
933 jxbt_throw_jni(env, "Hosts table allocation failed");
937 for (index = 0; index < count; index++) {
939 jhost = (jobject) (host->data);
942 jname = (*env)->NewStringUTF(env, host->name);
944 jhost = Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname);
945 /* FIXME: leak of jname ? */
948 (*env)->SetObjectArrayElement(env, jtable, index, jhost);
955 JNIEXPORT void JNICALL
956 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,
962 /* get the C string from the java string */
963 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
966 SIMIX_context_select_factory(name);
968 errmsg = xbt_strdup(e.msg);
972 (*env)->ReleaseStringUTFChars(env, jname, name);
975 char *thrown = bprintf("xbt_select_context_factory() failed: %s", errmsg);
977 jxbt_throw_native(env, thrown);
981 JNIEXPORT void JNICALL
982 Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
983 jstring jalias, jobject jtask,
988 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
990 m_task_t task = jtask_to_native_task(jtask, env);
994 (*env)->ReleaseStringUTFChars(env, jalias, alias);
995 jxbt_throw_notbound(env, "task", jtask);
999 rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
1001 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1004 jxbt_throw_native(env, xbt_strdup("MSG_task_send_with_timeout() failed"));
1008 JNIEXPORT void JNICALL
1009 Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
1010 jstring jalias, jobject jtask,
1013 m_task_t task = jtask_to_native_task(jtask, env);
1018 jxbt_throw_notbound(env, "task", jtask);
1022 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1024 rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
1026 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1029 jxbt_throw_native(env, xbt_strdup("MSG_task_send_bounded() failed"));
1032 JNIEXPORT jobject JNICALL
1033 Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls,
1034 jstring jalias, jdouble jtimeout,
1038 m_task_t task = NULL;
1039 m_host_t host = NULL;
1043 host = jhost_get_native(env, jhost);
1046 jxbt_throw_notbound(env, "host", jhost);
1051 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1053 rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
1055 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1058 jxbt_throw_native(env, xbt_strdup("MSG_task_receive_ext() failed"));
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)
1090 m_host_t host = jhost_get_native(env, jhost);
1093 jxbt_throw_notbound(env, "host", jhost);
1097 alias = (*env)->GetStringUTFChars(env, jalias, 0);
1099 rv = MSG_task_listen_from_host(alias, host);
1101 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1106 JNIEXPORT jint JNICALL
1107 Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls,
1112 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
1114 rv = MSG_task_listen_from(alias);
1116 (*env)->ReleaseStringUTFChars(env, jalias, alias);
1121 JNIEXPORT void JNICALL
1122 Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
1123 jstring jdeploymentFile)
1126 const char *deploymentFile =
1127 (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
1129 surf_parse_reset_parser();
1131 surfxml_add_callback(STag_surfxml_process_cb_list,
1132 japplication_handler_on_begin_process);
1134 surfxml_add_callback(ETag_surfxml_argument_cb_list,
1135 japplication_handler_on_process_arg);
1137 surfxml_add_callback(STag_surfxml_prop_cb_list,
1138 japplication_handler_on_property);
1140 surfxml_add_callback(ETag_surfxml_process_cb_list,
1141 japplication_handler_on_end_process);
1143 surf_parse_open(deploymentFile);
1145 japplication_handler_on_start_document();
1148 jxbt_throw_native(env, xbt_strdup("surf_parse() failed"));
1152 japplication_handler_on_end_document();
1154 (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);