From 052c8009f409968d789bfb546d8f0af57a78c6c6 Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 22 Mar 2010 17:19:15 +0000 Subject: [PATCH] further cleanups of the java bindings git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7299 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/msg/datatypes.h | 8 ++++---- src/java/jmsg.c | 24 +++--------------------- src/java/jxbt_utilities.c | 17 +++++++---------- src/java/jxbt_utilities.h | 17 +++++++++++++---- src/java/simgrid/msg/MsgNative.java | 20 ++++++-------------- src/java/simgrid/msg/Process.java | 2 +- 6 files changed, 34 insertions(+), 54 deletions(-) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index 3187380740..8dd4bcc880 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -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_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. */ - 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 !*/ - MSG_TASK_CANCELLED, + MSG_TASK_CANCELLED=8, /**< @brief Cancelled task. This task has been cancelled by somebody!*/ MSG_FATAL diff --git a/src/java/jmsg.c b/src/java/jmsg.c index b18f5dfee8..2f228931a1 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -230,7 +230,7 @@ Java_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls, 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; } @@ -981,26 +981,8 @@ Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls, (*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 diff --git a/src/java/jxbt_utilities.c b/src/java/jxbt_utilities.c index 079e479168..9649bd6c0a 100644 --- a/src/java/jxbt_utilities.c +++ b/src/java/jxbt_utilities.c @@ -265,31 +265,28 @@ void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name) } // 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", - bprintf("There has been a problem during your task transfer (task :%s / alias :%s)",task_name,alias)); + details); } // 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", - 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 -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", - 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 +} diff --git a/src/java/jxbt_utilities.h b/src/java/jxbt_utilities.h index dc5416f079..4d6dd0395b 100644 --- a/src/java/jxbt_utilities.h +++ b/src/java/jxbt_utilities.h @@ -14,7 +14,6 @@ #define JXBT_UTILITY_H #include -#include "jxbt_utilities.h" /* *********** */ /* JNI GETTERS */ @@ -57,6 +56,16 @@ jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, /* 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); @@ -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 */ -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*/ -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 */ -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 */ diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index f44268851e..c31ab494c5 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -51,11 +51,9 @@ final class MsgNative { * * @param process The valid (binded with a native process) java process to suspend. * - * @exception NativeException if the SimGrid native code failed. - * * @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. @@ -96,11 +94,11 @@ final class MsgNative { * * @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() */ - 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. @@ -122,11 +120,9 @@ final class MsgNative { * * @return The PID of the specified process. * - * @exception NativeException if the SimGrid native code failed. - * * @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. @@ -135,22 +131,18 @@ final class MsgNative { * * @return The PPID of the specified process. * - * @exception NativeException if the SimGrid native code failed. - * * @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. * - * @exception NativeException if the SimGrid native code failed. - * @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. diff --git a/src/java/simgrid/msg/Process.java b/src/java/simgrid/msg/Process.java index f1e8049684..0fdc6621b8 100644 --- a/src/java/simgrid/msg/Process.java +++ b/src/java/simgrid/msg/Process.java @@ -222,7 +222,7 @@ public abstract class Process extends Thread { * @exception NativeException on error in the native SimGrid code * */ - public Host getHost() throws NativeException { + public Host getHost() { return MsgNative.processGetHost(this); } /** -- 2.20.1