JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobject jprocess, jobject jhost) { msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return; } /* try to change the host of the process */ msg_error_t rv = MSG_process_migrate(process, host); if (rv != MSG_OK) { jmsg_throw_status(env,rv); return; } /* change the host java side */ (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost); }
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); jobject jstorage; jstring jname; if (!host) { jxbt_throw_notbound(env, "host", jhost); return 0; } int index = 0; jobjectArray jtable; xbt_dict_t dict = MSG_host_get_mounted_storage_list(host); int count = xbt_dict_length(dict); jclass cls = env->FindClass("org/simgrid/msg/Storage"); jtable = env->NewObjectArray((jsize) count, cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Storages table allocation failed"); return nullptr; } xbt_dict_cursor_t cursor=nullptr; const char* mount_name; const char* storage_name; xbt_dict_foreach(dict,cursor,mount_name,storage_name) { jname = env->NewStringUTF(storage_name); jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname); env->SetObjectArrayElement(jtable, index, jstorage); index++; }
RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream) { RngStream rngstream = (RngStream)(intptr_t)env->GetLongField(jrngstream, jrngstream_bind); if (!rngstream) { jxbt_throw_notbound(env, "rngstream", jrngstream); return nullptr; } return rngstream; }
JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return -1; } return (jdouble) MSG_host_get_core_number(host); }
JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jobject jstorage) { msg_storage_t storage = jstorage_get_native(env, jstorage); if (!storage) { jxbt_throw_notbound(env, "storage", jstorage); return -1; } return (jlong) MSG_storage_get_used_size(storage); }
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return -1; } return (jint) MSG_get_host_msgload(host); }
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return 0; } return (jboolean) MSG_host_is_on(host); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject jprocess) { /* get the native instances from the java ones */ msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } MSG_process_kill(process); }
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env, jobject jprocess) { msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return 0; } /* true is the process is suspended, false otherwise */ return (jboolean) MSG_process_is_suspended(process); }
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getHost(JNIEnv * env,jobject jstorage) { msg_storage_t storage = jstorage_get_native(env, jstorage); if (!storage) { jxbt_throw_notbound(env, "storage", jstorage); return NULL; } const char *host_name = MSG_storage_get_host(storage); if (!host_name) { return NULL; } jobject jhost_name = env->NewStringUTF(host_name); return jhost_name; }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume(JNIEnv * env, jobject jprocess) { msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } /* try to resume the process */ msg_error_t rv = MSG_process_resume(process); jxbt_check_res("MSG_process_resume()", rv, MSG_OK, bprintf("unexpected error , please report this bug")); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return; } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0); char *value = xbt_strdup(value_java); MSG_host_set_property_value(host, name, value, xbt_free_f); env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject jname, jobject jvalue) { msg_storage_t storage = jstorage_get_native(env, jstorage); if (!storage) { jxbt_throw_notbound(env, "storage", jstorage); return; } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0); char *value = xbt_strdup(value_java); MSG_storage_set_property_value(storage, name, value, xbt_free_f); env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *env, jobject jprocess) { msg_process_t process = jprocess_to_native_process(jprocess, env); xbt_ex_t e; if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } TRY { MSG_process_restart(process); } CATCH (e) { xbt_ex_free(e); } }
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env, jobject jstorage, jobject jname) { msg_storage_t storage = jstorage_get_native(env, jstorage); if (!storage) { jxbt_throw_notbound(env, "storage", jstorage); return NULL; } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *property = MSG_storage_get_property_value(storage, name); if (!property) { return NULL; } jobject jproperty = env->NewStringUTF(property); env->ReleaseStringUTFChars((jstring) jname, name); return jproperty; }
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *env, jobject jprocess, jboolean jauto_restart) { msg_process_t process = jprocess_to_native_process(jprocess, env); xbt_ex_t e; int auto_restart = jauto_restart == JNI_TRUE ? 1 : 0; if (!process) { jxbt_throw_notbound(env, "process", jprocess); return; } TRY { MSG_process_auto_restart_set(process,auto_restart); } CATCH (e) { xbt_ex_free(e); } }
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { jxbt_throw_notbound(env, "host", jhost); return nullptr; } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *property = MSG_host_get_property_value(host, name); if (!property) { return nullptr; } jobject jproperty = env->NewStringUTF(property); env->ReleaseStringUTFChars((jstring) jname, name); return jproperty; }
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) { msg_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { jxbt_throw_notbound(env, "process", jprocess); return NULL; } const char *name = (*env)->GetStringUTFChars(env, jname, 0); const char *property = MSG_process_get_property_value(process, name); if (!property) { return NULL; } jobject jproperty = (*env)->NewStringUTF(env, property); (*env)->ReleaseStringUTFChars(env, jname, name); return jproperty; }