Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further cleanups of the java bindings
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 22 Mar 2010 17:19:15 +0000 (17:19 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 22 Mar 2010 17:19:15 +0000 (17:19 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7299 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/msg/datatypes.h
src/java/jmsg.c
src/java/jxbt_utilities.c
src/java/jxbt_utilities.h
src/java/simgrid/msg/MsgNative.java
src/java/simgrid/msg/Process.java

index 3187380..8dd4bcc 100644 (file)
@@ -121,16 +121,16 @@ SG_BEGIN_DECL()
        MSG_WARNING,
                /**< @brief Mmmh! Something must be not perfectly clean. But I
       may be a paranoid freak... ! */
        MSG_WARNING,
                /**< @brief Mmmh! Something must be not perfectly clean. But I
       may be a paranoid freak... ! */
-       MSG_TIMEOUT_FAILURE, /**< @brief nothing good happened before the timer you provided elapsed */
-       MSG_TRANSFER_FAILURE,
+       MSG_TIMEOUT_FAILURE=1, /**< @brief nothing good happened before the timer you provided elapsed */
+       MSG_TRANSFER_FAILURE=2,
                         /**< @brief There has been a problem during you task
       transfer. Either the network is down or the remote host has been
       shutdown. */
                         /**< @brief There has been a problem during you task
       transfer. Either the network is down or the remote host has been
       shutdown. */
-       MSG_HOST_FAILURE,
+       MSG_HOST_FAILURE=4,
                     /**< @brief System shutdown. The host on which you are
       running has just been rebooted. Free your datastructures and
       return now !*/
                     /**< @brief System shutdown. The host on which you are
       running has just been rebooted. Free your datastructures and
       return now !*/
-       MSG_TASK_CANCELLED,
+       MSG_TASK_CANCELLED=8,
                       /**< @brief Cancelled task. This task has been cancelled 
                        by somebody!*/
        MSG_FATAL
                       /**< @brief Cancelled task. This task has been cancelled 
                        by somebody!*/
        MSG_FATAL
index b18f5df..2f22893 100644 (file)
@@ -230,7 +230,7 @@ Java_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls,
   host = MSG_process_get_host(process);
 
   if (!host->data) {
   host = MSG_process_get_host(process);
 
   if (!host->data) {
-    jxbt_throw_native(env, xbt_strdup("MSG_process_get_host() failed"));
+    jxbt_throw_jni(env, "MSG_process_get_host() failed");
     return NULL;
   }
 
     return NULL;
   }
 
@@ -981,26 +981,8 @@ Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
 
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
 
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
-  /*  throw the right exception corresponding to HostFailureException, TransferFailureException, TimeoutFailureException
-   * Note: these exceptions must be created beforehand
-   *       then, you want to create some functions like jxbt_throw_notbound()
-   *       then, you must declare in the MsgNative stuff that these native functions can throw these exceptions
-   */
-  if (MSG_OK != rv)
-  {
-    
-      if ( rv == MSG_TRANSFER_FAILURE )
-       jxbt_throw_transfer_failure(env,MSG_task_get_name(task),alias);
-       
-      else if ( rv == MSG_HOST_FAILURE )
-       jxbt_throw_host_failure(env,MSG_task_get_name(task),alias);
-       
-      else if ( rv == MSG_TIMEOUT_FAILURE )
-        jxbt_throw_time_out_failure(env,MSG_task_get_name(task),alias);
-      else
-       jxbt_throw_native(env, xbt_strdup("MSG_task_send_with_timeout() failed"));
-  
-  } 
+  jxbt_check_res("MSG_task_send_with_timeout()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT_FAILURE,
+    bprintf("while sending task %s to mailbox %s", MSG_task_get_name(task),alias));
 }
 
 JNIEXPORT void JNICALL
 }
 
 JNIEXPORT void JNICALL
index 079e479..9649bd6 100644 (file)
@@ -265,31 +265,28 @@ void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name)
 }
 
 // tranfert failure
 }
 
 // tranfert failure
-void jxbt_throw_transfer_failure(JNIEnv *env,const char *task_name,const char *alias)
-{
+void jxbt_throw_transfer_failure(JNIEnv *env,char *details) {
   
   jxbt_throw_by_name(env,
                     "simgrid/msg/TransferFailureException",
   
   jxbt_throw_by_name(env,
                     "simgrid/msg/TransferFailureException",
-                    bprintf("There has been a problem during your task transfer (task :%s / alias :%s)",task_name,alias));
+                    details);
   
 }
 
 // host failure Exception
   
 }
 
 // host failure Exception
-void jxbt_throw_host_failure(JNIEnv *env,const char *task_name,const char *alias)
-{
+void jxbt_throw_host_failure(JNIEnv *env,char *details) {
   
  jxbt_throw_by_name(env,
                    "simgrid/msg/HostFailureException",
   
  jxbt_throw_by_name(env,
                    "simgrid/msg/HostFailureException",
-                   bprintf("Host Failure while sending (task :%s / alias %s) : The host on which you are running has just been rebooted",task_name,alias));
+                   bprintf("Host Failure %s",details));
   
 }
 
 // time out failure Exception
   
 }
 
 // time out failure Exception
-void jxbt_throw_time_out_failure(JNIEnv *env,const char *task_name,const char *alias)
-{
+void jxbt_throw_time_out_failure(JNIEnv *env,char *details) {
   
   jxbt_throw_by_name(env,
                    "simgrid/msg/TimeoutException",
   
   jxbt_throw_by_name(env,
                    "simgrid/msg/TimeoutException",
-                   bprintf("Timeout Failure while sending(task :%s / alias %s ):nothing good happened before the timer you provided elapsed ",task_name,alias));
+                   details);
   
   
-}
\ No newline at end of file
+}
index dc5416f..4d6dd03 100644 (file)
@@ -14,7 +14,6 @@
 #define JXBT_UTILITY_H
 
 #include <jni.h>
 #define JXBT_UTILITY_H
 
 #include <jni.h>
-#include "jxbt_utilities.h"
 
 /* *********** */
 /* JNI GETTERS */
 
 /* *********** */
 /* JNI GETTERS */
@@ -57,6 +56,16 @@ jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname,
 /* EXCEPTION RAISING */
 /* ***************** */
 
 /* EXCEPTION RAISING */
 /* ***************** */
 
+#define jxbt_check_res(fun, res, allowed_exceptions, detail) do {\
+    if (res != MSG_OK && res | allowed_exceptions) { \
+      xbt_die(bprintf("%s failed with error code %d, which is not an allowed exception. Please fix me.",fun,res)); \
+    } else if (res == MSG_HOST_FAILURE) { \
+      jxbt_throw_host_failure(env, detail); \
+    } else if (res == MSG_TRANSFER_FAILURE) { \
+      jxbt_throw_transfer_failure(env,detail); \
+    } else if (res == MSG_TIMEOUT_FAILURE) { \
+      jxbt_throw_time_out_failure(env,detail); \
+   } } while (0)
 
 /** Thrown on internal error of this layer, or on problem with JNI */
 void jxbt_throw_jni(JNIEnv * env, const char *msg);
 
 /** Thrown on internal error of this layer, or on problem with JNI */
 void jxbt_throw_jni(JNIEnv * env, const char *msg);
@@ -76,10 +85,10 @@ void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name);
 /** Thrown when looking for an host from name does not lead to anything */
 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
 /** Thrown when a transfer failure accure while Sending task */
 /** Thrown when looking for an host from name does not lead to anything */
 void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name);
 /** Thrown when a transfer failure accure while Sending task */
-void jxbt_throw_transfer_failure(JNIEnv * env,const char *task_name,const char *alias);
+void jxbt_throw_transfer_failure(JNIEnv * env,char *detail);
 /** Thrown when a host failure accures while Sending task*/
 /** Thrown when a host failure accures while Sending task*/
-void jxbt_throw_host_failure(JNIEnv *env,const char *task_name,const char *alias);
+void jxbt_throw_host_failure(JNIEnv *env,char *details);
 /** Thrown when a time out accures While Sending task */
 /** Thrown when a time out accures While Sending task */
-void jxbt_throw_time_out_failure(JNIEnv *env,const char *task_name,const char *alias);
+void jxbt_throw_time_out_failure(JNIEnv *env,char *details);
 
 #endif /* ! JXBT_UTILITY_H */
 
 #endif /* ! JXBT_UTILITY_H */
index f442688..c31ab49 100644 (file)
@@ -51,11 +51,9 @@ final class MsgNative {
         *
         * @param process        The valid (binded with a native process) java process to suspend.
         *
         *
         * @param process        The valid (binded with a native process) java process to suspend.
         *
-        * @exception            NativeException if the SimGrid native code failed.
-        *
         * @see                 Process.pause()
         */
         * @see                 Process.pause()
         */
-       final static native void processSuspend(Process process) throws NativeException;
+       final static native void processSuspend(Process process);
 
        /**
         * The natively implemented method to kill a MSG process.
 
        /**
         * The natively implemented method to kill a MSG process.
@@ -96,11 +94,11 @@ final class MsgNative {
         *
         * @return                The method returns the host where the process is running.
         *
         *
         * @return                The method returns the host where the process is running.
         *
-        * @exception            NativeException if the SimGrid native code failed.
+        * @exception            HostNotFoundException if the SimGrid native code failed (initialization error?).
         *
         * @see                 Process.getHost()
         */
         *
         * @see                 Process.getHost()
         */
-       final static native Host processGetHost(Process process) throws NativeException;
+       final static native Host processGetHost(Process process);
 
        /**
         * The natively implemented method to get a MSG process from his PID.
 
        /**
         * The natively implemented method to get a MSG process from his PID.
@@ -122,11 +120,9 @@ final class MsgNative {
         *
         * @return                The PID of the specified process.
         *
         *
         * @return                The PID of the specified process.
         *
-        * @exception            NativeException if the SimGrid native code failed.
-        *
         * @see                 Process.getPID()
         */
         * @see                 Process.getPID()
         */
-       final static native int processGetPID(Process process) throws NativeException;
+       final static native int processGetPID(Process process);
 
        /**
         * The natively implemented method to get the PPID of a MSG process.
 
        /**
         * The natively implemented method to get the PPID of a MSG process.
@@ -135,22 +131,18 @@ final class MsgNative {
         *
         * @return                The PPID of the specified process.
         *
         *
         * @return                The PPID of the specified process.
         *
-        * @exception            NativeException if the SimGrid native code failed.
-        *
         * @see                 Process.getPPID()
         */
         * @see                 Process.getPPID()
         */
-       final static native int processGetPPID(Process process) throws NativeException;
+       final static native int processGetPPID(Process process);
 
        /**
         * The natively implemented method to get the current running process.
         *
         * @return             The current process.
         *
 
        /**
         * The natively implemented method to get the current running process.
         *
         * @return             The current process.
         *
-        * @exception            NativeException if the SimGrid native code failed.
-
         * @see                Process.currentProcess()
         */
         * @see                Process.currentProcess()
         */
-       final static native Process processSelf() throws NativeException;
+       final static native Process processSelf();
 
        /**
         * The natively implemented method to migrate a process from his currnet host to a new host.
 
        /**
         * The natively implemented method to migrate a process from his currnet host to a new host.
index f1e8049..0fdc662 100644 (file)
@@ -222,7 +222,7 @@ public abstract class Process extends Thread {
         * @exception                   NativeException on error in the native SimGrid code
         *
         */ 
         * @exception                   NativeException on error in the native SimGrid code
         *
         */ 
-       public Host getHost() throws NativeException {
+       public Host getHost() {
                return MsgNative.processGetHost(this);
        }
        /**
                return MsgNative.processGetHost(this);
        }
        /**