* Finalize the communication object, destroying it.
*/
protected void finalize() throws Throwable {
- unbind();
+ destroy();
}
/**
* Unbind the communication object
*/
- public native void unbind() throws NativeException;
+ public native void destroy() throws NativeException;
/**
* Returns if the communication is finished or not.
* If the communication has finished and there was an error,
(*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL);
return env;
}
+
+void jmsg_throw_status(JNIEnv *env, MSG_error_t status) {
+ switch (status) {
+ case MSG_TIMEOUT:
+ jxbt_throw_time_out_failure(env,NULL);
+ break;
+ case MSG_TRANSFER_FAILURE:
+ jxbt_throw_transfer_failure(env,NULL);
+ break;
+ case MSG_HOST_FAILURE:
+ jxbt_throw_host_failure(env,NULL);
+ break;
+ default:
+ jxbt_throw_native(env,bprintf("communication failed"));
+ }
+}
+
+
/***************************************************************************************
* Unsortable functions *
***************************************************************************************/
#ifndef MSG4JAVA_H
#define MSG4JAVA_H
-
+#include <msg/msg.h>
#include <jni.h>
JavaVM *get_java_VM(void);
JNIEnv *get_current_thread_env(void);
+/**
+ * This function throws the correct exception according to the status
+ * provided.
+ */
+void jmsg_throw_status(JNIEnv *env, MSG_error_t status);
/*
* Class org_simgrid_msg_Msg
/* Copyright (c) 2012. The SimGrid Team. All rights reserved. */
#include "jmsg_comm.h"
#include "jxbt_utilities.h"
+#include "jmsg.h"
+
#include <msg/msg.h>
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
}
}
-void jcomm_throw(JNIEnv *env, MSG_error_t status) {
- switch (status) {
- case MSG_TIMEOUT:
- jxbt_throw_time_out_failure(env,NULL);
- break;
- case MSG_TRANSFER_FAILURE:
- jxbt_throw_transfer_failure(env,NULL);
- break;
- case MSG_HOST_FAILURE:
- jxbt_throw_host_failure(env,NULL);
- break;
- default:
- jxbt_throw_native(env,bprintf("communication failed"));
- }
-}
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) {
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Comm_unbind(JNIEnv *env, jobject jcomm) {
+Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm) {
msg_comm_t comm;
m_task_t *task_received;
}
else {
//send the correct exception
- jcomm_throw(env,status);
+ jmsg_throw_status(env,status);
return JNI_FALSE;
}
}
return;
}
else {
- jcomm_throw(env,status);
+ jmsg_throw_status(env,status);
}
* the java communication object.
*/
void jcomm_bind_task(JNIEnv *env, jobject jcomm);
-/**
- * This function throws the correct exception according to the status
- * returned.
- */
-void jcomm_throw(JNIEnv *env, MSG_error_t status);
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Comm_unbind(JNIEnv *env, jobject jcomm);
+Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm);
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm);
(*env)->ReleaseStringUTFChars(env, jalias, alias);
- jxbt_check_res("MSG_task_send_with_timeout()", rv,
- MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
- bprintf("while sending task %s to mailbox %s",
- MSG_task_get_name(task), alias));
+ if (rv != MSG_OK) {
+ jmsg_throw_status(env, rv);
+ return;
+ }
}
JNIEXPORT void JNICALL
return NULL;
}
if (rv != MSG_OK) {
- switch (rv) {
- case MSG_TIMEOUT:
- jxbt_throw_time_out_failure(env,NULL);
- break;
- case MSG_TRANSFER_FAILURE:
- jxbt_throw_transfer_failure(env,NULL);
- break;
- case MSG_HOST_FAILURE:
- jxbt_throw_host_failure(env,NULL);
- break;
- default:
- jxbt_throw_native(env,bprintf("receive failed"));
- }
+ jmsg_throw_status(env,rv);
return NULL;
}
jtask_global = MSG_task_get_data(task);