1 /* Java Wrappers to the MSG API. */
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights 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. */
10 #include <simgrid/simix.h>
11 #include <surf/surfxml_parse.h>
14 #include "smx_context_java.h"
16 #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"
25 /* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */
32 /* end of eclipse-mandated pimple */
34 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
36 static JavaVM *__java_vm = NULL;
39 JavaVM *get_java_VM(void)
44 JNIEnv *get_current_thread_env(void)
48 (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL);
54 * The MSG process connected functions implementation.
57 JNIEXPORT void JNICALL
58 Java_org_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
64 jobject jprocess; /* the global reference to the java process instance */
65 jstring jname; /* the name of the java process instance */
66 const char *name; /* the C name of the process */
68 m_process_t process; /* the native process to create */
69 m_host_t host; /* Where that process lives */
71 hostname = (*env)->GetStringUTFChars(env, jhostname, 0);
73 XBT_DEBUG("Java_org_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,host=%s)",
74 env, cls, jprocess_arg, hostname);
77 /* get the name of the java process */
78 jname = jprocess_get_name(jprocess_arg, env);
81 xbt_strdup("Internal error: Process name cannot be NULL"));
85 /* bind/retrieve the msg host */
86 host = MSG_get_host_by_name(hostname);
88 if (!(host)) { /* not binded */
89 jxbt_throw_host_not_found(env, hostname);
93 /* create a global java process instance */
94 jprocess = jprocess_new_global_ref(jprocess_arg, env);
96 jxbt_throw_jni(env, "Can't get a global ref to the java process");
100 /* build the C name of the process */
101 name = (*env)->GetStringUTFChars(env, jname, 0);
102 name = xbt_strdup(name);
104 /* Actually build the MSG process */
105 process = MSG_process_create_with_environment(name,
106 (xbt_main_func_t) jprocess,
110 /*argc, argv, properties*/
113 MSG_process_set_data(process,&process);
115 /* release our reference to the process name (variable name becomes invalid) */
116 //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING
117 //(*env)->ReleaseStringUTFChars(env, jname, name);
118 (*env)->ReleaseStringUTFChars(env, jhostname, hostname);
120 /* bind the java process instance to the native process */
121 jprocess_bind(jprocess, process, env);
125 JNIEXPORT void JNICALL
126 Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
129 m_process_t process = jprocess_to_native_process(jprocess, env);
132 jxbt_throw_notbound(env, "process", jprocess);
136 /* try to suspend the process */
137 MSG_error_t rv = MSG_process_suspend(process);
139 jxbt_check_res("MSG_process_suspend()", rv, MSG_OK,
140 bprintf("unexpected error , please report this bug"));
144 JNIEXPORT void JNICALL
145 Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jobject jprocess,
147 m_process_t process = jprocess_to_native_process(jprocess, env);
150 jxbt_throw_notbound(env, "process", jprocess);
153 MSG_error_t rv = MSG_process_sleep((double)jseconds);
155 jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
156 bprintf("unexpected error , please report this bug"));
160 JNIEXPORT void JNICALL
161 Java_org_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
164 m_process_t process = jprocess_to_native_process(jprocess, env);
167 jxbt_throw_notbound(env, "process", jprocess);
171 /* try to resume the process */
172 MSG_error_t rv = MSG_process_resume(process);
174 jxbt_check_res("MSG_process_resume()", rv, MSG_OK,
175 bprintf("unexpected error , please report this bug"));
178 JNIEXPORT jboolean JNICALL
179 Java_org_simgrid_msg_MsgNative_processIsSuspended(JNIEnv * env, jclass cls,
182 m_process_t process = jprocess_to_native_process(jprocess, env);
185 jxbt_throw_notbound(env, "process", jprocess);
189 /* true is the process is suspended, false otherwise */
190 return (jboolean) MSG_process_is_suspended(process);
193 JNIEXPORT void JNICALL
194 Java_org_simgrid_msg_MsgNative_processKill(JNIEnv * env, jclass cls,
197 /* get the native instances from the java ones */
198 m_process_t process = jprocess_to_native_process(jprocess, env);
201 jxbt_throw_notbound(env, "process", jprocess);
205 /* kill the native process (this wrapper is call by the destructor of the java
208 MSG_process_kill(process);
211 JNIEXPORT jobject JNICALL
212 Java_org_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls,
215 /* get the native instances from the java ones */
216 m_process_t process = jprocess_to_native_process(jprocess, env);
220 jxbt_throw_notbound(env, "process", jprocess);
224 host = MSG_process_get_host(process);
225 jobject res = (jobject)MSG_host_get_data(host);
228 XBT_INFO("Binding error for host %s ",MSG_host_get_name(host));
229 jxbt_throw_jni(env, bprintf("Binding error for host %s ",MSG_host_get_name(host)));
233 /* return the global reference to the java host instance */
238 JNIEXPORT jobject JNICALL
239 Java_org_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls,
242 m_process_t process = MSG_process_from_PID(PID);
245 jxbt_throw_process_not_found(env, bprintf("PID = %d",(int) PID));
249 if (!native_to_java_process(process)) {
250 jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
254 return (jobject) (native_to_java_process(process));
258 JNIEXPORT jint JNICALL
259 Java_org_simgrid_msg_MsgNative_processGetPID(JNIEnv * env, jclass cls,
262 m_process_t process = jprocess_to_native_process(jprocess, env);
265 jxbt_throw_notbound(env, "process", jprocess);
269 return (jint) MSG_process_get_PID(process);
273 JNIEXPORT jint JNICALL
274 Java_org_simgrid_msg_MsgNative_processGetPPID(JNIEnv * env, jclass cls,
277 m_process_t process = jprocess_to_native_process(jprocess, env);
280 jxbt_throw_notbound(env, "process", jprocess);
284 return (jint) MSG_process_get_PPID(process);
287 JNIEXPORT jobject JNICALL
288 Java_org_simgrid_msg_MsgNative_processSelf(JNIEnv * env, jclass cls)
290 m_process_t process = MSG_process_self();
294 jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed"));
298 jprocess = native_to_java_process(process);
301 jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
306 JNIEXPORT void JNICALL
307 Java_org_simgrid_msg_MsgNative_processMigrate(JNIEnv * env, jclass cls,
308 jobject jprocess, jobject jhost)
310 m_process_t process = jprocess_to_native_process(jprocess, env);
313 jxbt_throw_notbound(env, "process", jprocess);
317 m_host_t host = jhost_get_native(env, jhost);
320 jxbt_throw_notbound(env, "host", jhost);
324 /* try to change the host of the process */
325 MSG_error_t rv = MSG_process_migrate(process, host);
326 jxbt_check_res("MSG_process_migrate()", rv, MSG_OK,
327 bprintf("unexpected error , please report this bug"));
331 JNIEXPORT void JNICALL
332 Java_org_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls,
335 MSG_error_t rv = MSG_process_sleep((double) seconds);
337 jxbt_check_res("MSG_process_sleep()", rv, MSG_HOST_FAILURE,
338 bprintf("while process was waiting for %f seconds",
344 /***************************************************************************************
345 * The MSG host connected functions implementation. *
346 ***************************************************************************************/
348 JNIEXPORT jobject JNICALL
349 Java_org_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls,
352 m_host_t host; /* native host */
353 jobject jhost; /* global reference to the java host instance returned */
355 /* get the C string from the java string */
356 const char *name = (*env)->GetStringUTFChars(env, jname, 0);
357 XBT_DEBUG("Looking for host '%s'",name);
358 /* get the host by name (the hosts are created during the grid resolution) */
359 host = MSG_get_host_by_name(name);
360 XBT_DEBUG("MSG gave %p as native host", host);
362 if (!host) { /* invalid name */
363 jxbt_throw_host_not_found(env, name);
364 (*env)->ReleaseStringUTFChars(env, jname, name);
367 (*env)->ReleaseStringUTFChars(env, jname, name);
369 if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */
371 /* Instantiate a new java host */
372 jhost = jhost_new_instance(env);
375 jxbt_throw_jni(env, "java host instantiation failed");
379 /* get a global reference to the newly created host */
380 jhost = jhost_ref(env, jhost);
383 jxbt_throw_jni(env, "new global ref allocation failed");
387 /* bind the java host and the native host */
388 jhost_bind(jhost, host, env);
390 /* the native host data field is set with the global reference to the
391 * java host returned by this function
393 MSG_host_set_data(host, (void *) jhost);
396 /* return the global reference to the java host instance */
397 return (jobject) MSG_host_get_data(host);
400 JNIEXPORT jstring JNICALL
401 Java_org_simgrid_msg_MsgNative_hostGetName(JNIEnv * env, jclass cls,
404 m_host_t host = jhost_get_native(env, jhost);
408 jxbt_throw_notbound(env, "host", jhost);
412 name = MSG_host_get_name(host);
414 xbt_die("This host has no name...");
416 return (*env)->NewStringUTF(env, name);
419 JNIEXPORT jint JNICALL
420 Java_org_simgrid_msg_MsgNative_hostGetNumber(JNIEnv * env, jclass cls)
422 xbt_dynar_t hosts = MSG_hosts_as_dynar();
423 int nb_host = xbt_dynar_length(hosts);
424 xbt_dynar_free(&hosts);
425 return (jint) nb_host;
428 JNIEXPORT jobject JNICALL
429 Java_org_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls)
433 m_host_t host = MSG_host_self();
435 if (!MSG_host_get_data(host)) {
436 /* the native host not yet associated with the java host instance */
438 /* instanciate a new java host instance */
439 jhost = jhost_new_instance(env);
442 jxbt_throw_jni(env, "java host instantiation failed");
446 /* get a global reference to the newly created host */
447 jhost = jhost_ref(env, jhost);
450 jxbt_throw_jni(env, "global ref allocation failed");
454 /* Bind & store it */
455 jhost_bind(jhost, host, env);
456 MSG_host_set_data(host, (void *) jhost);
458 jhost = (jobject) MSG_host_get_data(host);
464 JNIEXPORT jdouble JNICALL
465 Java_org_simgrid_msg_MsgNative_hostGetSpeed(JNIEnv * env, jclass cls,
468 m_host_t host = jhost_get_native(env, jhost);
471 jxbt_throw_notbound(env, "host", jhost);
475 return (jdouble) MSG_get_host_speed(host);
478 JNIEXPORT jint JNICALL
479 Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
482 m_host_t host = jhost_get_native(env, jhost);
485 jxbt_throw_notbound(env, "host", jhost);
489 return (jint) MSG_get_host_msgload(host);
493 JNIEXPORT jboolean JNICALL
494 Java_org_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
497 m_host_t host = jhost_get_native(env, jhost);
500 jxbt_throw_notbound(env, "host", jhost);
504 return (jboolean) MSG_host_is_avail(host);
508 /***************************************************************************************
509 * The MSG task connected functions implementation. *
510 ***************************************************************************************/
512 JNIEXPORT jobject JNICALL
513 Java_org_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
517 m_task_t task = jtask_to_native_task(jtask, env);
520 jxbt_throw_notbound(env, "task", jtask);
524 host = MSG_task_get_source(task);
526 if (!MSG_host_get_data(host)) {
527 jxbt_throw_jni(env, "MSG_task_get_source() failed");
531 return (jobject) MSG_host_get_data(host);
534 JNIEXPORT void JNICALL
535 Java_org_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls,
538 m_task_t ptask = jtask_to_native_task(jtask, env);
541 jxbt_throw_notbound(env, "task", jtask);
545 MSG_error_t rv = MSG_task_cancel(ptask);
547 jxbt_check_res("MSG_task_cancel()", rv, MSG_OK,
548 bprintf("unexpected error , please report this bug"));
551 JNIEXPORT jdouble JNICALL
552 Java_org_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls,
555 m_task_t ptask = jtask_to_native_task(jtask, env);
558 jxbt_throw_notbound(env, "task", jtask);
561 return (jdouble) MSG_task_get_compute_duration(ptask);
564 JNIEXPORT jdouble JNICALL
565 Java_org_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env,
569 m_task_t ptask = jtask_to_native_task(jtask, env);
572 jxbt_throw_notbound(env, "task", jtask);
575 return (jdouble) MSG_task_get_remaining_computation(ptask);
578 JNIEXPORT void JNICALL
579 Java_org_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls,
580 jobject jtask, jdouble priority)
582 m_task_t task = jtask_to_native_task(jtask, env);
585 jxbt_throw_notbound(env, "task", jtask);
588 MSG_task_set_priority(task, (double) priority);
591 JNIEXPORT void JNICALL
592 Java_org_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
595 m_task_t task = jtask_to_native_task(jtask, env);
598 jxbt_throw_notbound(env, "task", jtask);
602 MSG_error_t rv = MSG_task_execute(task);
604 jxbt_check_res("MSG_task_execute()", rv,
605 MSG_HOST_FAILURE | MSG_TASK_CANCELED,
606 bprintf("while executing task %s",
607 MSG_task_get_name(task)));
610 /***************************************************************************************
611 * Unsortable functions *
612 ***************************************************************************************/
614 JNIEXPORT jdouble JNICALL
615 Java_org_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
617 return (jdouble) MSG_get_clock();
620 JNIEXPORT void JNICALL
621 Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs)
629 smx_factory_initializer_to_use = SIMIX_ctx_java_factory_init;
632 argc = (int) (*env)->GetArrayLength(env, jargs);
635 argv = xbt_new(char *, argc + 1);
636 argv[0] = strdup("java");
638 for (index = 0; index < argc - 1; index++) {
639 jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index);
640 tmp = (*env)->GetStringUTFChars(env, jval, 0);
641 argv[index + 1] = strdup(tmp);
642 (*env)->ReleaseStringUTFChars(env, jval, tmp);
646 MSG_global_init(&argc, argv);
648 for (index = 0; index < argc; index++)
653 (*env)->GetJavaVM(env, &__java_vm);
656 JNIEXPORT void JNICALL
657 JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls)
665 XBT_INFO("Ready to run MSG_MAIN");
667 XBT_INFO("Done running MSG_MAIN");
668 jxbt_check_res("MSG_main()", rv, MSG_OK,
670 ("unexpected error : MSG_main() failed .. please report this bug "));
672 XBT_INFO("MSG_main finished");
674 XBT_INFO("Clean java world");
675 /* Cleanup java hosts */
676 hosts = MSG_hosts_as_dynar();
677 for (index = 0; index < xbt_dynar_length(hosts) - 1; index++) {
678 jhost = (jobject) MSG_host_get_data(xbt_dynar_get_as(hosts,index,m_host_t));
680 jhost_unref(env, jhost);
683 xbt_dynar_free(&hosts);
684 XBT_INFO("Clean native world");
686 JNIEXPORT void JNICALL
687 JNICALL Java_org_simgrid_msg_Msg_clean(JNIEnv * env, jclass cls)
689 /* cleanup native stuff. Calling it is ... useless since leaking memory at the end of the simulation is a non-issue */
690 MSG_error_t rv = MSG_OK != MSG_clean();
691 jxbt_check_res("MSG_clean()", rv, MSG_OK,
693 ("unexpected error : MSG_clean() failed .. please report this bug "));
696 JNIEXPORT jint JNICALL
697 Java_org_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls,
700 return (jint) MSG_process_killall((int) jresetPID);
703 JNIEXPORT void JNICALL
704 Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
705 jstring jplatformFile)
708 const char *platformFile =
709 (*env)->GetStringUTFChars(env, jplatformFile, 0);
711 MSG_create_environment(platformFile);
713 (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
716 JNIEXPORT void JNICALL
717 Java_org_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls,
721 m_process_t process = jprocess_to_native_process(jprocess, env);
724 jxbt_throw_notbound(env, "process", jprocess);
728 smx_ctx_java_stop(MSG_process_get_smx_ctx(process));
731 JNIEXPORT void JNICALL
732 Java_org_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
734 const char *s = (*env)->GetStringUTFChars(env, js, 0);
736 (*env)->ReleaseStringUTFChars(env, js, s);
739 JNIEXPORT jobjectArray JNICALL
740 Java_org_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
748 xbt_dynar_t table = MSG_hosts_as_dynar();
749 int count = xbt_dynar_length(table);
751 jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
757 jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
760 jxbt_throw_jni(env, "Hosts table allocation failed");
764 for (index = 0; index < count; index++) {
765 host = xbt_dynar_get_as(table,index,m_host_t);
766 jhost = (jobject) (MSG_host_get_data(host));
769 jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));
772 Java_org_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname);
773 /* FIXME: leak of jname ? */
776 (*env)->SetObjectArrayElement(env, jtable, index, jhost);
778 xbt_dynar_free(&table);
782 JNIEXPORT void JNICALL
783 Java_org_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
784 jstring jalias, jobject jtask,
789 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
791 m_task_t task = jtask_to_native_task(jtask, env);
795 (*env)->ReleaseStringUTFChars(env, jalias, alias);
796 jxbt_throw_notbound(env, "task", jtask);
800 /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
801 MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
802 rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
804 (*env)->ReleaseStringUTFChars(env, jalias, alias);
806 jxbt_check_res("MSG_task_send_with_timeout()", rv,
807 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
808 bprintf("while sending task %s to mailbox %s",
809 MSG_task_get_name(task), alias));
812 static void msg_task_cancel_on_failed_dsend(void*t) {
814 JNIEnv *env =get_current_thread_env();
815 jobject jtask_global = MSG_task_get_data(task);
817 /* Destroy the global ref so that the JVM can free the stuff */
818 (*env)->DeleteGlobalRef(env, jtask_global);
819 MSG_task_set_data(task, NULL);
820 MSG_task_destroy(task);
824 JNIEXPORT void JNICALL
825 Java_org_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
826 jstring jalias, jobject jtask,
829 m_task_t task = jtask_to_native_task(jtask, env);
834 jxbt_throw_notbound(env, "task", jtask);
838 alias = (*env)->GetStringUTFChars(env, jalias, 0);
840 /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
841 MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
842 rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
844 (*env)->ReleaseStringUTFChars(env, jalias, alias);
846 jxbt_check_res("MSG_task_send_bounded()", rv,
847 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
849 ("while sending task %s to mailbox %s with max rate %f",
850 MSG_task_get_name(task), alias, (double) jmaxRate));
854 JNIEXPORT jobject JNICALL
855 Java_org_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls,
856 jstring jalias, jdouble jtimeout,
860 m_task_t task = NULL;
861 m_host_t host = NULL;
862 jobject jtask_global, jtask_local;
866 host = jhost_get_native(env, jhost);
869 jxbt_throw_notbound(env, "host", jhost);
874 alias = (*env)->GetStringUTFChars(env, jalias, 0);
876 rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
880 jxbt_throw_time_out_failure(env,NULL);
882 case MSG_TRANSFER_FAILURE:
883 jxbt_throw_transfer_failure(env,NULL);
885 case MSG_HOST_FAILURE:
886 jxbt_throw_host_failure(env,NULL);
889 jxbt_throw_native(env,bprintf("receive failed"));
893 jtask_global = MSG_task_get_data(task);
895 /* Convert the global ref into a local ref so that the JVM can free the stuff */
896 jtask_local = (*env)->NewLocalRef(env, jtask_global);
897 (*env)->DeleteGlobalRef(env, jtask_global);
898 MSG_task_set_data(task, NULL);
900 (*env)->ReleaseStringUTFChars(env, jalias, alias);
902 jxbt_check_res("MSG_task_receive_ext()", rv,
903 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
904 bprintf("while receiving from mailbox %s", alias));
906 return (jobject) jtask_local;
909 JNIEXPORT jboolean JNICALL
910 Java_org_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls,
917 alias = (*env)->GetStringUTFChars(env, jalias, 0);
919 rv = MSG_task_listen(alias);
921 (*env)->ReleaseStringUTFChars(env, jalias, alias);
923 return (jboolean) rv;
926 JNIEXPORT jint JNICALL
927 Java_org_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls,
934 m_host_t host = jhost_get_native(env, jhost);
937 jxbt_throw_notbound(env, "host", jhost);
940 alias = (*env)->GetStringUTFChars(env, jalias, 0);
942 rv = MSG_task_listen_from_host(alias, host);
944 (*env)->ReleaseStringUTFChars(env, jalias, alias);
949 JNIEXPORT jint JNICALL
950 Java_org_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls,
955 const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
957 rv = MSG_task_listen_from(alias);
959 (*env)->ReleaseStringUTFChars(env, jalias, alias);
964 JNIEXPORT void JNICALL
965 Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
966 jstring jdeploymentFile)
969 const char *deploymentFile =
970 (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
972 surf_parse_reset_callbacks();
974 surfxml_add_callback(STag_surfxml_process_cb_list,
975 japplication_handler_on_begin_process);
977 surfxml_add_callback(ETag_surfxml_argument_cb_list,
978 japplication_handler_on_process_arg);
980 surfxml_add_callback(STag_surfxml_prop_cb_list,
981 japplication_handler_on_property);
983 surfxml_add_callback(ETag_surfxml_process_cb_list,
984 japplication_handler_on_end_process);
986 surf_parse_open(deploymentFile);
988 japplication_handler_on_start_document();
991 jxbt_throw_jni(env, "surf_parse() failed");
995 japplication_handler_on_end_document();
997 (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);