Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the handling of errors in Task.send
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 18 May 2012 12:03:57 +0000 (14:03 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 18 May 2012 12:03:57 +0000 (14:03 +0200)
org/simgrid/msg/Comm.java
src/jmsg.c
src/jmsg.h
src/jmsg_comm.c
src/jmsg_comm.h
src/jmsg_task.c

index bd84cb5..3ef08e3 100644 (file)
@@ -41,12 +41,12 @@ public class Comm {
         * Finalize the communication object, destroying it.
         */
        protected void finalize() throws Throwable {
         * Finalize the communication object, destroying it.
         */
        protected void finalize() throws Throwable {
-               unbind();
+               destroy();
        }
        /**
         * Unbind the communication object
         */
        }
        /**
         * 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,
        /**
         * Returns if the communication is finished or not.
         * If the communication has finished and there was an error,
index 1e02578..ee091f2 100644 (file)
@@ -49,6 +49,24 @@ JNIEnv *get_current_thread_env(void)
   (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL);
   return env;
 }
   (*__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                                                        *
  ***************************************************************************************/
 /***************************************************************************************
  * Unsortable functions                                                        *
  ***************************************************************************************/
index c943fe6..da58d25 100644 (file)
@@ -8,12 +8,17 @@
 
 #ifndef MSG4JAVA_H
 #define MSG4JAVA_H
 
 #ifndef MSG4JAVA_H
 #define MSG4JAVA_H
-
+#include <msg/msg.h>
 #include <jni.h>
 
 JavaVM *get_java_VM(void);
 
 JNIEnv *get_current_thread_env(void);
 #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
 
 /*
  * Class               org_simgrid_msg_Msg
index 4a394cd..48638c0 100644 (file)
@@ -3,6 +3,8 @@
 /* Copyright (c) 2012. The SimGrid Team. All rights reserved.                   */
 #include "jmsg_comm.h"
 #include "jxbt_utilities.h"
 /* 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);
 
 #include <msg/msg.h>
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
@@ -35,21 +37,6 @@ void jcomm_bind_task(JNIEnv *env, jobject jcomm) {
        }
 
 }
        }
 
 }
-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_nativeInit(JNIEnv *env, jclass cls) {
@@ -68,7 +55,7 @@ Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) {
 }
 
 JNIEXPORT void JNICALL
 }
 
 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;
 
        msg_comm_t comm;
        m_task_t *task_received;
 
@@ -97,7 +84,7 @@ Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) {
                        }
                        else {
                                //send the correct exception
                        }
                        else {
                                //send the correct exception
-                               jcomm_throw(env,status);
+                               jmsg_throw_status(env,status);
                                return JNI_FALSE;
                        }
                }
                                return JNI_FALSE;
                        }
                }
@@ -129,7 +116,7 @@ Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble tim
                return;
        }
        else {
                return;
        }
        else {
-               jcomm_throw(env,status);
+               jmsg_throw_status(env,status);
        }
 
 
        }
 
 
index 2c70d39..ce86f9d 100644 (file)
  * the java communication object.
  */
 void jcomm_bind_task(JNIEnv *env, jobject jcomm);
  * 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
 
 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);
 
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm);
index 86fe919..9eb973c 100644 (file)
@@ -367,10 +367,10 @@ Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask,
 
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
 
   (*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
 }
 
 JNIEXPORT void JNICALL
@@ -432,19 +432,7 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
        return NULL;
   }
   if (rv != MSG_OK) {
        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);
        return NULL;
   }
   jtask_global = MSG_task_get_data(task);