From: mquinson Date: Sat, 27 Feb 2010 23:06:30 +0000 (+0000) Subject: various cleanups to the java bindings X-Git-Tag: SVN~598 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/78c34e74fbe28d492254148c6b3d3fc2a37133f1 various cleanups to the java bindings git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7140 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/ChangeLog b/ChangeLog index 8482646c3e..37be72d27f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,12 @@ SimGrid (3.3.5-svn) unstable; urgency=low * Kill the useless "rate" argument of SD_task_get_execution_time() Everyone used to provide -1 as a value, it was not used, and the semantic of a possible use wasn't even clear. + Java Bindings: Various Cleanups + * Remove put/get: no need to export deprecated interface in Java + 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) -- Da SimGrid team diff --git a/src/Makefile.am b/src/Makefile.am index 0a5134520c..ce1e167dda 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -240,7 +240,6 @@ JMSG_C_SRC = \ simix/smx_context_java.c \ java/jxbt_utilities.c java/jxbt_utilities.h \ java/jmsg.c java/jmsg.h \ - java/jmsg_channel.c java/jmsg_channel.h \ java/jmsg_host.c java/jmsg_host.h \ java/jmsg_process.c java/jmsg_process.h \ java/jmsg_task.c java/jmsg_task.h \ diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 22d3a02e07..c1d65dfc4a 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -17,7 +17,6 @@ #include "jmsg_process.h" #include "jmsg_host.h" #include "jmsg_task.h" -#include "jmsg_channel.h" #include "jmsg_application_handler.h" #include "jxbt_utilities.h" @@ -790,118 +789,9 @@ Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls, } /*************************************************************************************** - * The Task reception functions * + * Unsortable functions * ***************************************************************************************/ -JNIEXPORT jobject JNICALL -Java_simgrid_msg_MsgNative_taskGet(JNIEnv * env, jclass cls, - jint chan_id, jdouble jtimeout, - jobject jhost) -{ - m_task_t task = NULL; - m_host_t host = NULL; - - if (jhost) { - host = jhost_get_native(env, jhost); - if (!host) { - jxbt_throw_notbound(env, "host", jhost); - return NULL; - } - } - - if (MSG_OK != - MSG_task_get_ext(&task, (int) chan_id, (double) jtimeout, host)) { - jxbt_throw_native(env, xbt_strdup("MSG_task_get_ext() failed")); - return NULL; - } - - return (jobject) task->data; -} - - -JNIEXPORT jboolean JNICALL -Java_simgrid_msg_MsgNative_taskProbe(JNIEnv * env, jclass cls, jint chan_id) -{ - return (jboolean) MSG_task_Iprobe(chan_id); -} - -JNIEXPORT jobject JNICALL -Java_simgrid_msg_MsgNative_taskGetCommunicatingProcess(JNIEnv * env, - jclass cls, - jint chan_id) -{ - int pid = MSG_task_probe_from(chan_id); - if (pid >= 0) - return Java_simgrid_msg_MsgNative_processFromPID(env, cls, (jint) pid); - - return NULL; -} - -JNIEXPORT jint JNICALL -Java_simgrid_msg_MsgNative_taskProbeHost(JNIEnv * env, jclass cls, - jobject jhost, jint chan_id) -{ - m_host_t host = jhost_get_native(env, jhost); - - if (!host) { - jxbt_throw_notbound(env, "host", jhost); - return -1; - } - - return (jint) MSG_task_probe_from_host(chan_id, host); -} - - -/*************************************************************************************** - * The Task reception functions * - ***************************************************************************************/ - - -JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_hostPut(JNIEnv * env, jclass cls, - jobject jhost, jint chan_id, jobject jtask, - jdouble jtimeout) -{ - m_task_t task = jtask_to_native_task(jtask, env); - m_host_t host = jhost_get_native(env, jhost); - - if (!host) { - jxbt_throw_notbound(env, "host", jhost); - return; - } - if (!task) { - jxbt_throw_notbound(env, "task", jtask); - return; - } - - if (MSG_OK != - MSG_task_put_with_timeout(task, host, (int) chan_id, (double) jtimeout)) - jxbt_throw_native(env, xbt_strdup("MSG_task_put_with_timeout() failed")); -} - - - -JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_hostPutBounded(JNIEnv * env, jclass cls, - jobject jhost, jint chan_id, - jobject jtask, jdouble jmaxRate) -{ - m_task_t task = jtask_to_native_task(jtask, env); - m_host_t host = jhost_get_native(env, jhost); - - if (!host) { - jxbt_throw_notbound(env, "host", jhost); - return; - } - if (!task) { - jxbt_throw_notbound(env, "task", jtask); - return; - } - - if (MSG_OK != - MSG_task_put_bounded(task, host, (int) chan_id, (double) jmaxRate)) - jxbt_throw_native(env, xbt_strdup("MSG_task_put_bounded() failed")); -} JNIEXPORT jint JNICALL Java_simgrid_msg_Msg_getErrCode(JNIEnv * env, jclass cls) @@ -917,9 +807,7 @@ Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) JNIEXPORT void JNICALL -Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) -{ - +Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) { char **argv = NULL; int index; int argc = 0; @@ -930,23 +818,17 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) argc = (int) (*env)->GetArrayLength(env, jargs); argc++; - argv = xbt_new0(char *, argc); - argv[0] = strdup("java"); for (index = 0; index < argc - 1; index++) { jval = (jstring) (*env)->GetObjectArrayElement(env, jargs, index); - tmp = (*env)->GetStringUTFChars(env, jval, 0); - argv[index + 1] = strdup(tmp); - (*env)->ReleaseStringUTFChars(env, jval, tmp); } MSG_global_init(&argc, argv); - MSG_set_channel_number(10); /* FIXME: this should not be fixed statically */ SIMIX_context_select_factory("java"); for (index = 0; index < argc; index++) @@ -955,12 +837,10 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) free(argv); (*env)->GetJavaVM(env, &__java_vm); - } JNIEXPORT void JNICALL - JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) -{ + JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) { xbt_fifo_item_t item = NULL; m_host_t host = NULL; jobject jhost; @@ -1022,17 +902,6 @@ Java_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls, SIMIX_context_stop(SIMIX_process_self()->context); } -JNIEXPORT void JNICALL -Java_simgrid_msg_Msg_pajeOutput(JNIEnv * env, jclass cls, jstring jpajeFile) -{ - const char *pajeFile = (*env)->GetStringUTFChars(env, jpajeFile, 0); - - MSG_paje_output(pajeFile); - - (*env)->ReleaseStringUTFChars(env, jpajeFile, pajeFile); -} - - JNIEXPORT void JNICALL Java_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js) { diff --git a/src/java/jmsg.h b/src/java/jmsg.h index a135716308..3fbb9bf409 100644 --- a/src/java/jmsg.h +++ b/src/java/jmsg.h @@ -272,63 +272,14 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskDestroy JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskExecute (JNIEnv *, jclass, jobject); -/* - * Class simgrid_msg_Msg - * Method taskGetWithTimeout - * Signature (I;D;Lsimgrid/msg/Host;)Lsimgrid/msg/Task; - */ -JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGet - (JNIEnv *, jclass, jint, jdouble, jobject); - JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskReceive (JNIEnv *, jclass, jstring, jdouble, jobject); -/* - * Class simgrid_msg_Msg - * Method taskHasPendingCommunication - * Signature (I)Z - */ -JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_taskProbe - (JNIEnv *, jclass, jint); - -/* - * Class simgrid_msg_Msg - * Method taskGetCommunicatingProcess - * Signature (I)Lsimgrid/msg/Process; - */ -JNIEXPORT jobject JNICALL -Java_simgrid_msg_MsgNative_taskGetCommunicatingProcess(JNIEnv *, jclass, - jint); - -/* - * Class simgrid_msg_Msg - * Method taskGetHostWaitingTasks - * Signature (Lsimgrid/msg/Host;I)I - */ -JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_taskProbeHost - (JNIEnv *, jclass, jobject, jint); - -/* - * Class simgrid_msg_Msg - * Method hostPutWith - * Signature (Lsimgrid/msg/Host;I;Lsimgrid/msg/Task;D)V - */ -JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_hostPut - (JNIEnv *, jclass, jobject, jint, jobject, jdouble); - JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSend (JNIEnv *, jclass, jstring, jobject, jdouble); -/* - * Class simgrid_msg_Msg - * Method hostPutBounded - * Signature (Lsimgrid/msg/Host;I;Lsimgrid/msg/Task;D)V - */ -JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_hostPutBounded - (JNIEnv *, jclass, jobject, jint, jobject, jdouble); - /* * Class simgrid_msg_Msg * Method getErrCode @@ -365,9 +316,6 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processKillAll JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processExit (JNIEnv *, jclass, jobject); -JNIEXPORT void JNICALL -Java_simgrid_msg_Msg_pajeOutput(JNIEnv * env, jclass cls, jstring jpajeFile); - JNIEXPORT void JNICALL Java_simgrid_msg_Msg_info(JNIEnv *, jclass, jstring); JNIEXPORT jobjectArray JNICALL diff --git a/src/java/simgrid/msg/ApplicationHandler.java b/src/java/simgrid/msg/ApplicationHandler.java index 34803da7d4..3c8cd35aac 100644 --- a/src/java/simgrid/msg/ApplicationHandler.java +++ b/src/java/simgrid/msg/ApplicationHandler.java @@ -1,13 +1,12 @@ /* + * These are the upcalls used by the FleXML parser for application files * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid team. * All right reserved. * * This program is free software; you can redistribute * it and/or modify it under the terms of the license * (GNU LGPL) which comes with this package. - * - * These are the upcalls used by the FleXML parser for application files */ package simgrid.msg; @@ -15,19 +14,6 @@ package simgrid.msg; import java.util.Vector; import java.util.Hashtable; -/** - * The handler used to parse the deployment file which contains - * the description of the application (simulation). - * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @version 1.00, 07/05/01 - * @see Host - * @see Process - * @see Simulation - * @since SimGrid 3.3 - * @since JDK1.5011 - */ public final class ApplicationHandler { /* @@ -114,7 +100,7 @@ public final class ApplicationHandler { Host host = Host.getByName(this.hostName); MsgNative.processCreate(process, host); - Vector args = processFactory.args; + Vector args = processFactory.args; int size = args.size(); for (int index = 0; index < size; index++) diff --git a/src/java/simgrid/msg/Host.java b/src/java/simgrid/msg/Host.java index 101ef96795..97ef2c20c9 100644 --- a/src/java/simgrid/msg/Host.java +++ b/src/java/simgrid/msg/Host.java @@ -1,7 +1,7 @@ /* - * simgrid.msg.Host.java 1.00 07/05/01 + * Bindings to the MSG hosts * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -9,7 +9,7 @@ *(GNU LGPL) which comes with this package. * */ - package simgrid.msg; +package simgrid.msg; import java.lang.String; /** @@ -17,10 +17,10 @@ import java.lang.String; * Thus it is represented as a physical resource with computing capabilities, some * mailboxes to enable running process to communicate with remote ones, and some private * data that can be only accessed by local process. An instance of this class is always - * binded with the corresponding native host. All the native hosts are automaticaly created + * binded with the corresponding native host. All the native hosts are automatically created * during the call of the method Msg.createEnvironment(). This method take as parameter a * platform file which describes all elements of the platform (host, link, root..). - * You never need to create an host your self. + * You cannot create a host yourself. * * The best way to get an host instance is to call the static method * Host.getByName(). @@ -39,33 +39,30 @@ try { ... \endverbatim * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @since SimGrid 3.3 */ - public class Host { - - /** +public class Host { + + /** * This attribute represents a bind between a java host object and * a native host. Even if this attribute is public you must never - * access to it. It is set automaticatly during the call of the + * access to it. It is set automatically during the call of the * static method Host.getByName(). * * @see Host.getByName(). */ - public long bind; + public long bind; + - - /** + /** * User data. */ - private Object data; - protected Host() { - this.bind = 0; - this.data = null; - }; - - /** + private Object data; + protected Host() { + this.bind = 0; + this.data = null; + }; + + /** * This static method gets an host instance associated with a native * host of your platform. This is the best way to get a java host object. * @@ -74,76 +71,76 @@ try { * @exception HostNotFoundException if the name of the host is not valid. * MsgException if the native version of this method failed. */ - public static Host getByName(String name) - throws HostNotFoundException, NativeException, JniException { - return MsgNative.hostGetByName(name); - } - - /** - * This static method returns the number of the installed hosts. + public static Host getByName(String name) + throws HostNotFoundException, NativeException, JniException { + return MsgNative.hostGetByName(name); + } + + /** + * This static method returns the count of the installed hosts. * - * @return The number of the installed hosts. + * @return The count of the installed hosts. * */ - public static int getNumber() throws NativeException, JniException { - return MsgNative.hostGetNumber(); - } - - /** + public static int getCount() throws NativeException, JniException { + return MsgNative.hostGetCount(); + } + + /** * 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 { - return MsgNative.hostSelf(); - } - - /** + public static Host currentHost() throws JniException { + return MsgNative.hostSelf(); + } + + /** * This static method returns all of the hosts of the installed platform. * * @return An array containing all the hosts installed. * * @exception MsgException if the native version of this method failed. */ - public static Host[] all() throws JniException, NativeException { - return MsgNative.allHosts(); - } - - /** + public static Host[] all() throws JniException, NativeException { + return MsgNative.allHosts(); + } + + /** * This method returns the name of a host. * * @return The name of the host. * * @exception InvalidHostException if the host is not valid. */ - public String getName() throws NativeException, JniException { - return MsgNative.hostGetName(this); - } - - /** + public String getName() throws NativeException, JniException { + return MsgNative.hostGetName(this); + } + + /** * This method sets the data of the host. * */ - public void setData(Object data) { - this.data = data; - } - /** + public void setData(Object data) { + this.data = data; + } + /** * This method gets the data of the host. */ - public Object getData() { - return this.data; - } - - /** + public Object getData() { + return this.data; + } + + /** * This function tests if a host has data. */ - public boolean hasData() { - return null != this.data; - } - - /** + public boolean hasData() { + return null != this.data; + } + + /** * This method returns the number of tasks currently running on a host. * The external load is not taken in account. * @@ -152,11 +149,11 @@ try { * @exception InvalidHostException if the host is invalid. * */ - public int getLoad() throws JniException { - return MsgNative.hostGetLoad(this); - } - - /** + public int getLoad() throws JniException { + return MsgNative.hostGetLoad(this); + } + + /** * This method returns the speed of the processor of a host, * regardless of the current load of the machine. * @@ -165,73 +162,51 @@ try { * @exception InvalidHostException if the host is not valid. * */ - public double getSpeed() throws JniException { - return MsgNative.hostGetSpeed(this); - } - - /** + public double getSpeed() throws JniException { + 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 { - return MsgNative.hostIsAvail(this); - } - - /** Send the given task to the given channel of the host */ - - public void put(int channel, Task task) throws JniException, - NativeException { - MsgNative.hostPut(this, channel, task, -1); - } - /** Send the given task to the given channel of the host (waiting at most \a timeout seconds) */ - - public void put(int channel, Task task, - double timeout) throws JniException, NativeException { - MsgNative.hostPut(this, channel, task, timeout); - } - - - /** Send the given task to the given channel of the host (capping the emision rate to \a maxrate) */ - - public void putBounded(int channel, Task task, - double maxrate) throws JniException, - NativeException { - MsgNative.hostPutBounded(this, channel, task, maxrate); + public boolean isAvail() throws JniException { + return MsgNative.hostIsAvail(this); } - - /** Send the given task to mailbox identified by the default alias */ + + /** 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); - } - + 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); - } + + 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/HostNotFoundException.java b/src/java/simgrid/msg/HostNotFoundException.java index e39018f03e..d0e852f282 100644 --- a/src/java/simgrid/msg/HostNotFoundException.java +++ b/src/java/simgrid/msg/HostNotFoundException.java @@ -1,7 +1,7 @@ /* - * $Id$ + * This exception is raised when looking for a non-existing host. * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -15,22 +15,18 @@ package simgrid.msg; * This exception is raised when looking for a non-existing host. */ public class HostNotFoundException extends MsgException { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L; - /* - * Constructs an HostNotFoundException without a - * detail message. - */ - public HostNotFoundException() { - super(); - } - /* - * Constructs an HostNotFoundException with a detail message. - * - * @param s the detail message. - */ - public HostNotFoundException(String s) { - super(s); - } + /** Constructs an HostNotFoundException without a detail message. */ + public HostNotFoundException() { + super(); + } + /** + * Constructs an HostNotFoundException with a detail message. + * + * @param s the detail message. + */ + public HostNotFoundException(String s) { + super(s); + } } diff --git a/src/java/simgrid/msg/JniException.java b/src/java/simgrid/msg/JniException.java index 13479b8fea..af78f6f834 100644 --- a/src/java/simgrid/msg/JniException.java +++ b/src/java/simgrid/msg/JniException.java @@ -1,7 +1,7 @@ /* - * $Id$ + * This exception is raised when there is a problem within the bindings (in JNI). * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -14,20 +14,21 @@ package simgrid.msg; * This exception is raised when there is a problem within the bindings (in JNI). */ public class JniException extends MsgException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /* - * Constructs an JniException without a - * detail message. - */ - public JniException() { - super(); - } - /* - * Constructs an JniException with a detail message. - * - * @param s the detail message. - */ public JniException(String s) { - super(s); -}} + /** + * Constructs an JniException without a + * detail message. + */ + public JniException() { + super(); + } + /** + * Constructs an JniException with a detail message. + * + * @param s the detail message. + */ public JniException(String s) { + super(s); + } +} diff --git a/src/java/simgrid/msg/Msg.java b/src/java/simgrid/msg/Msg.java index 75c4952a71..60cc292b4c 100644 --- a/src/java/simgrid/msg/Msg.java +++ b/src/java/simgrid/msg/Msg.java @@ -1,137 +1,116 @@ /* - * simgrid.msg.Msg.java 1.00 07/05/01 - * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * JNI interface to C code for MSG. + * + * Copyright 2006,2007,2010 The SimGrid Team. * All right reserved. * * This program is free software; you can redistribute * it and/or modify it under the terms of the license - *(GNU LGPL) which comes with this package. + * (GNU LGPL) which comes with this package. */ package simgrid.msg; -import org.xml.sax.*; - -/** - * MSG was the first distributed programming environment - * provided within SimGrid. While almost realistic, it - * remains quite simple. - * This class contains all the declaration of the natives methods - * of the MSG API. - * All of these methods are statics. You can't directly use these methods - * but it is recommanded to use the classes Process, Host and Task - * of the package to build your application. - * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @since SimGrid 3.3 - */ + public final class Msg { - /* - * Statically load the library which contains all native functions used in here - */ - static { - try { - System.loadLibrary("simgrid"); - } catch(UnsatisfiedLinkError e) { - System.err.println("Cannot load simgrid library : "); - e.printStackTrace(); - System.err.println("Please check your LD_LIBRARY_PATH, " + - "or copy the library to the current directory"); - System.exit(1); - } - } - - /** Returns the last error code of the simulation */ - public final static native int getErrCode(); - - /** Everything is right. Keep on goin the way ! */ - public static final int SUCCESS = 0; - - /** Something must be not perfectly clean (but I may be paranoid freak...) */ - public static final int WARNING = 1; - - /** There has been a problem during you task treansfer. - * Either the network is down or the remote host has been shutdown */ - public static final int TRANSFERT_FAILURE = 2; - - /** System shutdown. - * The host on which you are running has just been rebooted. - * Free your datastructures and return now ! */ - public static final int HOST_FAILURE = 3; - - /** Cancelled task. This task has been cancelled by somebody ! */ - public static final int TASK_CANCELLLED = 4; - - /** You've done something wrong. You'd better look at it... */ - public static final int FATAL_ERROR = 5; - - - - /** Retrieve the simulation time */ - public final static native double getClock(); - - public final static native void pajeOutput(String pajeFile); - - - /** Issue an information logging message */ - public final static native void info(String s); - - /********************************************************************************* - * Deployment and initialization related functions * - *********************************************************************************/ - - /** - * The natively implemented method to initialize a MSG simulation. - * - * @param args The arguments of the command line of the simulation. - * - * @see Msg.init() - */ - public final static native void init(String[]args); - - /** - * Run the MSG simulation, and cleanup everything afterward. - * - * If you want to chain simulations in the same process, you - * should call again createEnvironment and deployApplication afterward. - * - * @see MSG_run, MSG_clean - */ - public final static native void run() throws NativeException; - - /** - * The native implemented method to create the environment of the simulation. - * - * @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; - - /** - * 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; - - /* The launcher */ - static public void main(String[]args) throws MsgException { - /* initialize the MSG simulation. Must be done before anything else (even logging). */ - Msg.init(args); - - if (args.length < 2) { - Msg.info("Usage: Msg platform_file deployment_file"); - System.exit(1); - } - - /* Load the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - /* Execute the simulation */ - Msg.run(); - } + /* Statically load the library which contains all native functions used in here */ + static { + try { + System.loadLibrary("simgrid"); + } catch(UnsatisfiedLinkError e) { + System.err.println("Cannot load simgrid library: "); + e.printStackTrace(); + System.err.println( + "Please check your LD_LIBRARY_PATH, or copy the library to the current directory"); + System.exit(1); + } + } + + /** Returns the last error code of the simulation */ + public final static native int getErrCode(); + + /** Everything is right. Keep on going the way ! */ + public static final int SUCCESS = 0; + + /** Something must be not perfectly clean (but I may be paranoid freak...) */ + public static final int WARNING = 1; + + /** There has been a problem during you task transfer. + * Either the network is down or the remote host has been shutdown */ + public static final int TRANSFERT_FAILURE = 2; + + /** System shutdown. + * The host on which you are running has just been rebooted. + * Free your data structures and return now ! */ + public static final int HOST_FAILURE = 3; + + /** Canceled task. This task has been canceled by somebody ! */ + public static final int TASK_CANCELLLED = 4; + + /** You've done something wrong. You'd better look at it... */ + public static final int FATAL_ERROR = 5; + + + /** Retrieve the simulation time */ + public final static native double getClock(); + + /** Issue an information logging message */ + public final static native void info(String s); + + /********************************************************************************* + * Deployment and initialization related functions * + *********************************************************************************/ + + /** + * The natively implemented method to initialize a MSG simulation. + * + * @param args The arguments of the command line of the simulation. + * + * @see Msg.init() + */ + public final static native void init(String[]args); + + /** + * Run the MSG simulation, and cleanup everything afterward. + * + * If you want to chain simulations in the same process, you + * should call again createEnvironment and deployApplication afterward. + * + * @see MSG_run, MSG_clean + */ + public final static native void run() throws NativeException; + + /** + * The native implemented method to create the environment of the simulation. + * + * @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; + + /** + * 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; + + /** Example launcher. You can use it or provide your own launcher, as you wish */ + static public void main(String[]args) throws MsgException { + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + + if (args.length < 2) { + Msg.info("Usage: Msg platform_file deployment_file"); + System.exit(1); + } + + /* Load the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* Execute the simulation */ + Msg.run(); + } } diff --git a/src/java/simgrid/msg/MsgException.java b/src/java/simgrid/msg/MsgException.java index ad45da032a..e7a89ead06 100644 --- a/src/java/simgrid/msg/MsgException.java +++ b/src/java/simgrid/msg/MsgException.java @@ -1,7 +1,7 @@ /* - * java.com.simgrid.msg.MsgException.java 1.00 07/05/01 + * This exception is an abstract class grouping all MSG-related exceptions * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -25,14 +25,14 @@ import java.lang.Exception; public abstract class MsgException extends Exception { private static final long serialVersionUID = 1L; - /* + /** * Constructs an MsgException without a * detail message. */ public MsgException() { super(); } - /* + /** * Constructs an MsgException with a detail message. * * @param s the detail message. diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index 1cb47da32e..0e070edc61 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -1,7 +1,7 @@ /* - * simgrid.msg.Msg.java 1.00 07/05/01 + * Contains all the native methods related to Process, Host and Task. * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -11,648 +11,539 @@ package simgrid.msg; -/* Contains all the native methods reloaded by Process, Host and Task. - * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @since SimGrid 3.3 +/** + * Contains all the native methods related to Process, Host and Task. */ final class MsgNative { - final static native - void selectContextFactory(String name) throws NativeException; - - /****************************************************************** - * The natively implemented methods connected to the MSG Process * - ******************************************************************/ - - /** - * The natively implemented method to create an MSG process. - * - * @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; - - /** - * The natively implemented method to kill all the process of the simulation. - * - * @param resetPID Should we reset the PID numbers. A negative number means no reset - * and a positive number will be used to set the PID of the next newly - * created process. - * - * @return The function returns the PID of the next created process. - */ - final static native int processKillAll(int resetPID); - - /** - * The natively implemented method to suspend an MSG process. - * - * @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. - * - * @see Process.pause() - */ - final static native void processSuspend(Process process) - throws JniException, NativeException; - - /** - * The natively implemented method to kill a MSG process. - * - * @param process The valid (binded with a native process) java process to kill. - * - * @see Process.kill() - */ - final static native void processKill(Process process) - throws JniException; - - /** - * 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. - * - * @see Process.restart() - */ - final static native void processResume(Process process) - throws JniException, NativeException; - - /** - * The natively implemented method to test if MSG process is suspended. - * - * @param process The valid (binded with a native process) java process to test. - * - * @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; - - /** - * The natively implemented method to get the host of a MSG process. - * - * @param process The valid (binded with a native process) java process to get the host. - * - * @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. - * - * @see Process.getHost() - */ - final static native Host processGetHost(Process process) - throws JniException, NativeException; - - /** - * The natively implemented method to get a MSG process from his PID. - * - * @param PID The PID of the process to get. - * - * @return The process with the specified PID. - * - * @exception NativeException if the SimGrid native code failed. - * - * @see Process.getFromPID() - */ - final static native Process processFromPID(int PID) throws NativeException; - - /** - * The natively implemented method to get the PID of a MSG process. - * - * @param process The valid (binded with a native process) java process to get the PID. - * - * @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; - - /** - * The natively implemented method to get the PPID of a MSG process. - * - * @param process The valid (binded with a native process) java process to get the PID. - * - * @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; - - /** - * 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; - - /** - * 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. - * - * @see Process.migrate() - * @see Host.getByName() - */ - final static native void processChangeHost(Process process, Host host) - throws JniException, NativeException; - - /** - * The natively implemented native to request the current process to sleep - * until time seconds have elapsed. - * - * @param seconds The time the current process must sleep. - * - * @exception NativeException if the SimGrid native code failed. - * - * @see Process.waitFor() - */ - 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; - - - /****************************************************************** - * The natively implemented methods connected to the MSG host * - ******************************************************************/ - - /** - * The natively implemented method to get an host from his name. - * - * @param name The name of the host to get. - * - * @return The host having the specified name. - * - * @exception JniException if something goes wrong with JNI - * 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; - - /** - * The natively implemented method to get the name of an MSG host. - * - * @param host The host (valid) to get the name. - * - * @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; - - /** - * The natively implemented method to get the number of hosts of the simulation. - * - * @return The number of hosts of the simulation. - * - * @see Host.getNumber() - */ - final static native int hostGetNumber(); - - /** - * The natively implemented method to get the host of the current runing process. - * - * @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; - - /** - * The natively implemented method to get the speed of a MSG host. - * - * @param host The host to get the host. - * - * @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; - - /** - * The natively implemented native method to test if an host is avail. - * - * @param host The host to test. - * - * @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; - - /** - * 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; - - /** - * The natively implemented native method to get the number of running tasks on a host. - * - * @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; - - /****************************************************************** - * The natively implemented methods connected to the MSG task * - ******************************************************************/ - - /** - * The natively implemented method to create a MSG task. - * - * @param name The name of th task. - * @param computeDuration A value of the processing amount (in flop) needed - * to process the task. If 0, then it cannot be executed - * with the execute() method. This value has to be >= 0. - * @param messageSize A value of amount of data (in bytes) needed to transfert - * this task. If 0, then it cannot be transfered this task. - * If 0, then it cannot be transfered with the get() and put() - * 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 - * NullPointerException if the specified name is null. - * 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, NullPointerException, IllegalArgumentException; - - /** - * The natively implemented method to get the sender of a task. - * - * @param task The task (valid) to get the sender. - * - * @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; - - /** - * The natively implementd method to get the source of a task. - * - * @param task The task to get the source. - * - * @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. - * - * @see Task.getSource() - */ - final static native Host taskGetSource(Task task) throws JniException, - NativeException; - - /** - * The natively implemented method to get the name of the task. - * - * @param task The task to get the name. - * - * @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; - - /** - * 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. - * - * @see Task.cancel(). - */ - final static native void taskCancel(Task task) throws JniException, - NativeException; - - /** - * The natively implemented method to create a MSG parallel task. - * - * @param name The name of the parallel task. - * @param hosts The list of hosts implied by the parallel task. - * @param computeDurations The total number of operations that have to be performed - * on the hosts. - * @param messageSizes An array of doubles - * - * @see ParallelTask.create() - */ - final static native void parallelTaskCreate(Task pTask, String name, - Host[]hosts, - double[]computeDurations, - double[]messageSizes) - throws JniException, NullPointerException, IllegalArgumentException; - - /** - * The natively implemented method to get the computing amount of the task. - * - * @param task The task to get the computing amount. - * - * @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; - - /** - * The natively implemented method to get the remaining computation - * - * @param task The task to get the remaining computation. - * - * @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; - - /** - * The natively implemented method to set the priority of a task. - * - * @param task The task to set the priority - * - * @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; - - /** - * 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. - * - * @see Task.destroy() - */ - final static native void taskDestroy(Task task) throws JniException, - 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. - * - * @see Task.execute() - */ - final static native void taskExecute(Task task) throws JniException, - NativeException; - - - /****************************************************************** - * Task reception methods * - ******************************************************************/ - - /** - * The natively implemented method to listen on the channel and wait for receiving a task with a timeout. - * - * @param channel The channel to listen. - * @param timeout The timeout of the listening. - * @param host The specific host from which we accept messages (or NULL for any). - * - * @return The task read from the channel. - * - * @exception MsgException if the listening operation failed. - * - * @see Channel.getWithTimeout() - * - */ - final static native Task taskGet(int channel, double timeout, - Host host) throws JniException, - NativeException; - - - /****************************************************************** - * Task methods relative with the alias * - ******************************************************************/ - - - 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; - - - - /** - * The natively implemented method to test whether there is a pending communication on the channel. - * - * @param channel The channel concerned by the operation. - * - * @return The method returns true if there is a pending communication on the specified - * channel. Otherwise the method returns false. - * - * @see Channel.hasPendingCommunication() - */ - final static native boolean taskProbe(int channel) throws JniException; - - /** - * The natively implemented method to test whether there is a pending communication on a - * channel, and who sent it. - * - * @param The channel concerned by the operation. - * - * @return The method returns -1 if there is no pending communication and - * the PID of the process who sent it otherwise. - * - * @see Channel.getCummunicatingProcess() - */ - final static native int taskGetCommunicatingProcess(int channel) throws - JniException; - - /** - * The natively implemented method to get the number of tasks waiting to be received on a - * channel and sent by a host. - * - * @param channel The channel concerned by the operation. - * - * @param host The sender of the tasks. - * - * @return The number of tasks waiting to be received on a channel - * and sent by the specified host. - * - * @exception InvalidHostException if the specified host is not valid. - * - * @see Channel.getHostWaiting() - */ - final static native int taskProbeHost(int channel, - Host host) throws JniException; - - - /****************************************************************** - * Task emission methods * - ******************************************************************/ - /** - * The natively implemented method to put a task on the channel of an host. - * - * @param host The host on which to send the data - * @param channel The channel where to put the task. - * @param task The task to put. - * @param task Timeout (or <0 if none) - * - * @exception InvalidTaskException if the task is not valid. - * InvalidHostException if the host is not valid. - * MsgException if the operation failed. - * - */ - final static native void hostPut(Host host, int channel, Task task, - double timeout) throws JniException, - NativeException; - - - /** - * The natively implemented method to put a task on channel with a bounded transmition - * rate. - * - * @param channel The channel where to put the task. - * @param task The task to put. - * @param host The host containing the channel. - * @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. - * - * @see Channel.putBounded() - */ - final static native void hostPutBounded(Host host, int channel, Task task, - double max_rate) throws - JniException, NativeException; - - /** - * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition - * rate. - * - * @param alias The alias of the mailbox. - * @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. - */ - final static native void taskSendBounded(String alias, Task task, double maxrate) - throws JniException, NativeException; + final static native + void selectContextFactory(String name) throws NativeException; + + /****************************************************************** + * The natively implemented methods connected to the MSG Process * + ******************************************************************/ + + /** + * The natively implemented method to create an MSG process. + * + * @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; + + /** + * The natively implemented method to kill all the process of the simulation. + * + * @param resetPID Should we reset the PID numbers. A negative number means no reset + * and a positive number will be used to set the PID of the next newly + * created process. + * + * @return The function returns the PID of the next created process. + */ + final static native int processKillAll(int resetPID); + + /** + * The natively implemented method to suspend an MSG process. + * + * @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. + * + * @see Process.pause() + */ + final static native void processSuspend(Process process) throws JniException, NativeException; + + /** + * The natively implemented method to kill a MSG process. + * + * @param process The valid (binded with a native process) java process to kill. + * + * @see Process.kill() + */ + final static native void processKill(Process process) + throws JniException; + + /** + * 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. + * + * @see Process.restart() + */ + final static native void processResume(Process process) + throws JniException, NativeException; + + /** + * The natively implemented method to test if MSG process is suspended. + * + * @param process The valid (binded with a native process) java process to test. + * + * @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; + + /** + * The natively implemented method to get the host of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the host. + * + * @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. + * + * @see Process.getHost() + */ + final static native Host processGetHost(Process process) + throws JniException, NativeException; + + /** + * The natively implemented method to get a MSG process from his PID. + * + * @param PID The PID of the process to get. + * + * @return The process with the specified PID. + * + * @exception NativeException if the SimGrid native code failed. + * + * @see Process.getFromPID() + */ + final static native Process processFromPID(int PID) throws NativeException; + + /** + * The natively implemented method to get the PID of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the PID. + * + * @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; + + /** + * The natively implemented method to get the PPID of a MSG process. + * + * @param process The valid (binded with a native process) java process to get the PID. + * + * @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; + + /** + * 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; + + /** + * 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. + * + * @see Process.migrate() + * @see Host.getByName() + */ + final static native void processChangeHost(Process process, Host host) + throws JniException, NativeException; + + /** + * The natively implemented native to request the current process to sleep + * until time seconds have elapsed. + * + * @param seconds The time the current process must sleep. + * + * @exception NativeException if the SimGrid native code failed. + * + * @see Process.waitFor() + */ + 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; + + + /****************************************************************** + * The natively implemented methods connected to the MSG host * + ******************************************************************/ + + /** + * The natively implemented method to get an host from his name. + * + * @param name The name of the host to get. + * + * @return The host having the specified name. + * + * @exception JniException if something goes wrong with JNI + * 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; + + /** + * The natively implemented method to get the name of an MSG host. + * + * @param host The host (valid) to get the name. + * + * @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; + + /** + * The natively implemented method to get the number of hosts of the simulation. + * + * @return The number of hosts of the simulation. + * + * @see Host.getNumber() + */ + final static native int hostGetCount(); + + /** + * The natively implemented method to get the host of the current runing process. + * + * @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; + + /** + * The natively implemented method to get the speed of a MSG host. + * + * @param host The host to get the host. + * + * @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; + + /** + * The natively implemented native method to test if an host is avail. + * + * @param host The host to test. + * + * @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; + + /** + * 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; + + /** + * The natively implemented native method to get the number of running tasks on a host. + * + * @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; + + /****************************************************************** + * The natively implemented methods connected to the MSG task * + ******************************************************************/ + + /** + * The natively implemented method to create a MSG task. + * + * @param name The name of th task. + * @param computeDuration A value of the processing amount (in flop) needed + * to process the task. If 0, then it cannot be executed + * with the execute() method. This value has to be >= 0. + * @param messageSize A value of amount of data (in bytes) needed to transfert + * this task. If 0, then it cannot be transfered this task. + * If 0, then it cannot be transfered with the get() and put() + * 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 + * NullPointerException if the specified name is null. + * 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, NullPointerException, IllegalArgumentException; + + /** + * The natively implemented method to get the sender of a task. + * + * @param task The task (valid) to get the sender. + * + * @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; + + /** + * The natively implementd method to get the source of a task. + * + * @param task The task to get the source. + * + * @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. + * + * @see Task.getSource() + */ + final static native Host taskGetSource(Task task) throws JniException, + NativeException; + + /** + * The natively implemented method to get the name of the task. + * + * @param task The task to get the name. + * + * @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; + + /** + * 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. + * + * @see Task.cancel(). + */ + final static native void taskCancel(Task task) throws JniException, + NativeException; + + /** + * The natively implemented method to create a MSG parallel task. + * + * @param name The name of the parallel task. + * @param hosts The list of hosts implied by the parallel task. + * @param computeDurations The total number of operations that have to be performed + * on the hosts. + * @param messageSizes An array of doubles + * + * @see ParallelTask.create() + */ + final static native void parallelTaskCreate(Task pTask, String name, + Host[]hosts, + double[]computeDurations, + double[]messageSizes) + throws JniException, NullPointerException, IllegalArgumentException; + + /** + * The natively implemented method to get the computing amount of the task. + * + * @param task The task to get the computing amount. + * + * @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; + + /** + * The natively implemented method to get the remaining computation + * + * @param task The task to get the remaining computation. + * + * @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; + + /** + * The natively implemented method to set the priority of a task. + * + * @param task The task to set the priority + * + * @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; + + /** + * 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. + * + * @see Task.destroy() + */ + final static native void taskDestroy(Task task) throws JniException, + 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. + * + * @see Task.execute() + */ + final static native void taskExecute(Task task) throws JniException, + NativeException; + + + + /* **************************************************************** + * Communication methods thru mailboxes * + **************************************************************** */ + + + 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; + + /* *************************************************************** + * Task sending methods * + *************************************************************** */ + + /** + * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition + * rate. + * + * @param alias The alias of the mailbox. + * @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. + */ + final static native void taskSendBounded(String alias, Task task, double maxrate) + throws JniException, NativeException; } diff --git a/src/java/simgrid/msg/NativeException.java b/src/java/simgrid/msg/NativeException.java index 96053b6d8f..1882a61bf4 100644 --- a/src/java/simgrid/msg/NativeException.java +++ b/src/java/simgrid/msg/NativeException.java @@ -1,7 +1,7 @@ /* - * $Id$ + * This exception is raised when there is an error within the C world of SimGrid. * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid team * All right reserved. * * This program is free software; you can redistribute @@ -11,23 +11,25 @@ package simgrid.msg; /** - * This exception is raised when there is an error within the SimGrid message. Refer to the string message for more info on what went wrong. + * This exception is raised when there is an error within the C world of SimGrid. + * Refer to the string message for more info on what went wrong. */ public class NativeException extends MsgException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /* - * Constructs an NativeException without a - * detail message. - */ - public NativeException() { - super(); - } - /* - * Constructs an NativeException with a detail message. - * - * @param s the detail message. - */ public NativeException(String s) { - super(s); - } + /* + * Constructs an NativeException without a + * detail message. + * + public NativeException() { + super(); + }*/ + /** + * Constructs an NativeException with a detail message. + * + * @param s the detail message. + */ + public NativeException(String s) { + super(s); + } } diff --git a/src/java/simgrid/msg/Process.java b/src/java/simgrid/msg/Process.java index 740b38efb1..e173b1d279 100644 --- a/src/java/simgrid/msg/Process.java +++ b/src/java/simgrid/msg/Process.java @@ -18,7 +18,7 @@ import java.util.*; * A process may be defined as a code, with some private data, executing * in a location (host). All the process used by your simulation must be * declared in the deployment file (XML format). - * To create your ouwn process you must inherite your own process from this + * To create your own process you must inherit your own process from this * class and override the method "main()". For example if you want to use * a process named Slave proceed as it : * @@ -36,478 +36,398 @@ import java.util.*; * \endverbatim * } * The name of your process must be declared in the deployment file of your simulation. - * For the exemple, for the previouse process Slave this file must contains a line : + * For the example, for the previous process Slave this file must contains a line : * <process host="Maxims" function="Slave"/>, where Maxims is the host of the process - * Slave. All the process of your simulation are automaticaly launched and managed by Msg. + * Slave. All the process of your simulation are automatically launched and managed by Msg. * A process use tasks to simulate communications or computations with another process. * For more information see Task. For more information on host concept * see Host. * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @since SimGrid 3.3 */ public abstract class Process extends Thread { - /** - * This attribute represents a bind between a java process object and - * a native process. Even if this attribute is public you must never - * access to it. It is set automaticatly during the build of the object. - */ - public long bind; - - /** - * Even if this attribute is public you must never access to it. - * It is used to compute the id of an MSG process. - */ - public static long nextProcessId = 0; - - /** - * Even if this attribute is public you must never access to it. - * It is compute automaticaly during the creation of the object. - * The native functions use this identifier to synchronize the process. - */ - public long id; - - public Hashtable properties; - - /** - * The name of the process. - */ - protected String name; - public String msgName() { - return this.name; - } - /* - * The arguments of the method function of the process. - */ public Vector args; - - /* process synchronisation tools */ - protected Sem schedBegin, schedEnd; - - /** - * Default constructor. (used in ApplicationHandler to initialize it) - */ - protected Process() { - super(); - this.id = 0; - this.name = null; - this.bind = 0; - this.args = new Vector(); - this.properties = null; - schedBegin = new Sem(0); - schedEnd = new Sem(0); - } - - - /** - * Constructs a new process from the name of a host and his name. The method - * function of the process doesn't have argument. - * - * @param hostname The name of the host of the process to create. - * @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 - * - */ - public Process(String hostname, String name) - throws NullPointerException, HostNotFoundException, JniException, - NativeException { - this(Host.getByName(hostname), name, null); - } - /** - * Constructs a new process from the name of a host and his name. The arguments - * of the method function of the process are specified by the parameter args. - * - * @param hostname The name of the host of the process to create. - * @param name The name of the process. - * @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 - * - */ - public Process(String hostname, String name, String args[]) - throws NullPointerException, HostNotFoundException, JniException, - NativeException { - this(Host.getByName(hostname), name, args); - } - /** - * Constructs a new process from a host and his name. The method function of the - * process doesn't have argument. - * - * @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 { - this(host, name, null); - } - /** - * Constructs a new process from a host and his name, the arguments of here method function are - * specified by the parameter args. - * - * @param host The host of the process to create. - * @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 { - /* This is the constructor called by all others */ - - if (name == null) - throw new NullPointerException("Process name cannot be NULL"); - - this.properties = null; - - 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); - } - - - /** - * This method kills all running process of the simulation. - * - * @param resetPID Should we reset the PID numbers. A negative number means no reset - * and a positive number will be used to set the PID of the next newly - * created process. - * - * @return The function returns the PID of the next created process. - * - */ public static int killAll(int resetPID) { - return MsgNative.processKillAll(resetPID); - } - - /** - * This method adds an argument in the list of the arguments of the main function - * of the process. - * - * @param arg The argument to add. - */ - protected void addArg(String arg) { - args.add(arg); - } - - /** - * This method 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 - */ - public void pause() throws JniException, NativeException { - MsgNative.processSuspend(this); - } - /** - * This method 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 - * - */ public void restart() throws JniException, NativeException { - MsgNative.processResume(this); - } - /** - * This method 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 { - return MsgNative.processIsSuspended(this); - } - /** - * This method 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 - * - */ public Host getHost() throws JniException, NativeException { - return MsgNative.processGetHost(this); - } - /** - * This static method get a process from a PID. - * - * @param PID The process identifier of the process to get. - * - * @return The process with the specified PID. - * - * @exception NativeException on error in the native SimGrid code - */ public static Process fromPID(int PID) throws NativeException { - return MsgNative.processFromPID(PID); - } - /** - * This method returns the PID of the process. - * - * @return The PID of the process. - * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code - */ public int getPID() throws JniException, NativeException { - return MsgNative.processGetPID(this); - } - /** - * This method returns the PID of the parent of a process. - * - * @return The PID of the parent of the process. - * - * @exception NativeException on error in the native SimGrid code - */ public int getPPID() throws NativeException { - return MsgNative.processGetPPID(this); - } - /** - * This static method returns the currently running process. - * - * @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. - * - * @param host The host where to migrate the process. - * - * @exception JniException on JNI madness - * NativeException on error in the native SimGrid code - */ - public void migrate(Host host) throws JniException, NativeException { - MsgNative.processChangeHost(this, host); - } - /** - * This method makes the current process sleep until time seconds have elapsed. - * - * @param seconds The time the current process must sleep. - * - * @exception NativeException on error in the native SimGrid code - */ public static void waitFor(double seconds) throws NativeException { - MsgNative.processWaitFor(seconds); - } public void showArgs() { - try { - Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" + - this.args.size()); - for (int i = 0; i < this.args.size(); i++) - Msg.info("[" + this.msgName() + "/" + this.getHost().getName() + - "] args[" + i + "]=" + (String) (this.args.get(i))); - } catch(MsgException e) { - Msg.info("Damn JNI stuff"); - e.printStackTrace(); - System.exit(1); - } - } - /** - * This method runs the process. Il calls the method function that you must overwrite. - */ - public /*synchronized*/ void run() { - - String[]args = null; /* do not fill it before the signal or this.args will be empty */ - - //waitSignal(); /* wait for other people to fill the process in */ - - - try { - schedBegin.acquire(); - } catch(InterruptedException e) { - } - - - - try { - args = new String[this.args.size()]; - if (this.args.size() > 0) { - this.args.toArray(args); - } - - this.main(args); - MsgNative.processExit(this); - schedEnd.release(); - } - catch(MsgException e) { - e.printStackTrace(); - Msg.info("Unexpected behavior. Stopping now"); - System.exit(1); - } - } - - /** - * The main function of the process (to implement). - */ - public abstract void main(String[]args) - throws JniException, NativeException; - - - public void unschedule() { - try { - schedEnd.release(); - schedBegin.acquire(); - } catch(InterruptedException e) { - } - } - - public void schedule() { - try { - schedBegin.release(); - schedEnd.acquire(); - } catch(InterruptedException e) { - } - } - - /** Send the given task to given host on given channel */ - public void taskPut(Host host, int channel, - Task task) throws NativeException, JniException { - MsgNative.hostPut(host, channel, task, -1); - } - - /** Send the given task to given host on given channel (waiting at most given time)*/ - public void taskPut(Host host, int channel, - Task task, double timeout) throws NativeException, JniException { - MsgNative.hostPut(host, channel, task, timeout); - } - /** Receive a task on given channel */ - public Task taskGet(int channel) throws NativeException, - JniException { - return MsgNative.taskGet(channel, -1, null); - } - /** Receive a task on given channel (waiting at most given time) */ - public Task taskGet(int channel, - double timeout) throws NativeException, - JniException { - return MsgNative.taskGet(channel, timeout, null); - } - /** Receive a task on given channel from given sender */ - public Task taskGet(int channel, Host host) throws NativeException, - JniException { - return MsgNative.taskGet(channel, -1, host); - } - /** Receive a task on given channel from given sender (waiting at most given time) */ - public Task taskGet(int channel, double timeout, - Host host) throws NativeException, JniException { - return MsgNative.taskGet(channel, timeout, host); - } - - /** Send the given task in the mailbox associated with the specified alias (waiting at most given time) */ - public void taskSend(String alias, - Task task, double timeout) throws NativeException, JniException { - MsgNative.taskSend(alias, task, timeout); - } - - /** Send the given task in the mailbox associated with the specified alias*/ - public void taskSend(String alias, - Task task) throws NativeException, JniException { - MsgNative.taskSend(alias, task, -1); - } - - /** Send the given task in the mailbox associated with the default alias (defaultAlias = "hostName:processName") */ - public void taskSend(Task task) throws NativeException, JniException { - - String alias = this.getHost().getName() + ":" + this.msgName(); - MsgNative.taskSend(alias, task, -1); - } - - /** Send the given task in the mailbox associated with the default alias (waiting at most given time) */ - public void taskSend(Task task, double timeout) throws NativeException, JniException { - - String alias = this.getHost().getName() + ":" + this.msgName(); - MsgNative.taskSend(alias, task, timeout); - } - - - /** Receive a task on mailbox associated with the specified alias */ - public Task taskReceive(String alias) throws NativeException, - JniException { - return MsgNative.taskReceive(alias, -1.0, null); - } - - /** Receive a task on mailbox associated with the default alias */ - public Task taskReceive() throws NativeException, - JniException { - String alias = this.getHost().getName() + ":" + this.msgName(); - return MsgNative.taskReceive(alias, -1.0, null); - } - - /** Receive a task on mailbox associated with the specified alias (waiting at most given time) */ - public Task taskReceive(String alias, - double timeout) throws NativeException, - JniException { - return MsgNative.taskReceive(alias, timeout, null); - } - - /** Receive a task on mailbox associated with the default alias (waiting at most given time) */ - public Task taskReceive(double timeout) throws NativeException, - JniException { - String alias = this.getHost().getName() + ":" + this.msgName(); - return MsgNative.taskReceive(alias, timeout, null); - } - - /** Receive a task on mailbox associated with the specified alias from given sender */ - public Task taskReceive(String alias, - double timeout, Host host) throws NativeException, - JniException { - return MsgNative.taskReceive(alias, timeout, host); - } - - /** Receive a task on mailbox associated with the default alias from given sender (waiting at most given time) */ - public Task taskReceive(double timeout, Host host) throws NativeException, - JniException { - String alias = this.getHost().getName() + ":" + this.msgName(); - return MsgNative.taskReceive(alias, timeout, host); - } - - /** Receive a task on mailbox associated with the specified alias from given sender*/ - public Task taskReceive(String alias, - Host host) throws NativeException, - JniException { - return MsgNative.taskReceive(alias, -1.0, host); - } - /** Receive a task on mailbox associated with the default alias from given sender */ - public Task taskReceive( Host host) throws NativeException, - JniException { - String alias = this.getHost().getName() + ":" + this.msgName(); - return MsgNative.taskReceive(alias, -1.0, host); - } + /** + * This attribute represents a bind between a java process object and + * a native process. Even if this attribute is public you must never + * access to it. It is set automatically during the build of the object. + */ + public long bind; + + /** + * Even if this attribute is public you must never access to it. + * It is used to compute the id of an MSG process. + */ + public static long nextProcessId = 0; + + /** + * Even if this attribute is public you must never access to it. + * It is compute automatically during the creation of the object. + * The native functions use this identifier to synchronize the process. + */ + public long id; + + public Hashtable properties; + + /** + * The name of the process. + */ + protected String name; + public String msgName() { + return this.name; + } + /** The arguments of the method function of the process. */ + public Vector args; + + /* process synchronization tools */ + protected Sem schedBegin, schedEnd; + + /** + * Default constructor (used in ApplicationHandler to initialize it) + */ + protected Process() { + super(); + this.id = 0; + this.name = null; + this.bind = 0; + this.args = new Vector(); + this.properties = null; + schedBegin = new Sem(0); + schedEnd = new Sem(0); + } + + + /** + * Constructs a new process from the name of a host and his name. The method + * function of the process doesn't have argument. + * + * @param hostname The name of the host of the process to create. + * @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 { + this(Host.getByName(hostname), name, null); + } + /** + * Constructs a new process from the name of a host and his name. The arguments + * of the method function of the process are specified by the parameter args. + * + * @param hostname The name of the host of the process to create. + * @param name The name of the process. + * @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 + * + */ + public Process(String hostname, String name, String args[]) + throws NullPointerException, HostNotFoundException, JniException, + NativeException { + this(Host.getByName(hostname), name, args); + } + /** + * Constructs a new process from a host and his name. The method function of the + * process doesn't have argument. + * + * @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 { + this(host, name, null); + } + /** + * Constructs a new process from a host and his name, the arguments of here method function are + * specified by the parameter args. + * + * @param host The host of the process to create. + * @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 { + /* This is the constructor called by all others */ + + if (name == null) + throw new NullPointerException("Process name cannot be NULL"); + + this.properties = null; + + 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); + } + + + /** + * This method kills all running process of the simulation. + * + * @param resetPID Should we reset the PID numbers. A negative number means no reset + * and a positive number will be used to set the PID of the next newly + * created process. + * + * @return The function returns the PID of the next created process. + * + */ + public static int killAll(int resetPID) { + return MsgNative.processKillAll(resetPID); + } + + /** + * This method adds an argument in the list of the arguments of the main function + * of the process. + * + * @param arg The argument to add. + */ + protected void addArg(String arg) { + args.add(arg); + } + + /** + * This method 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 + */ + public void pause() throws JniException, NativeException { + MsgNative.processSuspend(this); + } + /** + * This method 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 + * + */ + public void restart() throws JniException, NativeException { + MsgNative.processResume(this); + } + /** + * This method 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 { + return MsgNative.processIsSuspended(this); + } + /** + * This method 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 + * + */ + public Host getHost() throws JniException, NativeException { + return MsgNative.processGetHost(this); + } + /** + * This static method get a process from a PID. + * + * @param PID The process identifier of the process to get. + * + * @return The process with the specified PID. + * + * @exception NativeException on error in the native SimGrid code + */ + public static Process fromPID(int PID) throws NativeException { + return MsgNative.processFromPID(PID); + } + /** + * This method returns the PID of the process. + * + * @return The PID of the process. + * + * @exception JniException on JNI madness + * NativeException on error in the native SimGrid code + */ + public int getPID() throws JniException, NativeException { + return MsgNative.processGetPID(this); + } + /** + * This method returns the PID of the parent of a process. + * + * @return The PID of the parent of the process. + * + * @exception NativeException on error in the native SimGrid code + */ + public int getPPID() throws NativeException { + return MsgNative.processGetPPID(this); + } + /** + * This static method returns the currently running process. + * + * @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. + * + * @param host The host where to migrate the process. + * + * @exception JniException on JNI madness + * NativeException on error in the native SimGrid code + */ + public void migrate(Host host) throws JniException, NativeException { + MsgNative.processChangeHost(this, host); + } + /** + * This method makes the current process sleep until time seconds have elapsed. + * + * @param seconds The time the current process must sleep. + * + * @exception NativeException on error in the native SimGrid code + */ + public static void waitFor(double seconds) throws NativeException { + MsgNative.processWaitFor(seconds); + } + public void showArgs() { + try { + Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" + + this.args.size()); + for (int i = 0; i < this.args.size(); i++) + Msg.info("[" + this.msgName() + "/" + this.getHost().getName() + + "] args[" + i + "]=" + (String) (this.args.get(i))); + } catch(MsgException e) { + Msg.info("Damn JNI stuff"); + e.printStackTrace(); + System.exit(1); + } + } + /** + * This method runs the process. Il calls the method function that you must overwrite. + */ + public void run() { + + String[]args = null; /* do not fill it before the signal or this.args will be empty */ + + //waitSignal(); /* wait for other people to fill the process in */ + + + try { + schedBegin.acquire(); + } catch(InterruptedException e) { + } + + try { + args = new String[this.args.size()]; + if (this.args.size() > 0) { + this.args.toArray(args); + } + + this.main(args); + MsgNative.processExit(this); + schedEnd.release(); + } catch(MsgException e) { + e.printStackTrace(); + Msg.info("Unexpected behavior. Stopping now"); + System.exit(1); + } + } + + /** + * The main function of the process (to implement). + */ + public abstract void main(String[]args) throws JniException, NativeException; + + + public void unschedule() { + try { + schedEnd.release(); + schedBegin.acquire(); + } catch(InterruptedException e) { + } + } + + public void schedule() { + try { + schedBegin.release(); + schedEnd.acquire(); + } catch(InterruptedException e) { + } + } + + /** 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 { + 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 { + MsgNative.taskSend(mailbox, task, -1); + } + + /** Receive a task on mailbox associated with the specified mailbox */ + public Task taskReceive(String mailbox) throws NativeException, JniException { + 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 { + 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 { + 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 { + return MsgNative.taskReceive(mailbox, -1.0, host); + } } diff --git a/src/java/simgrid/msg/ProcessNotFoundException.java b/src/java/simgrid/msg/ProcessNotFoundException.java index 081daed6be..e3c7df8e09 100644 --- a/src/java/simgrid/msg/ProcessNotFoundException.java +++ b/src/java/simgrid/msg/ProcessNotFoundException.java @@ -1,7 +1,7 @@ /* - * $Id$ + * This exception is raised when looking for a non-existing process. * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute @@ -12,23 +12,24 @@ package simgrid.msg; /** - * This exception is raised when looking for a non-existing process. - */ + * This exception is raised when looking for a non-existing process. + */ public class ProcessNotFoundException extends MsgException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /* - * Constructs an ProcessNotFoundException without a - * detail message. - */ - public ProcessNotFoundException() { - super(); - } - /* - * Constructs an ProcessNotFoundException with a detail message. - * - * @param s the detail message. - */ public ProcessNotFoundException(String s) { - super(s); - } + /** + * Constructs an ProcessNotFoundException without a + * detail message. + */ + public ProcessNotFoundException() { + super(); + } + /** + * Constructs an ProcessNotFoundException with a detail message. + * + * @param s the detail message. + */ + public ProcessNotFoundException(String s) { + super(s); + } } diff --git a/src/java/simgrid/msg/Sem.java b/src/java/simgrid/msg/Sem.java index 6e44870813..af1d60bf83 100644 --- a/src/java/simgrid/msg/Sem.java +++ b/src/java/simgrid/msg/Sem.java @@ -1,38 +1,35 @@ /* - * $Id$ + * Simple semaphore implementation, from Doug Lea (public domain) * - * Copyright 2006,2007 Martin Quinson, Malek Cherier + * Copyright 2006,2007,2010 The SimGrid Team * All right reserved. * * This program is free software; you can redistribute * it and/or modify it under the terms of the license *(GNU LGPL) which comes with this package. */ - package simgrid.msg; - public class Sem { - - /******************************************************************/ - /* Simple semaphore implementation, from Doug Lea (public domain) */ - /******************************************************************/ - private int permits_; - public Sem(int i) { - permits_ = i; - } public void acquire() throws InterruptedException { - if (Thread.interrupted()) - throw new InterruptedException(); - synchronized(this) { - try { - while (permits_ <= 0) - wait(); - --permits_; - } - catch(InterruptedException ex) { - notify(); - throw ex; - } - } - } - public synchronized void release() { - ++(this.permits_); - notify(); - } } + package simgrid.msg; + public class Sem { + /******************************************************************/ + /* Simple semaphore implementation, from Doug Lea (public domain) */ + /******************************************************************/ + private int permits_; + public Sem(int i) { permits_ = i; } public void acquire() throws InterruptedException { + if (Thread.interrupted()) + throw new InterruptedException(); + synchronized(this) { + try { + while (permits_ <= 0) + wait(); + --permits_; + } + catch(InterruptedException ex) { + notify(); + throw ex; + } + } + } + public synchronized void release() { + ++(this.permits_); + notify(); + } } diff --git a/src/java/simgrid/msg/Task.java b/src/java/simgrid/msg/Task.java index b31b8236e1..6be0204297 100644 --- a/src/java/simgrid/msg/Task.java +++ b/src/java/simgrid/msg/Task.java @@ -12,34 +12,25 @@ package simgrid.msg; /** - * Since most scheduling algorithms rely on a concept of - * task that can be either computed locally or transferred - * on another processor, it seems to be the right level of - * abstraction for our purposes. A task may then be defined - * by a computing amount, a message size and some private - * data. To transfer a task you use an instance of the class - * Channel identified by an number. + * A task is either something to compute somewhere, or something to exchange between two hosts (or both). + * It is defined by a computing amount and a message size. * - * @author Abdelmalek Cherier - * @author Martin Quinson - * @since SimGrid 3.3 */ public class Task { - - /** + /** * This attribute represents a bind between a java task object and * a native task. Even if this attribute is public you must never - * access to it. It is set automaticatly during the build of the object. + * access to it. It is set automatically during the build of the object. */ - public long bind = 0; + public long bind = 0; - /* Default constructor (disabled) */ - protected Task() { - } - /* * * * - * * Constructors * * - * * * *//** + /* Default constructor (disabled) */ + protected Task() {} + /* * * * + * * Constructors * * + * * * */ + /** * Construct an new task with the specified processing amount and amount * of data needed. * @@ -53,360 +44,206 @@ public class 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 mecanism fails. - */ public Task(String name, double computeDuration, - double messageSize) throws JniException { - MsgNative.taskCreate(this, name, computeDuration, messageSize); - } - /** - * Construct an new parallel task with the specified processing amount and amount for each host - * implied. - * - * @param name The name of the parallel 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 { - MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, - messageSizes); - } - /* * * * - * * Getters / Setters * * - * * * *//** - * This method gets the name of a task. + * @exception JniException if the binding mechanism fails. + */ + public Task(String name, double computeDuration, double messageSize) throws JniException { + MsgNative.taskCreate(this, name, computeDuration, messageSize); + } + /** + * Construct an new parallel task with the specified processing amount and amount for each host + * implied. * - * @return The name of the task. + * @param name The name of the parallel 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 { + 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 { + return MsgNative.taskGetName(this); + } + /** gets the sender of the task. + * @exception JniException if the binding mechanism fails. * - * @exception JniException if the binding mecanism fails. - * @exception InvalidTaskException is the specified task is not valid. A task - * is invalid if it is not binded with a native task. - */ public String getName() throws JniException { - return MsgNative.taskGetName(this); - } - /** - * This method gets the sender of the task. - * - * @return The sender of the task. - * - * @exception JniException if the binding mecanism fails. - * - */ Process getSender() throws JniException { - return MsgNative.taskGetSender(this); - } - /** - * This method gets the source of the task. - * - * @return The source of the task. - * - * @exception JniException if the binding mecanism fails. - */ public Host getSource() throws JniException, NativeException { - return MsgNative.taskGetSource(this); - } - /** - * This method gets the computing amount of the task. + */ + Process getSender() throws JniException { + return MsgNative.taskGetSender(this); + } + /** Gets the source of the task. + * @exception JniException if the binding mechanism fails. + */ + public Host getSource() throws JniException, NativeException { + return MsgNative.taskGetSource(this); + } + /** gets the computing amount of the task. + * @exception JniException if the binding mechanism fails. + */ + public double getComputeDuration() throws JniException { + return MsgNative.taskGetComputeDuration(this); + } + /** gets the remaining computation of the task. + * @exception JniException if the binding mechanism fails. + */ + public double getRemainingDuration() throws JniException { + return MsgNative.taskGetRemainingDuration(this); + } + /** + * This method sets the priority of the computation of the task. + * The priority doesn't affect the transfert rate. For example a + * priority of 2 will make the task receive two times more cpu than + * the other ones. * - * @return The computing amount of the task. + * @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 { + MsgNative.taskSetPriority(this, priority); + } + /* * * * + * * Communication-related * * + * * * */ + + + /* * * * + * * Computation-related * * + * * * */ + /** + * This method execute a task on the location on which the + * process is running. * - * @exception JniException if the binding mecanism fails. - */ public double getComputeDuration() throws JniException { - return MsgNative.taskGetComputeDuration(this); - } - /** - * This method gets the remaining computation. - * - * @return The remaining duration. - * - * @exception JniException if the binding mecanism fails. - */ public double getRemainingDuration() throws JniException { - return MsgNative.taskGetRemainingDuration(this); - } - /** - * This method sets the priority of the computation of the task. - * The priority doesn't affect the transfert rate. For example a - * priority of 2 will make the task receive two times more cpu than - * 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 { - MsgNative.taskSetPriority(this, priority); - } - /* * * * - * * Communication-related * * - * * * */ - - /** - * Retrieves next task on given channel of local host - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task get(int channel) throws JniException, NativeException { - return MsgNative.taskGet(channel, -1.0, null); - } - /** - * Retrieves next task on given channel of local host (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task get(int channel, double timeout) throws JniException, - NativeException { - return MsgNative.taskGet(channel, timeout, null); - } - /** - * Retrieves next task from given host on given channel of local host - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task get(int channel, Host host) throws JniException, - NativeException { - return MsgNative.taskGet(channel, -1, host); - } - /** - * Retrieves next task from given host on given channel of local host (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ public static Task get(int channel, double timeout, - Host host) throws JniException, NativeException { - return MsgNative.taskGet(channel, timeout, host); - } - - /** - * Probes whether there is a waiting task on the given channel of local host - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ public static boolean probe(int channel) throws JniException { - return MsgNative.taskProbe(channel); - } - /** - * Counts tasks waiting on the given \a channel of local host and sent by given \a host - * - * @exception JniException if the binding mecanism fails. - */ public static int probe(int channel, Host host) throws JniException { - return MsgNative.taskProbeHost(channel, host); - } - - /* * * * - * * Computation-related * * - * * * */ - /** - * This method execute a task on the location on which the - * process is running. - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the cancelation failed. - */ - public void execute() throws JniException, NativeException { - MsgNative.taskExecute(this); - } - /** + * @exception JniException if the binding mechanism fails. + * @exception NativeException if the execution failed. + */ + public void execute() throws JniException, NativeException { + MsgNative.taskExecute(this); + } + /** * This method cancels a task. * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the cancelation failed. - */ public void cancel() throws JniException, NativeException { - MsgNative.taskCancel(this); - } - /** - * This method deletes a task. + * @exception JniException if the binding mechanism fails. + * @exception NativeException if the cancellation failed. + */ + public void cancel() throws JniException, NativeException { + MsgNative.taskCancel(this); + } + /** Deletes a task. * - * @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. - */ protected void finalize() throws JniException, NativeException { - if (this.bind != 0) - MsgNative.taskDestroy(this); + * @exception JniException if the binding mechanism fails + * NativeException if the destruction failed. + */ + protected void finalize() throws JniException, NativeException { + if (this.bind != 0) + MsgNative.taskDestroy(this); } - - /** - * Send the task on the mailbox identified by the default alias (defaultAlias = "currentHostName:CurrentProcessName") - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public void send() throws JniException,NativeException { - - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - - MsgNative.taskSend(alias, this, -1); - } - - /** - * Send the task on the mailbox identified by the specified alias - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public void send(String alias) throws JniException,NativeException { - MsgNative.taskSend(alias, this, -1); - } - - /** - * Send the task on the mailbox identified by the default alias (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public void send(double timeout) throws JniException,NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - MsgNative.taskSend(alias, this, timeout); - } - + /** - * Send the task on the mailbox identified by the specified alias (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public void send(String alias, double timeout) throws JniException,NativeException { - MsgNative.taskSend(alias, this, timeout); + * Send 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 { + MsgNative.taskSend(mailbox, this, -1); } - - + /** - * Send the task on the mailbox identified by the default alias (capping the emision rate to \a maxrate) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public void sendBounded(double maxrate) throws JniException,NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - MsgNative.taskSendBounded(alias, this, maxrate); + * Send 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 { + MsgNative.taskSend(mailbox, this, timeout); } - + /** - * Send the task on the mailbox identified by the specified alias (capping the emision rate to \a maxrate) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ + * Send 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 { MsgNative.taskSendBounded(alias, this, maxrate); } - - /** - * Retrieves next task from the mailbox identified by the default alias (defaultAlias = "currentHostName:CurrentProcessName") - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task receive() throws JniException, NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - return MsgNative.taskReceive(alias, -1.0, null); - } - + /** - * Retrieves next task from the mailbox identified by the specified alias - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - - public static Task receive(String alias) throws JniException, NativeException { - return MsgNative.taskReceive(alias, -1.0, null); + * 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 { + return MsgNative.taskReceive(mailbox, -1.0, null); } - + /** - * Retrieves next task on the mailbox identified by the specified alias (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task receive(String alias, double timeout) throws JniException, NativeException { - return MsgNative.taskReceive(alias, timeout, 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 { + return MsgNative.taskReceive(mailbox, timeout, null); } - + /** - * Retrieves next task sended by a given host on the mailbox identified by the specified alias - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - - public static Task receive(String alias, Host host) throws JniException, NativeException { - return MsgNative.taskReceive(alias, -1.0, host); + * 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 { + return MsgNative.taskReceive(mailbox, -1.0, host); } - + /** - * Retrieves next task sended by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds) - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static Task receive(String alias, double timeout, Host host) throws JniException, NativeException { - return MsgNative.taskReceive(alias, timeout, 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 { + return MsgNative.taskReceive(mailbox, timeout, host); } - + /** - * Listen whether there is a waiting task on the mailbox identified by the default alias of local host - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static boolean listen() throws JniException, NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - - return MsgNative.taskListen(alias); + * Test 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 { + return MsgNative.taskListenFrom(mailbox); } - /** - * Test whether there is a pending communication on the mailbox identified by the specified alias, and who sent it - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static int listenFrom(String alias) throws JniException, NativeException { - return MsgNative.taskListenFrom(alias); + * 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 { + return MsgNative.taskListen(mailbox); } - + /** - * Test whether there is a pending communication on the mailbox identified by the default alias, of the current host, and who sent it - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static int listenFrom() throws JniException, NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - - return MsgNative.taskListenFrom(alias); - } - - /** - * Listen whether there is a waiting task on the mailbox identified by the specified alias - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static boolean listen(String alias) throws JniException, NativeException { - return MsgNative.taskListen(alias); - } - - /** - * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alias and sended by the current host. - * - * @exception JniException if the binding mecanism fails. - * @exception NativeException if the retrival fails. - */ - public static int listenFromHost(Host host) throws JniException, NativeException { - String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName(); - return MsgNative.taskListenFromHost(alias,host); - } - - /** - * 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 mecanism fails. - * @exception NativeException if the retrival fails. - */ + * 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 { return MsgNative.taskListenFromHost(alias, host); }