From 13e36e7d7378077df05f126c50f87108518a6ea7 Mon Sep 17 00:00:00 2001 From: coldpeace Date: Tue, 23 Mar 2010 10:43:36 +0000 Subject: [PATCH] removing NativeExpection and adding others git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7308 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/java/jmsg.c | 54 ++++++++++++-------- src/java/jxbt_utilities.c | 10 ++++ src/java/jxbt_utilities.h | 4 ++ src/java/simgrid/msg/ApplicationHandler.java | 4 -- src/java/simgrid/msg/Host.java | 10 ++-- src/java/simgrid/msg/MsgNative.java | 35 ++++++------- src/java/simgrid/msg/Process.java | 38 ++++++-------- src/java/simgrid/msg/Task.java | 40 +++++++-------- 8 files changed, 100 insertions(+), 95 deletions(-) diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 2f228931a1..8b57c1c8d7 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -158,8 +158,11 @@ Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls, } /* try to suspend the process */ - if (MSG_OK != MSG_process_suspend(process)) - jxbt_throw_native(env, xbt_strdup("MSG_process_suspend() failed")); + MSG_error_t rv = MSG_process_suspend(process); + + jxbt_check_res("MSG_process_suspend()",rv,MSG_OK, + bprintf("unexpected error , please report this bug")); + } JNIEXPORT void JNICALL @@ -174,8 +177,10 @@ Java_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls, } /* try to resume the process */ - if (MSG_OK != MSG_process_resume(process)) - jxbt_throw_native(env, xbt_strdup("MSG_process_resume() failed")); + 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 jboolean JNICALL @@ -326,10 +331,11 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls, jdouble seconds) { - if (MSG_OK != MSG_process_sleep((double) seconds)) - jxbt_throw_native(env, - bprintf("MSG_process_change_host(%f) failed", - (double) seconds)); + MSG_error_t rv= MSG_process_sleep((double) seconds); + + jxbt_check_res("MSG_process_sleep()",rv, MSG_HOST_FAILURE, + bprintf("while process was waiting for %f seconds",(double)seconds)); + } @@ -656,7 +662,7 @@ Java_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls, host = MSG_task_get_source(task); if (!host->data) { - jxbt_throw_native(env, xbt_strdup("MSG_task_get_source() failed")); + jxbt_throw_jni(env, "MSG_task_get_source() failed"); return NULL; } @@ -688,8 +694,10 @@ Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask) return; } - if (MSG_OK != MSG_task_cancel(ptask)) - jxbt_throw_native(env, xbt_strdup("MSG_task_cancel() failed")); + MSG_error_t rv = MSG_task_cancel(ptask); + + jxbt_check_res("MSG_task_cancel()",rv,MSG_OK, + bprintf("unexpected error , please report this bug")); } JNIEXPORT jdouble JNICALL @@ -745,9 +753,12 @@ Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls, return; } jtask = (jobject) task->data; + + MSG_error_t rv = MSG_task_destroy(task); + + jxbt_check_res("MSG_task_destroy()",rv,MSG_OK, + bprintf("unexpected error , please report this bug")); - if (MSG_OK != MSG_task_destroy(task)) - jxbt_throw_native(env, xbt_strdup("MSG_task_destroy() failed")); /* delete the global reference to the java task object */ jtask_delete_global_ref(jtask, env); @@ -764,8 +775,10 @@ Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls, return; } - if (MSG_OK != MSG_task_execute(task)) - jxbt_throw_native(env, xbt_strdup("MSG_task_execute() failed")); + MSG_error_t rv = MSG_task_execute(task); + + jxbt_check_res("MSG_task_execute()",rv,MSG_HOST_FAILURE|MSG_TASK_CANCELLED, + bprintf("while executing task %s", MSG_task_get_name(task))); } /*************************************************************************************** @@ -1005,8 +1018,9 @@ Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls, (*env)->ReleaseStringUTFChars(env, jalias, alias); - if (MSG_OK != rv) - jxbt_throw_native(env, xbt_strdup("MSG_task_send_bounded() failed")); + jxbt_check_res("MSG_task_send_bounded()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT_FAILURE, + bprintf("while sending task %s to mailbox %s with max rate %f", MSG_task_get_name(task),alias,(double)jmaxRate)); + } JNIEXPORT jobject JNICALL @@ -1034,10 +1048,8 @@ Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls, (*env)->ReleaseStringUTFChars(env, jalias, alias); - if (MSG_OK != rv) { - jxbt_throw_native(env, xbt_strdup("MSG_task_receive_ext() failed")); - return NULL; - } + jxbt_check_res("MSG_task_receive_ext()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT_FAILURE, + bprintf("while receiving from mailbox %s",alias)); return (jobject) task->data; } diff --git a/src/java/jxbt_utilities.c b/src/java/jxbt_utilities.c index 9649bd6c0a..43047a636a 100644 --- a/src/java/jxbt_utilities.c +++ b/src/java/jxbt_utilities.c @@ -290,3 +290,13 @@ void jxbt_throw_time_out_failure(JNIEnv *env,char *details) { details); } + +// task Cancelled exception +void jxbt_throw_task_cancelled(JNIEnv *env,char *details) +{ + + jxbt_throw_by_name(env, + "simgrid/msg/TaskCancelledException", + details); + +} \ No newline at end of file diff --git a/src/java/jxbt_utilities.h b/src/java/jxbt_utilities.h index 4d6dd0395b..699e4f67e0 100644 --- a/src/java/jxbt_utilities.h +++ b/src/java/jxbt_utilities.h @@ -65,6 +65,8 @@ jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, jxbt_throw_transfer_failure(env,detail); \ } else if (res == MSG_TIMEOUT_FAILURE) { \ jxbt_throw_time_out_failure(env,detail); \ + } else if (res == MSG_TASK_CANCELLED){ \ + jxbt_throw_task_cancelled(env,detail); \ } } while (0) /** Thrown on internal error of this layer, or on problem with JNI */ @@ -90,5 +92,7 @@ void jxbt_throw_transfer_failure(JNIEnv * env,char *detail); 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,char *details); +/**Thrown when a task is canceled */ +void jxbt_throw_task_cancelled(JNIEnv *env,char *details); #endif /* ! JXBT_UTILITY_H */ diff --git a/src/java/simgrid/msg/ApplicationHandler.java b/src/java/simgrid/msg/ApplicationHandler.java index 82d38e86f3..ef245d7c7c 100644 --- a/src/java/simgrid/msg/ApplicationHandler.java +++ b/src/java/simgrid/msg/ApplicationHandler.java @@ -96,10 +96,6 @@ public final class ApplicationHandler { process.properties = properties; properties = new Hashtable(); - } catch(NativeException e) { - System.out.println(e.toString()); - e.printStackTrace(); - } catch(HostNotFoundException e) { System.out.println(e.toString()); e.printStackTrace(); diff --git a/src/java/simgrid/msg/Host.java b/src/java/simgrid/msg/Host.java index 9dd9f4b9ac..ffe8b416b0 100644 --- a/src/java/simgrid/msg/Host.java +++ b/src/java/simgrid/msg/Host.java @@ -72,7 +72,7 @@ public class Host { * NativeException if the native version of this method failed. */ public static Host getByName(String name) - throws HostNotFoundException, NativeException { + throws HostNotFoundException { if (name==null) throw new NullPointerException("No host can have a null name"); return MsgNative.hostGetByName(name); @@ -84,7 +84,7 @@ public class Host { * @return The count of the installed hosts. * */ - public static int getCount() throws NativeException { + public static int getCount() { return MsgNative.hostGetCount(); } @@ -102,9 +102,8 @@ public class Host { * * @return An array containing all the hosts installed. * - * @exception NativeException if the native version of this method failed. */ - public static Host[] all() throws NativeException { + public static Host[] all() { return MsgNative.allHosts(); } @@ -113,9 +112,8 @@ public class Host { * * @return The name of the host. * - * @exception NativeException FIXME: check when */ - public String getName() throws NativeException { + public String getName() { return MsgNative.hostGetName(this); } diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index c31ab494c5..aa7a3b9378 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -69,11 +69,10 @@ final class MsgNative { * * @param process The valid (binded with a native process) java process to resume. * - * @exception NativeException if the SimGrid native code failed. * * @see Process.restart() */ - final static native void processResume(Process process) throws NativeException; + final static native void processResume(Process process); /** * The natively implemented method to test if MSG process is suspended. @@ -150,12 +149,11 @@ final class MsgNative { * @param process The (valid) process to migrate. * @param host A (valid) host where move the process. * - * @exception NativeException if the SimGrid native code failed. * * @see Process.migrate() * @see Host.getByName() */ - final static native void processChangeHost(Process process, Host host) throws NativeException; + final static native void processChangeHost(Process process, Host host) ; /** * The natively implemented native to request the current process to sleep @@ -163,11 +161,11 @@ final class MsgNative { * * @param seconds The time the current process must sleep. * - * @exception NativeException if the SimGrid native code failed. + * @exception HostFailureException if the SimGrid native code failed. * * @see Process.waitFor() */ - final static native void processWaitFor(double seconds) throws NativeException; + final static native void processWaitFor(double seconds) throws HostFailureException; /** * The natively implemented native method to exit a process. @@ -189,11 +187,11 @@ final class MsgNative { * @return The host having the specified name. * * @exception HostNotFoundException if there is no such host - * NativeException if the SimGrid native code failed. + * * * @see Host.getByName() */ - final static native Host hostGetByName(String name) throws HostNotFoundException, NativeException; + final static native Host hostGetByName(String name) throws HostNotFoundException; /** * The natively implemented method to get the name of an MSG host. @@ -309,11 +307,10 @@ final class MsgNative { * * @return The source of the task. * - * @exception NativeException if the SimGrid native code failed. * * @see Task.getSource() */ - final static native Host taskGetSource(Task task) throws NativeException; + final static native Host taskGetSource(Task task); /** * The natively implemented method to get the name of the task. @@ -331,11 +328,10 @@ final class MsgNative { * * @param task The task to cancel. * - * @exception NativeException if the cancellation failed. * * @see Task.cancel(). */ - final static native void taskCancel(Task task) throws NativeException; + final static native void taskCancel(Task task); /** * The natively implemented method to create a MSG parallel task. @@ -392,30 +388,29 @@ final class MsgNative { * * @param The task to destroy. * - * @exception NativeException on error in the C world * * @see Task.destroy() */ - final static native void taskDestroy(Task task) throws NativeException; + final static native void taskDestroy(Task task) ; /** * The natively implemented method to execute a MSG task. * * @param task The task to execute. * - * @exception NativeException on error in the C world + * @exception HostFailureException,TaskCancelledException on error in the C world * * @see Task.execute() */ - final static native void taskExecute(Task task) throws NativeException; + final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException; /* **************************************************************** * Communication methods thru mailboxes * **************************************************************** */ - final static native void taskSend(String alias, Task task, double timeout) throws NativeException,TransferFailureException,HostFailureException,TimeoutException; - final static native Task taskReceive(String alias, double timeout, Host host) throws NativeException; - final static native int taskListenFrom(String alias) throws NativeException; + final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException; + final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException; + final static native int taskListenFrom(String alias); final static native boolean taskListen(String alias); final static native int taskListenFromHost(String alias, Host host); @@ -433,6 +428,6 @@ final class MsgNative { * * @exception NativeException on error in the C world */ - final static native void taskSendBounded(String alias, Task task, double maxrate) throws NativeException; + final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException; } \ No newline at end of file diff --git a/src/java/simgrid/msg/Process.java b/src/java/simgrid/msg/Process.java index 0fdc6621b8..0a49369fbc 100644 --- a/src/java/simgrid/msg/Process.java +++ b/src/java/simgrid/msg/Process.java @@ -104,10 +104,10 @@ public abstract class Process extends Thread { * @param name The name of the process. * * @exception HostNotFoundException if no host with this name exists. - * NativeException + * * */ - public Process(String hostname, String name) throws HostNotFoundException, NativeException { + public Process(String hostname, String name) throws HostNotFoundException { this(Host.getByName(hostname), name, null); } /** @@ -190,19 +190,17 @@ public abstract class Process extends Thread { * Suspends the process by suspending the task on which it was * waiting for the completion. * - * @exception NativeException on error in the native SimGrid code */ - public void pause() throws NativeException { + public void pause() { MsgNative.processSuspend(this); } /** * Resumes a suspended process by resuming the task on which it was * waiting for the completion. * - * @exception NativeException on error in the native SimGrid code * */ - public void restart() throws NativeException { + public void restart() { MsgNative.processResume(this); } /** @@ -242,9 +240,8 @@ public abstract class Process extends Thread { * * @return The PID of the process. * - * @exception NativeException on error in the native SimGrid code */ - public int getPID() throws NativeException { + public int getPID() { return MsgNative.processGetPID(this); } /** @@ -252,9 +249,8 @@ public abstract class Process extends Thread { * * @return The PID of the parent of the process. * - * @exception NativeException on error in the native SimGrid code */ - public int getPPID() throws NativeException { + public int getPPID() { return MsgNative.processGetPPID(this); } /** @@ -262,9 +258,8 @@ public abstract class Process extends Thread { * * @return The current process. * - * @exception NativeException on error in the native SimGrid code */ - public static Process currentProcess() throws NativeException { + public static Process currentProcess() { return MsgNative.processSelf(); } /** @@ -272,9 +267,8 @@ public abstract class Process extends Thread { * * @param host The host where to migrate the process. * - * @exception NativeException on error in the native SimGrid code */ - public void migrate(Host host) throws NativeException { + public void migrate(Host host) { MsgNative.processChangeHost(this, host); } /** @@ -282,9 +276,9 @@ public abstract class Process extends Thread { * * @param seconds The time the current process must sleep. * - * @exception NativeException on error in the native SimGrid code + * @exception HostFailureException on error in the native SimGrid code */ - public static void waitFor(double seconds) throws NativeException { + public static void waitFor(double seconds) throws HostFailureException { MsgNative.processWaitFor(seconds); } public void showArgs() { @@ -357,7 +351,7 @@ public abstract class Process extends Thread { * @throws TimeoutException * @throws HostFailureException * @throws TransferFailureException */ - public void taskSend(String mailbox, Task task, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException { + public void taskSend(String mailbox, Task task, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { MsgNative.taskSend(mailbox, task, timeout); } @@ -365,27 +359,27 @@ public abstract class Process extends Thread { * @throws TimeoutException * @throws HostFailureException * @throws TransferFailureException */ - public void taskSend(String mailbox, Task task) throws NativeException, TransferFailureException, HostFailureException, TimeoutException { + public void taskSend(String mailbox, Task task) throws TransferFailureException, HostFailureException, TimeoutException { MsgNative.taskSend(mailbox, task, -1); } /** Receive a task on mailbox associated with the specified mailbox */ - public Task taskReceive(String mailbox) throws NativeException { + public Task taskReceive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, -1.0, null); } /** Receive a task on mailbox associated with the specified alias (waiting at most given time) */ - public Task taskReceive(String mailbox, double timeout) throws NativeException { + public Task taskReceive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, timeout, null); } /** Receive a task on mailbox associated with the specified alias from given sender */ - public Task taskReceive(String mailbox, double timeout, Host host) throws NativeException { + public Task taskReceive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, timeout, host); } /** Receive a task on mailbox associated with the specified alias from given sender*/ - public Task taskReceive(String mailbox, Host host) throws NativeException { + public Task taskReceive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, -1.0, host); } } diff --git a/src/java/simgrid/msg/Task.java b/src/java/simgrid/msg/Task.java index 3c54be47a0..bc2cdaa23b 100644 --- a/src/java/simgrid/msg/Task.java +++ b/src/java/simgrid/msg/Task.java @@ -73,7 +73,7 @@ public class Task { return MsgNative.taskGetSender(this); } /** Gets the source of the task */ - public Host getSource() throws NativeException { + public Host getSource() { return MsgNative.taskGetSource(this); } /** Gets the computing amount of the task */ @@ -106,9 +106,9 @@ public class Task { /** * Executes a task on the location on which the process is running. * - * @exception NativeException if the execution failed. + * @exception HostFailureException,TaskCancelledException */ - public void execute() throws NativeException { + public void execute() throws HostFailureException,TaskCancelledException { MsgNative.taskExecute(this); } /** @@ -116,7 +116,7 @@ public class Task { * * @exception NativeException if the cancellation failed. */ - public void cancel() throws NativeException { + public void cancel() { MsgNative.taskCancel(this); } /** Deletes a task. @@ -131,12 +131,11 @@ public class Task { /** * Sends the task on the mailbox identified by the specified name * - * @exception NativeException if the retrieval fails. * @throws TimeoutException * @throws HostFailureException * @throws TransferFailureException */ - public void send(String mailbox) throws NativeException, TransferFailureException, HostFailureException, TimeoutException { + public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { MsgNative.taskSend(mailbox, this, -1); } @@ -155,73 +154,70 @@ public class Task { /** * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) * - * @exception NativeException if the retrieval fails. + * @exception TransferFailureException, HostFailureException, TimeoutException. */ - public void sendBounded(String alias, double maxrate) throws NativeException { + public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException { MsgNative.taskSendBounded(alias, this, maxrate); } /** * Retrieves next task from the mailbox identified by the specified name * - * @exception NativeException if the retrieval fails. + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. */ - public static Task receive(String mailbox) throws NativeException { + public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, -1.0, null); } /** * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) * - * @exception NativeException if the retrieval fails. + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. */ - public static Task receive(String mailbox, double timeout) throws NativeException { + public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, timeout, null); } /** * Retrieves next task sent by a given host on the mailbox identified by the specified alias * - * @exception NativeException if the retrieval fails. + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. */ - public static Task receive(String mailbox, Host host) throws NativeException { + public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, -1.0, host); } /** * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds) * - * @exception NativeException if the retrieval fails. + * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails. */ - public static Task receive(String mailbox, double timeout, Host host) throws NativeException { + public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException { return MsgNative.taskReceive(mailbox, timeout, host); } /** * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it * - * @exception NativeException if the retrieval fails. */ - public static int listenFrom(String mailbox) throws NativeException { + public static int listenFrom(String mailbox) { return MsgNative.taskListenFrom(mailbox); } /** * Listen whether there is a waiting task on the mailbox identified by the specified alias * - * @exception NativeException if the retrieval fails. */ - public static boolean listen(String mailbox) throws NativeException { + public static boolean listen(String mailbox) { return MsgNative.taskListen(mailbox); } /** * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host. * - * @exception NativeException if the retrieval fails. */ - public static int listenFromHost(String alias, Host host) throws NativeException { + public static int listenFromHost(String alias, Host host) { return MsgNative.taskListenFromHost(alias, host); } } -- 2.20.1