X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1142f033583856ab639da863de9e4d0ac6db188b..ffe8ce65fd9a8e18a0469f26f067c3ea6d5d60d4:/src/bindings/java/jmsg.c diff --git a/src/bindings/java/jmsg.c b/src/bindings/java/jmsg.c index b3ec27cd41..c11ba91e7b 100644 --- a/src/bindings/java/jmsg.c +++ b/src/bindings/java/jmsg.c @@ -19,6 +19,7 @@ #include "jmsg_as.h" #include "jmsg_host.h" +#include "jmsg_storage.h" #include "jmsg_task.h" #include "jxbt_utilities.h" @@ -33,6 +34,9 @@ #endif /* end of eclipse-mandated pimple */ +int JAVA_HOST_LEVEL; +int JAVA_STORAGE_LEVEL; + static int create_jprocess(int argc, char *argv[]); XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); @@ -63,8 +67,11 @@ void jmsg_throw_status(JNIEnv *env, msg_error_t status) { case MSG_HOST_FAILURE: jxbt_throw_host_failure(env,NULL); break; + case MSG_TASK_CANCELED: + jxbt_throw_task_cancelled(env,NULL); + break; default: - jxbt_throw_native(env,xbt_strdup("communication failed")); + jxbt_throw_native(env,xbt_strdup("undefined message failed (please see jmsg_throw_status function in jmsg.c)")); } } @@ -79,6 +86,14 @@ Java_org_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) return (jdouble) MSG_get_clock(); } +static void __JAVA_host_priv_free(void *host) +{ +} + +static void __JAVA_storage_priv_free(void *storage) +{ +} + JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) { @@ -123,6 +138,9 @@ Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) MSG_init(&argc, argv); + JAVA_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __JAVA_host_priv_free); + JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, (void_f_pvoid_t) __JAVA_storage_priv_free); + for (index = 0; index < argc; index++) free(argv[index]); @@ -141,8 +159,9 @@ JNIEXPORT void JNICALL { msg_error_t rv; int index; - xbt_dynar_t hosts; - jobject jhost; + xbt_dynar_t hosts, storages; + jobject jhost, jstorage; + /* Run everything */ XBT_DEBUG("Ready to run MSG_MAIN"); @@ -155,12 +174,24 @@ JNIEXPORT void JNICALL /* Cleanup java hosts */ hosts = MSG_hosts_as_dynar(); for (index = 0; index < xbt_dynar_length(hosts) - 1; index++) { - jhost = (jobject) MSG_host_get_data(xbt_dynar_get_as(hosts,index,msg_host_t)); + jhost = (jobject) xbt_lib_get_level(xbt_dynar_get_as(hosts,index,msg_host_t), JAVA_HOST_LEVEL); if (jhost) jhost_unref(env, jhost); } xbt_dynar_free(&hosts); + + /* Cleanup java storages */ + storages = MSG_storages_as_dynar(); + if(!xbt_dynar_is_empty(storages)){ + for (index = 0; index < xbt_dynar_length(storages) - 1; index++) { + jstorage = (jobject) xbt_lib_get_level(xbt_dynar_get_as(storages,index,msg_storage_t), JAVA_STORAGE_LEVEL); + if (jstorage) + jstorage_unref(env, jstorage); + } + } + xbt_dynar_free(&storages); + } JNIEXPORT void JNICALL @@ -260,7 +291,7 @@ static int create_jprocess(int argc, char *argv[]) { jclass class_Process = (*env)->FindClass(env, argv[0]); xbt_str_subst(argv[0],'/','.',0); //Retrieve the methodID for the constructor - xbt_assert((class_Process != NULL), "Class not found (%s).", argv[0]); + xbt_assert((class_Process != NULL), "Class not found (%s). The deployment file must use the fully qualified class name, including the package. The case is important.", argv[0]); jmethodID constructor_Process = (*env)->GetMethodID(env, class_Process, "", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V"); xbt_assert((constructor_Process != NULL), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]);