From 4402a2f5346abec910e7ff8551fccb030a7ba823 Mon Sep 17 00:00:00 2001 From: mquinson Date: Sat, 27 Feb 2010 23:06:50 +0000 Subject: [PATCH] Make JniException a runtime exception, nobody wants to survive this git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7144 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 5 +- src/java/jmsg.c | 14 -- src/java/simgrid/msg/ApplicationHandler.java | 13 +- src/java/simgrid/msg/Host.java | 78 ++------ src/java/simgrid/msg/JniException.java | 1 + src/java/simgrid/msg/Msg.java | 6 +- src/java/simgrid/msg/MsgNative.java | 191 +++++-------------- src/java/simgrid/msg/NativeException.java | 7 - src/java/simgrid/msg/Process.java | 118 ++++-------- src/java/simgrid/msg/Task.java | 101 ++++------ 10 files changed, 143 insertions(+), 391 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37be72d27f..90b8f50f7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,7 +9,10 @@ SimGrid (3.3.5-svn) unstable; urgency=low Use send/receive instead. * Cleanup the examples and add a README per directory * Remove example autoDestination (that's the only way to go now) - * Remove example explicitDestination (was a plain copy of basic) + * Remove example explicitDestination (was a plain copy of basic) + * Make JniException a runtime exception, so that there is no need to + declare the fact that you may encounter such a beast. I guess that + nobody will ever want to survive such error. -- Da SimGrid team diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 43a31a4683..912f3017d2 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -311,20 +311,6 @@ Java_simgrid_msg_MsgNative_processSelf(JNIEnv * env, jclass cls) return jprocess; } - -JNIEXPORT jint JNICALL -Java_simgrid_msg_MsgNative_processSelfPID(JNIEnv * env, jclass cls) -{ - return (jint) MSG_process_self_PID(); -} - - -JNIEXPORT jint JNICALL -Java_simgrid_msg_MsgNative_processSelfPPID(JNIEnv * env, jclass cls) -{ - return (jint) MSG_process_self_PPID(); -} - JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv * env, jclass cls, jobject jhost) diff --git a/src/java/simgrid/msg/ApplicationHandler.java b/src/java/simgrid/msg/ApplicationHandler.java index 3c8cd35aac..307c731f0b 100644 --- a/src/java/simgrid/msg/ApplicationHandler.java +++ b/src/java/simgrid/msg/ApplicationHandler.java @@ -109,10 +109,6 @@ public final class ApplicationHandler { process.properties = this.properties; this.properties = new Hashtable(); - } catch(JniException e) { - System.out.println(e.toString()); - e.printStackTrace(); - } catch(NativeException e) { System.out.println(e.toString()); e.printStackTrace(); @@ -127,15 +123,12 @@ public final class ApplicationHandler { e.printStackTrace(); } catch(InstantiationException e) { - System.out.println("instantiation exception"); + System.out.println("Unable to create the process. I got an instantiation exception"); e.printStackTrace(); } catch(IllegalAccessException e) { - System.out.println("illegal access exception"); - e.printStackTrace(); - } catch(IllegalArgumentException e) { - System.out.println("illegal argument exception"); + System.out.println("Unable to create the process. I got an illegal access exception"); e.printStackTrace(); - } + } } } diff --git a/src/java/simgrid/msg/Host.java b/src/java/simgrid/msg/Host.java index 97ef2c20c9..9dd9f4b9ac 100644 --- a/src/java/simgrid/msg/Host.java +++ b/src/java/simgrid/msg/Host.java @@ -69,10 +69,12 @@ public class Host { * @param name The name of the host to get. * * @exception HostNotFoundException if the name of the host is not valid. - * MsgException if the native version of this method failed. + * NativeException if the native version of this method failed. */ public static Host getByName(String name) - throws HostNotFoundException, NativeException, JniException { + throws HostNotFoundException, NativeException { + if (name==null) + throw new NullPointerException("No host can have a null name"); return MsgNative.hostGetByName(name); } @@ -82,7 +84,7 @@ public class Host { * @return The count of the installed hosts. * */ - public static int getCount() throws NativeException, JniException { + public static int getCount() throws NativeException { return MsgNative.hostGetCount(); } @@ -90,10 +92,8 @@ public class Host { * This static method return an instance to the host of the current process. * * @return The host on which the current process is executed. - * - * @exception MsgException if the native version of this method failed. */ - public static Host currentHost() throws JniException { + public static Host currentHost() { return MsgNative.hostSelf(); } @@ -102,9 +102,9 @@ public class Host { * * @return An array containing all the hosts installed. * - * @exception MsgException if the native version of this method failed. + * @exception NativeException if the native version of this method failed. */ - public static Host[] all() throws JniException, NativeException { + public static Host[] all() throws NativeException { return MsgNative.allHosts(); } @@ -113,28 +113,28 @@ public class Host { * * @return The name of the host. * - * @exception InvalidHostException if the host is not valid. + * @exception NativeException FIXME: check when */ - public String getName() throws NativeException, JniException { + public String getName() throws NativeException { return MsgNative.hostGetName(this); } /** - * This method sets the data of the host. + * Sets the data of the host. * */ public void setData(Object data) { this.data = data; } /** - * This method gets the data of the host. + * Gets the data of the host. */ public Object getData() { return this.data; } /** - * This function tests if a host has data. + * Checks whether a host has data. */ public boolean hasData() { return null != this.data; @@ -145,11 +145,8 @@ public class Host { * The external load is not taken in account. * * @return The number of tasks currently running on a host. - * - * @exception InvalidHostException if the host is invalid. - * */ - public int getLoad() throws JniException { + public int getLoad() { return MsgNative.hostGetLoad(this); } @@ -159,54 +156,13 @@ public class Host { * * @return The speed of the processor of the host in flops. * - * @exception InvalidHostException if the host is not valid. - * */ - public double getSpeed() throws JniException { + public double getSpeed() { return MsgNative.hostGetSpeed(this); } - /** - * This method tests if a host is avail. - * - * @exception JniException if the host is not valid. - */ - public boolean isAvail() throws JniException { + /** This method tests if a host is avail. */ + public boolean isAvail() { return MsgNative.hostIsAvail(this); } - - /** Send the given task to mailbox identified by the default alias */ - public void send(Task task) throws JniException, NativeException { - String alias = this.getName() + ":" + Process.currentProcess().msgName(); - MsgNative.taskSend(alias, task, -1); - } - - /** Send the given task to the mailbox associated with the specified alias */ - - public void send(String alias, Task task) throws JniException, NativeException { - MsgNative.taskSend(alias, task, -1); - } - - /** Send the given task in the mailbox associated with the alias of the current host (waiting at most \a timeout seconds) */ - public void send(Task task, double timeout) throws JniException, NativeException { - String alias = this.getName() + ":" + Process.currentProcess().msgName(); - MsgNative.taskSend(alias, task, timeout); - } - - /** Send the given task to mailbox associated with the specified alias (waiting at most \a timeout seconds) */ - public void send(String alias, Task task, double timeout) throws JniException, NativeException { - MsgNative.taskSend(alias, task, timeout); - } - - /** Send the given task to the mailbox associated with the default alias (capping the emision rate to \a maxrate) */ - public void sendBounded(Task task, double maxrate) throws JniException, NativeException { - String alias = this.getName() + ":" + Process.currentProcess().msgName(); - - MsgNative.taskSendBounded(alias, task, maxrate); - } - - /** Send the given task to the mailbox associated with the specified alias (capping the emision rate to \a maxrate) */ - public void sendBounded(String alias, Task task, double maxrate) throws JniException, NativeException { - MsgNative.taskSendBounded(alias, task, maxrate); - } } diff --git a/src/java/simgrid/msg/JniException.java b/src/java/simgrid/msg/JniException.java index b884da8405..6592ef5fc8 100644 --- a/src/java/simgrid/msg/JniException.java +++ b/src/java/simgrid/msg/JniException.java @@ -12,6 +12,7 @@ package simgrid.msg; /** * This exception is raised when there is a problem within the bindings (in JNI). + * That's a RuntimeException: I guess nobody wants to survive a JNI error in SimGrid */ public class JniException extends RuntimeException { private static final long serialVersionUID = 1L; diff --git a/src/java/simgrid/msg/Msg.java b/src/java/simgrid/msg/Msg.java index 60cc292b4c..6ceeb7aecb 100644 --- a/src/java/simgrid/msg/Msg.java +++ b/src/java/simgrid/msg/Msg.java @@ -85,16 +85,14 @@ public final class Msg { * @param platformFile The XML file which contains the description of the environment of the simulation * */ - public final static native void createEnvironment(String platformFile) - throws NativeException; + public final static native void createEnvironment(String platformFile) throws NativeException; /** * The method to deploy the simulation. * * @param platformFile The XML file which contains the description of the application to deploy. */ - public final static native void deployApplication(String deploymentFile) - throws NativeException; + public final static native void deployApplication(String deploymentFile) throws NativeException; /** Example launcher. You can use it or provide your own launcher, as you wish */ static public void main(String[]args) throws MsgException { diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index 67925846e7..535420027a 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -30,12 +30,10 @@ final class MsgNative { * @param process The java process object to bind with the MSG native process. * @param host A valid (binded) host where create the process. * - * @exception simgrid.msg.JniException if JNI stuff goes wrong. - * * @see Process constructors. */ final static native - void processCreate(Process process, Host host) throws JniException; + void processCreate(Process process, Host host); /** * The natively implemented method to kill all the process of the simulation. @@ -53,12 +51,11 @@ final class MsgNative { * * @param process The valid (binded with a native process) java process to suspend. * - * @exception JniException if something goes wrong with JNI - * NativeException if the SimGrid native code failed. + * @exception NativeException if the SimGrid native code failed. * * @see Process.pause() */ - final static native void processSuspend(Process process) throws JniException, NativeException; + final static native void processSuspend(Process process) throws NativeException; /** * The natively implemented method to kill a MSG process. @@ -67,21 +64,18 @@ final class MsgNative { * * @see Process.kill() */ - final static native void processKill(Process process) - throws JniException; + final static native void processKill(Process process); /** * The natively implemented method to resume a suspended MSG process. * * @param process The valid (binded with a native process) java process to resume. * - * @exception JniException if something goes wrong with JNI - * NativeException if the SimGrid native code failed. + * @exception NativeException if the SimGrid native code failed. * * @see Process.restart() */ - final static native void processResume(Process process) - throws JniException, NativeException; + final static native void processResume(Process process) throws NativeException; /** * The natively implemented method to test if MSG process is suspended. @@ -91,12 +85,9 @@ final class MsgNative { * @return If the process is suspended the method retuns true. Otherwise the * method returns false. * - * @exception JniException if something goes wrong with JNI - * * @see Process.isSuspended() */ - final static native boolean processIsSuspended(Process process) throws - JniException; + final static native boolean processIsSuspended(Process process); /** * The natively implemented method to get the host of a MSG process. @@ -105,13 +96,11 @@ final class MsgNative { * * @return The method returns the host where the process is running. * - * @exception JniException if something goes wrong with JNI - * NativeException if the SimGrid native code failed. + * @exception NativeException if the SimGrid native code failed. * * @see Process.getHost() */ - final static native Host processGetHost(Process process) - throws JniException, NativeException; + final static native Host processGetHost(Process process) throws NativeException; /** * The natively implemented method to get a MSG process from his PID. @@ -137,8 +126,7 @@ final class MsgNative { * * @see Process.getPID() */ - final static native int processGetPID(Process process) throws - NativeException; + final static native int processGetPID(Process process) throws NativeException; /** * The natively implemented method to get the PPID of a MSG process. @@ -151,8 +139,7 @@ final class MsgNative { * * @see Process.getPPID() */ - final static native int processGetPPID(Process process) throws - NativeException; + final static native int processGetPPID(Process process) throws NativeException; /** * The natively implemented method to get the current running process. @@ -165,38 +152,18 @@ final class MsgNative { */ final static native Process processSelf() throws NativeException; - /** - * The natively implemented method to get the current running process PID. - * - * @return The PID of the current process. - * - * @see Process.currentProcessPID() - */ - final static native int processSelfPID(); - - /** - * The natively implemented method to get the current running process PPID. - * - * @return The PPID of the current process. - * - * @see Process.currentProcessPPID() - */ - final static native int processSelfPPID(); - /** * The natively implemented method to migrate a process from his currnet host to a new host. * * @param process The (valid) process to migrate. * @param host A (valid) host where move the process. * - * @exception JniException if something goes wrong with JNI - * NativeException if the SimGrid native code failed. + * @exception NativeException if the SimGrid native code failed. * * @see Process.migrate() * @see Host.getByName() */ - final static native void processChangeHost(Process process, Host host) - throws JniException, NativeException; + final static native void processChangeHost(Process process, Host host) throws NativeException; /** * The natively implemented native to request the current process to sleep @@ -208,17 +175,14 @@ final class MsgNative { * * @see Process.waitFor() */ - final static native void processWaitFor(double seconds) throws - NativeException; + final static native void processWaitFor(double seconds) throws NativeException; /** * The natively implemented native method to exit a process. * - * @exception JniException if something goes wrong with JNI - * * @see Process.exit() */ - final static native void processExit(Process process) throws JniException; + final static native void processExit(Process process); /****************************************************************** @@ -232,14 +196,12 @@ final class MsgNative { * * @return The host having the specified name. * - * @exception JniException if something goes wrong with JNI - * HostNotFoundException if there is no such host + * @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 JniException, HostNotFoundException, NativeException; + final static native Host hostGetByName(String name) throws HostNotFoundException, NativeException; /** * The natively implemented method to get the name of an MSG host. @@ -248,11 +210,9 @@ final class MsgNative { * * @return The name of the specified host. * - * @exception JniException if something goes wrong with JNI - * * @see Host.getName() */ - final static native String hostGetName(Host host) throws JniException; + final static native String hostGetName(Host host); /** * The natively implemented method to get the number of hosts of the simulation. @@ -268,11 +228,9 @@ final class MsgNative { * * @return The host of the current running process. * - * @exception JniException if something goes wrong with JNI - * * @see Host.currentHost() */ - final static native Host hostSelf() throws JniException; + final static native Host hostSelf(); /** * The natively implemented method to get the speed of a MSG host. @@ -281,12 +239,10 @@ final class MsgNative { * * @return The speed of the specified host. * - * @exception JniException if something goes wrong with JNI - * * @see Host.getSpeed() */ - final static native double hostGetSpeed(Host host) throws JniException; + final static native double hostGetSpeed(Host host); /** * The natively implemented native method to test if an host is avail. @@ -296,21 +252,17 @@ final class MsgNative { * @return If the host is avail the method returns true. * Otherwise the method returns false. * - * @exception JniException if something goes wrong with JNI - * * @see Host.isAvail() */ - final static native boolean hostIsAvail(Host host) throws JniException; + final static native boolean hostIsAvail(Host host); /** * The natively implemented native method to get all the hosts of the simulation. * - * @exception JniException if something goes wrong with JNI - * * @return A array which contains all the hosts of simulation. */ - final static native Host[] allHosts() throws JniException; + final static native Host[] allHosts(); /** * The natively implemented native method to get the number of running tasks on a host. @@ -318,11 +270,8 @@ final class MsgNative { * @param The host concerned by the operation. * * @return The number of running tasks. - * - * @exception JniException if something goes wrong with JNI - * */ - final static native int hostGetLoad(Host host) throws JniException; + final static native int hostGetLoad(Host host); /****************************************************************** * The natively implemented methods connected to the MSG task * @@ -341,15 +290,14 @@ final class MsgNative { * methods. This value has to be >= 0. * @param task The java task object to bind with the native task to create. * - * @exception JniException if something goes wrong with JNI - * IllegalArgumentException if compute duration <0 or message size <0 + * @exception IllegalArgumentException if compute duration <0 or message size <0 * * @see Task.create() */ final static native void taskCreate(Task task, String name, double computeDuration, double messageSize) - throws JniException, IllegalArgumentException; + throws IllegalArgumentException; /** * The natively implemented method to get the sender of a task. @@ -358,12 +306,9 @@ final class MsgNative { * * @return The sender of the task. * - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * * @see Task.getSender() */ - final static native Process taskGetSender(Task task) throws JniException; + final static native Process taskGetSender(Task task); /** * The natively implementd method to get the source of a task. @@ -372,13 +317,11 @@ final class MsgNative { * * @return The source of the task. * - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. + * @exception NativeException if the SimGrid native code failed. * * @see Task.getSource() */ - final static native Host taskGetSource(Task task) throws JniException, - NativeException; + final static native Host taskGetSource(Task task) throws NativeException; /** * The natively implemented method to get the name of the task. @@ -387,26 +330,20 @@ final class MsgNative { * * @return The name of the specified task. * - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * * @see Task.getName() */ - final static native String taskGetName(Task task) throws JniException; + final static native String taskGetName(Task task); /** * The natively implemented method to cancel a task. * * @param task The task to cancel. * - * @exception InvalidTaskException if the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the cancelation failed. + * @exception NativeException if the cancellation failed. * * @see Task.cancel(). */ - final static native void taskCancel(Task task) throws JniException, - NativeException; + final static native void taskCancel(Task task) throws NativeException; /** * The natively implemented method to create a MSG parallel task. @@ -423,7 +360,7 @@ final class MsgNative { Host[]hosts, double[]computeDurations, double[]messageSizes) - throws JniException, NullPointerException, IllegalArgumentException; + throws NullPointerException, IllegalArgumentException; /** * The natively implemented method to get the computing amount of the task. @@ -432,14 +369,9 @@ final class MsgNative { * * @return The computing amount of the specified task. * - * @exception InvalidTaskException if the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the cancelation failed. - * * @see Task.getComputeDuration() */ - final static native double taskGetComputeDuration(Task task) throws - JniException; + final static native double taskGetComputeDuration(Task task); /** * The natively implemented method to get the remaining computation @@ -448,14 +380,9 @@ final class MsgNative { * * @return The remaining computation of the specified task. * - * @exception InvalidTaskException if the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the cancelation failed. - * * @see Task.getRemainingDuration() */ - final static native double taskGetRemainingDuration(Task task) throws - JniException; + final static native double taskGetRemainingDuration(Task task); /** * The natively implemented method to set the priority of a task. @@ -464,43 +391,31 @@ final class MsgNative { * * @param priority The new priority of the specified task. * - * @exception InvalidTaskException if the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the cancelation failed. - * * @see Task.setPriority() */ - final static native void taskSetPriority(Task task, - double priority) throws - JniException; + final static native void taskSetPriority(Task task, double priority); /** * The natively implemented method to destroy a MSG task. * * @param The task to destroy. * - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the destruction failed. + * @exception NativeException on error in the C world * * @see Task.destroy() */ - final static native void taskDestroy(Task task) throws JniException, - NativeException; + final static native void taskDestroy(Task task) throws NativeException; /** * The natively implemented method to execute a MSG task. * * @param task The task to execute. * - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. - * MsgException if the destruction failed. + * @exception NativeException on error in the C world * * @see Task.execute() */ - final static native void taskExecute(Task task) throws JniException, - NativeException; + final static native void taskExecute(Task task) throws NativeException; @@ -509,22 +424,11 @@ final class MsgNative { **************************************************************** */ - final static native void taskSend(String alias, Task task, double timeout) - throws JniException, NativeException; - - - final static native Task taskReceive(String alias, double timeout, Host host) - throws JniException, NativeException; - - final static native int taskListenFrom(String alias) - throws JniException, NativeException; - - - final static native boolean taskListen(String alias) - throws JniException; - - final static native int taskListenFromHost(String alias, Host host) - throws JniException; + final static native void taskSend(String alias, Task task, double timeout) throws NativeException; + 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 boolean taskListen(String alias); + final static native int taskListenFromHost(String alias, Host host); /* *************************************************************** * Task sending methods * @@ -538,11 +442,8 @@ final class MsgNative { * @param task The task to put. * @param max_rate The bounded transmition rate. * - * @exception InvalidTaskException if the task is not valid. - * InvalidHostException if the host is not valid. - * MsgException if the operation failed. + * @exception NativeException on error in the C world */ - final static native void taskSendBounded(String alias, Task task, double maxrate) - throws JniException, NativeException; + final static native void taskSendBounded(String alias, Task task, double maxrate) throws NativeException; } diff --git a/src/java/simgrid/msg/NativeException.java b/src/java/simgrid/msg/NativeException.java index 1882a61bf4..deffee5732 100644 --- a/src/java/simgrid/msg/NativeException.java +++ b/src/java/simgrid/msg/NativeException.java @@ -17,13 +17,6 @@ package simgrid.msg; public class NativeException extends MsgException { private static final long serialVersionUID = 1L; - /* - * Constructs an NativeException without a - * detail message. - * - public NativeException() { - super(); - }*/ /** * Constructs an NativeException with a detail message. * diff --git a/src/java/simgrid/msg/Process.java b/src/java/simgrid/msg/Process.java index e173b1d279..5a0fafc52a 100644 --- a/src/java/simgrid/msg/Process.java +++ b/src/java/simgrid/msg/Process.java @@ -86,7 +86,7 @@ public abstract class Process extends Thread { */ protected Process() { super(); - this.id = 0; + this.id = nextProcessId++; this.name = null; this.bind = 0; this.args = new Vector(); @@ -104,14 +104,10 @@ public abstract class Process extends Thread { * @param name The name of the process. * * @exception HostNotFoundException if no host with this name exists. - * NullPointerException if the provided name is null - * JniException on JNI madness * NativeException * */ - public Process(String hostname, String name) - throws NullPointerException, HostNotFoundException, JniException, - NativeException { + public Process(String hostname, String name) throws HostNotFoundException, NativeException { this(Host.getByName(hostname), name, null); } /** @@ -123,13 +119,10 @@ public abstract class Process extends Thread { * @param args The arguments of the main function of the process. * * @exception HostNotFoundException if no host with this name exists. - * NullPointerException if the provided name is null - * JniException on JNI madness + * NativeException * */ - public Process(String hostname, String name, String args[]) - throws NullPointerException, HostNotFoundException, JniException, - NativeException { + public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException { this(Host.getByName(hostname), name, args); } /** @@ -139,12 +132,8 @@ public abstract class Process extends Thread { * @param host The host of the process to create. * @param name The name of the process. * - * @exception NullPointerException if the provided name is null - * JniException on JNI madness - * */ - public Process(Host host, String name) throws NullPointerException, - JniException { + public Process(Host host, String name) { this(host, name, null); } /** @@ -155,30 +144,19 @@ public abstract class Process extends Thread { * @param name The name of the process. * @param args The arguments of main method of the process. * - * @exception NullPointerException if the provided name is null - * JniException on JNI madness - * */ - public Process(Host host, String name, - String[]args) throws NullPointerException, JniException { + public Process(Host host, String name, String[]args) { /* This is the constructor called by all others */ - + this(); + if (name == null) throw new NullPointerException("Process name cannot be NULL"); - - this.properties = null; + this.name = name; this.args = new Vector(); - if (null != args) this.args.addAll(Arrays.asList(args)); - this.name = name; - this.id = nextProcessId++; - - schedBegin = new Sem(0); - schedEnd = new Sem(0); - MsgNative.processCreate(this, host); } @@ -203,56 +181,52 @@ public abstract class Process extends Thread { * * @param arg The argument to add. */ + @Deprecated protected void addArg(String arg) { args.add(arg); } /** - * This method suspends the process by suspending the task on which it was + * Suspends the process by suspending the task on which it was * waiting for the completion. * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code + * @exception NativeException on error in the native SimGrid code */ - public void pause() throws JniException, NativeException { + public void pause() throws NativeException { MsgNative.processSuspend(this); } /** - * This method resumes a suspended process by resuming the task on which it was + * Resumes a suspended process by resuming the task on which it was * waiting for the completion. * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code + * @exception NativeException on error in the native SimGrid code * */ - public void restart() throws JniException, NativeException { + public void restart() throws NativeException { MsgNative.processResume(this); } /** - * This method tests if a process is suspended. + * Tests if a process is suspended. * * @return The method returns true if the process is suspended. * Otherwise the method returns false. - * - * @exception JniException on JNI madness */ - public boolean isSuspended() throws JniException { + public boolean isSuspended() { return MsgNative.processIsSuspended(this); } /** - * This method returns the host of a process. + * Returns the host of a process. * * @return The host instance of the process. * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code + * @exception NativeException on error in the native SimGrid code * */ - public Host getHost() throws JniException, NativeException { + public Host getHost() throws NativeException { return MsgNative.processGetHost(this); } /** - * This static method get a process from a PID. + * This static method gets a process from a PID. * * @param PID The process identifier of the process to get. * @@ -268,10 +242,9 @@ public abstract class Process extends Thread { * * @return The PID of the process. * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code + * @exception NativeException on error in the native SimGrid code */ - public int getPID() throws JniException, NativeException { + public int getPID() throws NativeException { return MsgNative.processGetPID(this); } /** @@ -290,43 +263,22 @@ 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 { return MsgNative.processSelf(); } /** - * This static method returns the PID of the currently running process. - * - * @return The PID of the current process. - */ - public static int currentProcessPID() { - return MsgNative.processSelfPID(); - } - - /** - * This static method returns the PID of the parent of the currently running process. - * - * @return The PID of the parent of current process. - */ - public static int currentProcessPPID() { - return MsgNative.processSelfPPID(); - } - - /** - * This function migrates a process to another host. + * Migrates a process to another host. * * @param host The host where to migrate the process. * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code + * @exception NativeException on error in the native SimGrid code */ - public void migrate(Host host) throws JniException, NativeException { + public void migrate(Host host) throws NativeException { MsgNative.processChangeHost(this, host); } /** - * This method makes the current process sleep until time seconds have elapsed. + * Makes the current process sleep until time seconds have elapsed. * * @param seconds The time the current process must sleep. * @@ -382,7 +334,7 @@ public abstract class Process extends Thread { /** * The main function of the process (to implement). */ - public abstract void main(String[]args) throws JniException, NativeException; + public abstract void main(String[]args) throws NativeException; public void unschedule() { @@ -402,32 +354,32 @@ public abstract class Process extends Thread { } /** Send the given task in the mailbox associated with the specified alias (waiting at most given time) */ - public void taskSend(String mailbox, Task task, double timeout) throws NativeException, JniException { + public void taskSend(String mailbox, Task task, double timeout) throws NativeException { MsgNative.taskSend(mailbox, task, timeout); } /** Send the given task in the mailbox associated with the specified alias*/ - public void taskSend(String mailbox, Task task) throws NativeException, JniException { + public void taskSend(String mailbox, Task task) throws NativeException { MsgNative.taskSend(mailbox, task, -1); } /** Receive a task on mailbox associated with the specified mailbox */ - public Task taskReceive(String mailbox) throws NativeException, JniException { + public Task taskReceive(String mailbox) throws NativeException { 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, JniException { + public Task taskReceive(String mailbox, double timeout) throws NativeException { 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, JniException { + public Task taskReceive(String mailbox, double timeout, Host host) throws NativeException { 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, JniException { + public Task taskReceive(String mailbox, Host host) throws NativeException { return MsgNative.taskReceive(mailbox, -1.0, host); } } diff --git a/src/java/simgrid/msg/Task.java b/src/java/simgrid/msg/Task.java index bdd7e60322..52f48b4bc2 100644 --- a/src/java/simgrid/msg/Task.java +++ b/src/java/simgrid/msg/Task.java @@ -25,8 +25,8 @@ public class Task { public long bind = 0; - /* Default constructor (disabled) */ - public Task() throws JniException { + /** Default constructor (all fields to 0 or null) */ + public Task() { MsgNative.taskCreate(this, null, 0, 0); } /* * * * @@ -45,10 +45,8 @@ public class Task { * @param messageSize A value of amount of data (in bytes) needed to transfert this task. * If 0, then it cannot be transfered with the get() and put() methods. * This value has to be >= 0. - * - * @exception JniException if the binding mechanism fails. */ - public Task(String name, double computeDuration, double messageSize) throws JniException { + public Task(String name, double computeDuration, double messageSize) { MsgNative.taskCreate(this, name, computeDuration, messageSize); } /** @@ -59,44 +57,31 @@ public class Task { * @param hosts The list of hosts implied by the parallel task. * @param computeDurations The amount of operations to be performed by each host of \a hosts. * @param messageSizes A matrix describing the amount of data to exchange between hosts. - * - * @exception JniException if the binding mecanism fails. */ - public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) throws JniException { + public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) { MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes); } /* * * * * * Getters / Setters * * * * * */ - /** gets the name of a task. - * @exception JniException if the binding mechanism fails. - */ - public String getName() throws JniException { + /** Gets the name of a task */ + public String getName() { return MsgNative.taskGetName(this); } - /** gets the sender of the task. - * @exception JniException if the binding mechanism fails. - * - */ - Process getSender() throws JniException { + /** Gets the sender of the task */ + Process getSender() { return MsgNative.taskGetSender(this); } - /** Gets the source of the task. - * @exception JniException if the binding mechanism fails. - */ - public Host getSource() throws JniException, NativeException { + /** Gets the source of the task */ + public Host getSource() throws NativeException { return MsgNative.taskGetSource(this); } - /** gets the computing amount of the task. - * @exception JniException if the binding mechanism fails. - */ - public double getComputeDuration() throws JniException { + /** Gets the computing amount of the task */ + public double getComputeDuration() { return MsgNative.taskGetComputeDuration(this); } - /** gets the remaining computation of the task. - * @exception JniException if the binding mechanism fails. - */ - public double getRemainingDuration() throws JniException { + /** Gets the remaining computation of the task */ + public double getRemainingDuration() { return MsgNative.taskGetRemainingDuration(this); } /** @@ -106,10 +91,8 @@ public class Task { * the other ones. * * @param priority The new priority of the task. - * - * @exception JniException is the specified task is not valid (ie, not binded to a native task) */ - public void setPriority(double priority) throws JniException { + public void setPriority(double priority) { MsgNative.taskSetPriority(this, priority); } /* * * * @@ -121,132 +104,118 @@ public class Task { * * Computation-related * * * * * */ /** - * This method execute a task on the location on which the - * process is running. + * Executes a task on the location on which the process is running. * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the execution failed. */ - public void execute() throws JniException, NativeException { + public void execute() throws NativeException { MsgNative.taskExecute(this); } /** - * This method cancels a task. + * Cancels a task. * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the cancellation failed. */ - public void cancel() throws JniException, NativeException { + public void cancel() throws NativeException { MsgNative.taskCancel(this); } /** Deletes a task. * - * @exception JniException if the binding mechanism fails - * NativeException if the destruction failed. + * @exception NativeException if the destruction failed. */ - protected void finalize() throws JniException, NativeException { + protected void finalize() throws NativeException { if (this.bind != 0) MsgNative.taskDestroy(this); } /** - * Send the task on the mailbox identified by the specified name + * Sends the task on the mailbox identified by the specified name * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public void send(String mailbox) throws JniException,NativeException { + public void send(String mailbox) throws NativeException { MsgNative.taskSend(mailbox, this, -1); } /** - * Send the task on the mailbox identified by the specified name (wait at most \a timeout seconds) + * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds) * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public void send(String mailbox, double timeout) throws JniException,NativeException { + public void send(String mailbox, double timeout) throws NativeException { MsgNative.taskSend(mailbox, this, timeout); } /** - * Send the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) + * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public void sendBounded(String alias, double maxrate) throws JniException,NativeException { + public void sendBounded(String alias, double maxrate) throws NativeException { MsgNative.taskSendBounded(alias, this, maxrate); } /** * Retrieves next task from the mailbox identified by the specified name * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static Task receive(String mailbox) throws JniException, NativeException { + public static Task receive(String mailbox) throws NativeException { 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 JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static Task receive(String mailbox, double timeout) throws JniException, NativeException { + public static Task receive(String mailbox, double timeout) throws NativeException { return MsgNative.taskReceive(mailbox, timeout, null); } /** * Retrieves next task sent by a given host on the mailbox identified by the specified alias * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static Task receive(String mailbox, Host host) throws JniException, NativeException { + public static Task receive(String mailbox, Host host) throws NativeException { 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 JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static Task receive(String mailbox, double timeout, Host host) throws JniException, NativeException { + public static Task receive(String mailbox, double timeout, Host host) throws NativeException { return MsgNative.taskReceive(mailbox, timeout, host); } /** - * Test whether there is a pending communication on the mailbox identified by the specified alias, and who sent it + * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static int listenFrom(String mailbox) throws JniException, NativeException { + public static int listenFrom(String mailbox) throws NativeException { return MsgNative.taskListenFrom(mailbox); } /** * Listen whether there is a waiting task on the mailbox identified by the specified alias * - * @exception JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static boolean listen(String mailbox) throws JniException, NativeException { + public static boolean listen(String mailbox) throws NativeException { 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 JniException if the binding mechanism fails. * @exception NativeException if the retrieval fails. */ - public static int listenFromHost(String alias, Host host) throws JniException, NativeException { + public static int listenFromHost(String alias, Host host) throws NativeException { return MsgNative.taskListenFromHost(alias, host); } } -- 2.20.1