Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move all the remaining stuff for Task from MsgNative to Task
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 4 May 2012 16:58:53 +0000 (18:58 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 4 May 2012 16:58:53 +0000 (18:58 +0200)
org/simgrid/msg/MsgNative.java
org/simgrid/msg/Process.java
org/simgrid/msg/Task.java
src/jmsg.c
src/jmsg.h
src/jmsg_task.c
src/jmsg_task.h

index 3231615..088442b 100644 (file)
@@ -259,101 +259,4 @@ final class MsgNative {
         * @return                The number of running tasks.
         */
        final static native int hostGetLoad(Host host);
-
-       /******************************************************************
-        * The natively implemented methods connected to the MSG task     *
-        ******************************************************************/
-
-       /**
-        * 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.
-        *
-        *
-        * @see                    Task.getSource()
-        */
-       final static native Host taskGetSource(Task task);
-
-       /**
-        * The natively implemented method to cancel a task.
-        *
-        * @param task            The task to cancel.
-        *
-        *
-        * @see                    Task.cancel().
-        */
-       final static native void taskCancel(Task task);
-
-       /**
-        * 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.
-        *
-        * @see                    Task.getComputeDuration()
-        */
-       final static native double taskGetComputeDuration(Task task);
-
-       /**
-        * 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.
-        *
-        * @see                    Task.getRemainingDuration()
-        */
-       final static native double taskGetRemainingDuration(Task task);
-
-       /**
-        * 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.
-        *
-        * @see                    Task.setPriority()
-        */
-       final static native void taskSetPriority(Task task, double priority);
-
-       /**
-        * The natively implemented method to execute a MSG task.
-        *
-        * @param task            The task to execute.
-        *
-        * @exception             HostFailureException,TaskCancelledException on error in the C world
-        *
-        * @see                    Task.execute()
-        */
-       final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException;
-
-       /* ****************************************************************
-        * Communication methods thru mailboxes                           *
-        **************************************************************** */
-
-       final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException;
-       final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException;
-       final static native int taskListenFrom(String alias);
-       final static native boolean taskListen(String alias);
-       final static native int taskListenFromHost(String alias, Host host);
-
-       /* ***************************************************************
-        * 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             NativeException on error in the C world
-        */ 
-       final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;
-
 }
index 2aceb10..5d0340d 100644 (file)
@@ -516,8 +516,8 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
         * @throws HostFailureException 
         * @throws TransferFailureException */
-       public void taskSend(String mailbox, Task task, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, task, timeout);
+       public void taskSend(String mailbox, Task task, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+               task.send(mailbox, timeout);
        }
 
        /** Send the given task in the mailbox associated with the specified alias
@@ -526,8 +526,8 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
         * @throws HostFailureException 
         * @throws TransferFailureException */
-       public void taskSend(String mailbox, Task task) throws  TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, task, -1);
+       public void taskSend(String mailbox, Task task) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+               task.send(mailbox, -1);
        }
 
     /** Receive a task on mailbox associated with the specified mailbox
@@ -538,7 +538,7 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
      */
        public Task taskReceive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, null);
+               return Task.receive(mailbox, -1.0, null);
        }
 
     /** Receive a task on mailbox associated with the specified alias (waiting at most given time)
@@ -550,7 +550,7 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
      */
        public Task taskReceive(String mailbox, double timeout) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, timeout, null);
+               return Task.receive(mailbox, timeout, null);
        }
 
     /** Receive a task on mailbox associated with the specified alias from given sender
@@ -563,7 +563,7 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
      */
        public Task taskReceive(String mailbox, double timeout, Host host) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, timeout, host);
+               return Task.receive(mailbox, timeout, host);
        }
 
     /** Receive a task on mailbox associated with the specified alias from given sender
@@ -575,6 +575,6 @@ public abstract class Process extends Thread {
      * @throws TimeoutException
      */
        public Task taskReceive(String mailbox, Host host) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, host);
+               return Task.receive(mailbox, -1.0, host);
        }
 }
index 3abdfdc..93b7863 100644 (file)
@@ -103,26 +103,20 @@ public class Task {
      * @return
      */
        public native String getName();
-       /** Gets the sender of the task */ 
+       /** Gets the sender of the task */
+       //FIXME: Don't crash when the task has just been created.
        public native Process getSender();
        /** Gets the source of the task
-     * @return
+        * FIXME: Not defensive enough, can crash.
      */
-       public Host getSource()  {
-               return MsgNative.taskGetSource(this);
-       }
-    /** Gets the computing amount of the task
-     * @return
+       public native Host getSource();   
+       /** Gets the computing amount of the task
+     * FIXME: Cache it !
      */
-       public double getComputeDuration() {
-               return MsgNative.taskGetComputeDuration(this);
-       }
-    /** Gets the remaining computation of the task
-     * @return
+       public native double getComputeDuration();
+       /** Gets the remaining computation of the task
      */
-       public double getRemainingDuration() {
-               return MsgNative.taskGetRemainingDuration(this);
-       }
+       public native double getRemainingDuration();
        /**
         * This method sets the priority of the computation of the task.
         * The priority doesn't affect the transfer rate. For example a
@@ -131,9 +125,7 @@ public class Task {
         *
         * @param priority      The new priority of the task.
         */ 
-       public void setPriority(double priority) {
-               MsgNative.taskSetPriority(this, priority);
-       }
+       public native void setPriority(double priority);
        /* *                       * *
         * * Communication-related * *
         * *                       * */
@@ -149,16 +141,12 @@ public class Task {
      * @throws HostFailureException
      * @throws TaskCancelledException
      */
-       public void execute() throws HostFailureException,TaskCancelledException {
-               MsgNative.taskExecute(this);
-       }
+       public native void execute() throws HostFailureException,TaskCancelledException;
        /**
         * Cancels a task.
         *
         */ 
-       public void cancel()  {
-               MsgNative.taskCancel(this);
-       }
+       public native void cancel();
        /** Deletes a task.
         *
         * @exception                   NativeException if the destruction failed.
@@ -184,8 +172,8 @@ public class Task {
         * @throws HostFailureException 
         * @throws TransferFailureException 
         */
-       public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, this, -1);
+       public void send(String mailbox) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+               send(mailbox, -1);
        } 
 
        /**
@@ -198,10 +186,7 @@ public class Task {
         * @throws HostFailureException 
         * @throws TransferFailureException 
         */
-       public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, this, timeout);
-       } 
-
+       public native void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException;
        /**
         * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) 
         *
@@ -211,9 +196,7 @@ public class Task {
      * @throws HostFailureException
      * @throws TimeoutException
         */
-       public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSendBounded(alias, this, maxrate);
-       } 
+       public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
        /**
         * Sends the task on the mailbox asynchronously
         */
@@ -222,21 +205,16 @@ public class Task {
        /**
         * Starts listening for receiving a task from an asynchronous communication
         * @param mailbox
-        * @return
         */
        public static native Comm irecv(String mailbox);
        /**
         * Retrieves next task from the mailbox identified by the specified name
         *
      * @param mailbox
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
         */
 
        public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, null);
+               return receive(mailbox, -1.0, null);
        }
 
        /**
@@ -244,13 +222,9 @@ public class Task {
         *
      * @param mailbox
      * @param timeout
-     * @return 
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
         */
        public static Task receive(String mailbox, double timeout) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, timeout, null);
+               return receive(mailbox, timeout, null);
        }
 
        /**
@@ -258,14 +232,10 @@ public class Task {
         *
      * @param mailbox
      * @param host
-     * @return
-     * @throws TransferFailureException
-     * @throws TimeoutException
-     * @throws HostFailureException
         */
 
        public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, host);
+               return receive(mailbox, -1.0, host);
        }
 
        /**
@@ -274,15 +244,8 @@ public class Task {
      * @param mailbox
      * @param timeout 
      * @param host
-     * @return 
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
         */
-       public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, timeout, host);
-       }
-
+       public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
        /**
         * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
      */
index ac07bfb..e876df3 100644 (file)
@@ -504,109 +504,6 @@ Java_org_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
   return (jboolean) MSG_host_is_avail(host);
 }
 
-
-/***************************************************************************************
- * The MSG task connected functions implementation.                                    *
- ***************************************************************************************/
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
-                                         jobject jtask)
-{
-  m_host_t host;
-  m_task_t task = jtask_to_native_task(jtask, env);
-
-  if (!task) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return NULL;
-  }
-
-  host = MSG_task_get_source(task);
-
-  if (!MSG_host_get_data(host)) {
-    jxbt_throw_jni(env, "MSG_task_get_source() failed");
-    return NULL;
-  }
-
-  return (jobject) MSG_host_get_data(host);
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls,
-                                      jobject jtask)
-{
-  m_task_t ptask = jtask_to_native_task(jtask, env);
-
-  if (!ptask) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return;
-  }
-
-  MSG_error_t rv = MSG_task_cancel(ptask);
-
-  jxbt_check_res("MSG_task_cancel()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
-}
-
-JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls,
-                                                  jobject jtask)
-{
-  m_task_t ptask = jtask_to_native_task(jtask, env);
-
-  if (!ptask) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return -1;
-  }
-  return (jdouble) MSG_task_get_compute_duration(ptask);
-}
-
-JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env,
-                                                    jclass cls,
-                                                    jobject jtask)
-{
-  m_task_t ptask = jtask_to_native_task(jtask, env);
-
-  if (!ptask) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return -1;
-  }
-  return (jdouble) MSG_task_get_remaining_computation(ptask);
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskSetPriority(JNIEnv * env, jclass cls,
-                                           jobject jtask, jdouble priority)
-{
-  m_task_t task = jtask_to_native_task(jtask, env);
-
-  if (!task) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return;
-  }
-  MSG_task_set_priority(task, (double) priority);
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
-                                       jobject jtask)
-{
-  m_task_t task = jtask_to_native_task(jtask, env);
-
-  if (!task) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return;
-  }
-
-  MSG_error_t rv = MSG_task_execute(task);
-
-  jxbt_check_res("MSG_task_execute()", rv,
-                 MSG_HOST_FAILURE | MSG_TASK_CANCELED,
-                 bprintf("while executing task %s",
-                         MSG_task_get_name(task)));
-}
-
 /***************************************************************************************
  * Unsortable functions                                                        *
  ***************************************************************************************/
@@ -779,188 +676,6 @@ Java_org_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
   return jtable;
 }
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
-                                    jstring jalias, jobject jtask,
-                                    jdouble jtimeout)
-{
-
-  MSG_error_t rv;
-  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  m_task_t task = jtask_to_native_task(jtask, env);
-
-
-  if (!task) {
-    (*env)->ReleaseStringUTFChars(env, jalias, alias);
-    jxbt_throw_notbound(env, "task", jtask);
-    return;
-  }
-
-  /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
-  MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
-  rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  jxbt_check_res("MSG_task_send_with_timeout()", rv,
-                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
-                 bprintf("while sending task %s to mailbox %s",
-                         MSG_task_get_name(task), alias));
-}
-
-static void msg_task_cancel_on_failed_dsend(void*t) {
-       m_task_t task = t;
-       JNIEnv *env =get_current_thread_env();
-       jobject jtask_global = MSG_task_get_data(task);
-
-       /* Destroy the global ref so that the JVM can free the stuff */
-       (*env)->DeleteGlobalRef(env, jtask_global);
-       MSG_task_set_data(task, NULL);
-       MSG_task_destroy(task);
-}
-
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
-                                           jstring jalias, jobject jtask,
-                                           jdouble jmaxRate)
-{
-  m_task_t task = jtask_to_native_task(jtask, env);
-  MSG_error_t rv;
-  const char *alias;
-
-  if (!task) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return;
-  }
-
-  alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
-  MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
-  rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  jxbt_check_res("MSG_task_send_bounded()", rv,
-                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
-                 bprintf
-                 ("while sending task %s to mailbox %s with max rate %f",
-                  MSG_task_get_name(task), alias, (double) jmaxRate));
-
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls,
-                                       jstring jalias, jdouble jtimeout,
-                                       jobject jhost)
-{
-  MSG_error_t rv;
-  m_task_t task = NULL;
-  m_host_t host = NULL;
-  jobject jtask_global, jtask_local;
-  const char *alias;
-
-  if (jhost) {
-    host = jhost_get_native(env, jhost);
-
-    if (!host) {
-      jxbt_throw_notbound(env, "host", jhost);
-      return NULL;
-    }
-  }
-
-  alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
-  if (rv != MSG_OK) {
-       switch (rv) {
-               case MSG_TIMEOUT:
-                       jxbt_throw_time_out_failure(env,NULL);
-               break;
-               case MSG_TRANSFER_FAILURE:
-                       jxbt_throw_transfer_failure(env,NULL);
-               break;
-               case MSG_HOST_FAILURE:
-                       jxbt_throw_host_failure(env,NULL);
-               break;
-               default:
-                       jxbt_throw_native(env,bprintf("receive failed"));
-       }
-       return NULL;
-  }
-  jtask_global = MSG_task_get_data(task);
-
-  /* Convert the global ref into a local ref so that the JVM can free the stuff */
-  jtask_local = (*env)->NewLocalRef(env, jtask_global);
-  (*env)->DeleteGlobalRef(env, jtask_global);
-  MSG_task_set_data(task, NULL);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  jxbt_check_res("MSG_task_receive_ext()", rv,
-                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
-                 bprintf("while receiving from mailbox %s", alias));
-
-  return (jobject) jtask_local;
-}
-
-JNIEXPORT jboolean JNICALL
-Java_org_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls,
-                                      jstring jalias)
-{
-
-  const char *alias;
-  int rv;
-
-  alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen(alias);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  return (jboolean) rv;
-}
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls,
-                                              jstring jalias,
-                                              jobject jhost)
-{
-  int rv;
-  const char *alias;
-
-  m_host_t host = jhost_get_native(env, jhost);
-
-  if (!host) {
-    jxbt_throw_notbound(env, "host", jhost);
-    return -1;
-  }
-  alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen_from_host(alias, host);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  return (jint) rv;
-}
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_taskListenFrom(JNIEnv * env, jclass cls,
-                                          jstring jalias)
-{
-
-  int rv;
-  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
-
-  rv = MSG_task_listen_from(alias);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-
-  return (jint) rv;
-}
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
                                        jstring jdeploymentFile)
index 5b4172b..eb800fd 100644 (file)
@@ -189,71 +189,6 @@ Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_MsgNative_hostIsAvail
     (JNIEnv *, jclass, jobject);
 
-/*
- * Class               simgrid_msg_Msg
- * Method              taskGetSender
- * Signature   (Lsimgrid/msg/Task;)Lsimgrid/msg/Process;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_taskGetSender
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskGetSource
- * Signature   (Lsimgrid/msg/Task;)Lsimgrid/msg/Host;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_taskGetSource
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskCancel
- * Signature   (Lsimgrid/msg/Task;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskCancel
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskGetComputeDuration
- * Signature   (Lsimgrid/msg/Task;)D
- */
-JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_MsgNative_taskGetComputeDuration
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskGetRemainingDuration
- * Signature   (Lsimgrid/msg/Task;)D
- */
-JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv *, jclass,
-                                                    jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskSetPriority
- * Signature   (Lsimgrid/msg/Task;D)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskSetPriority
-    (JNIEnv *, jclass, jobject, jdouble);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              taskExecute
- * Signature   (Lsimgrid/msg/Task;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskExecute
-    (JNIEnv *, jclass, jobject);
-
-JNIEXPORT jobject JNICALL
-    Java_org_simgrid_msg_MsgNative_taskReceive
-    (JNIEnv *, jclass, jstring, jdouble, jobject);
-
-JNIEXPORT void JNICALL
-    Java_org_simgrid_msg_MsgNative_taskSend
-    (JNIEnv *, jclass, jstring, jobject, jdouble);
-
 /*
  * Class               simgrid_msg_Msg
  * Method              getClock
@@ -295,20 +230,6 @@ JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
                                        jstring jplatformFile);
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring,
-                                           jobject, jdouble);
-
-JNIEXPORT jboolean JNICALL
-Java_org_simgrid_msg_MsgNative_taskListen(JNIEnv *, jclass, jstring);
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv *, jclass, jstring,
-                                              jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_taskListenFrom(JNIEnv *, jclass, jstring);
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
                                        jstring jdeploymentFile);
index 068a747..d376bbc 100644 (file)
@@ -181,6 +181,42 @@ Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env,
     jxbt_throw_jni(env, "global ref allocation failed");
 }
 
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_cancel(JNIEnv * env,
+                                      jobject jtask)
+{
+  m_task_t ptask = jtask_to_native_task(jtask, env);
+
+  if (!ptask) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+
+  MSG_error_t rv = MSG_task_cancel(ptask);
+
+  jxbt_check_res("MSG_task_cancel()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_execute(JNIEnv * env,
+                                       jobject jtask)
+{
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+  if (!task) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+
+  MSG_error_t rv = MSG_task_execute(task);
+
+  jxbt_check_res("MSG_task_execute()", rv,
+                 MSG_HOST_FAILURE | MSG_TASK_CANCELED,
+                 bprintf("while executing task %s",
+                         MSG_task_get_name(task)));
+}
+
 JNIEXPORT jstring JNICALL
 Java_org_simgrid_msg_Task_getName(JNIEnv * env,
                                        jobject jtask) {
@@ -210,6 +246,181 @@ Java_org_simgrid_msg_Task_getSender(JNIEnv * env,
   return (jobject) native_to_java_process(process);
 }
 
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Task_getSource(JNIEnv * env,
+                                         jobject jtask)
+{
+  m_host_t host;
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+  if (!task) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return NULL;
+  }
+
+  host = MSG_task_get_source(task);
+
+  if (!MSG_host_get_data(host)) {
+    jxbt_throw_jni(env, "MSG_task_get_source() failed");
+    return NULL;
+  }
+
+  return (jobject) MSG_host_get_data(host);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_org_simgrid_msg_Task_getComputeDuration(JNIEnv * env,
+                                                  jobject jtask)
+{
+  m_task_t ptask = jtask_to_native_task(jtask, env);
+
+  if (!ptask) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return -1;
+  }
+  return (jdouble) MSG_task_get_compute_duration(ptask);
+}
+
+JNIEXPORT jdouble JNICALL
+Java_org_simgrid_msg_Task_getRemainingDuration(JNIEnv * env, jobject jtask)
+{
+  m_task_t ptask = jtask_to_native_task(jtask, env);
+
+  if (!ptask) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return -1;
+  }
+  return (jdouble) MSG_task_get_remaining_computation(ptask);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_setPriority(JNIEnv * env,
+                                           jobject jtask, jdouble priority)
+{
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+  if (!task) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+  MSG_task_set_priority(task, (double) priority);
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask,
+                                    jstring jalias,
+                                    jdouble jtimeout)
+{
+  MSG_error_t rv;
+  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+
+  if (!task) {
+    (*env)->ReleaseStringUTFChars(env, jalias, alias);
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+
+  /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
+  MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
+  rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+
+  jxbt_check_res("MSG_task_send_with_timeout()", rv,
+                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
+                 bprintf("while sending task %s to mailbox %s",
+                         MSG_task_get_name(task), alias));
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env, jobject jtask,
+                                           jstring jalias,
+                                           jdouble jmaxRate)
+{
+  m_task_t task = jtask_to_native_task(jtask, env);
+  MSG_error_t rv;
+  const char *alias;
+
+  if (!task) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+
+  alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
+  MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
+  rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+
+  jxbt_check_res("MSG_task_send_bounded()", rv,
+                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
+                 bprintf
+                 ("while sending task %s to mailbox %s with max rate %f",
+                  MSG_task_get_name(task), alias, (double) jmaxRate));
+
+}
+
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
+                                       jstring jalias, jdouble jtimeout,
+                                       jobject jhost)
+{
+  MSG_error_t rv;
+  m_task_t task = NULL;
+  m_host_t host = NULL;
+  jobject jtask_global, jtask_local;
+  const char *alias;
+
+  if (jhost) {
+    host = jhost_get_native(env, jhost);
+
+    if (!host) {
+      jxbt_throw_notbound(env, "host", jhost);
+      return NULL;
+    }
+  }
+
+  alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
+  if (rv != MSG_OK) {
+       switch (rv) {
+               case MSG_TIMEOUT:
+                       jxbt_throw_time_out_failure(env,NULL);
+               break;
+               case MSG_TRANSFER_FAILURE:
+                       jxbt_throw_transfer_failure(env,NULL);
+               break;
+               case MSG_HOST_FAILURE:
+                       jxbt_throw_host_failure(env,NULL);
+               break;
+               default:
+                       jxbt_throw_native(env,bprintf("receive failed"));
+       }
+       return NULL;
+  }
+  jtask_global = MSG_task_get_data(task);
+
+  /* Convert the global ref into a local ref so that the JVM can free the stuff */
+  jtask_local = (*env)->NewLocalRef(env, jtask_global);
+  (*env)->DeleteGlobalRef(env, jtask_global);
+  MSG_task_set_data(task, NULL);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+
+  jxbt_check_res("MSG_task_receive_ext()", rv,
+                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
+                 bprintf("while receiving from mailbox %s", alias));
+
+  return (jobject) jtask_local;
+}
+
+
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox) {
        msg_comm_t comm;
index 020caa7..8925bcb 100644 (file)
@@ -107,6 +107,23 @@ Java_org_simgrid_msg_Task_parallelCreate
  */
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_destroy
     (JNIEnv *, jobject);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              cancel
+ * Signature   ()V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel
+    (JNIEnv *, jobject);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              execute
+ * Signature   ()V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute
+    (JNIEnv *, jobject);
+
 /*
  * Class               org_simgrid_msg_Task
  * Method              getName
@@ -122,6 +139,60 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName
  */
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender
     (JNIEnv *, jobject);
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              getSource
+ * Signature   ()Lsimgrid/msg/Host;
+ */
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSource
+    (JNIEnv *, jobject);
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              getComputeDuration
+ * Signature   ()D
+ */
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Task_getComputeDuration
+    (JNIEnv *, jobject);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              getRemainingDuration
+ * Signature   ()D
+ */
+JNIEXPORT jdouble JNICALL
+Java_org_simgrid_msg_Task_getRemainingDuration(JNIEnv *, jobject);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              setPriority
+ * Signature   (D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_setPriority
+    (JNIEnv *, jobject, jdouble);
+
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              send
+ */
+JNIEXPORT void JNICALL
+    Java_org_simgrid_msg_Task_send
+    (JNIEnv *, jobject, jstring, jdouble);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              sendBounded
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_sendBounded(JNIEnv *, jobject, jstring,
+                                               jdouble);
+
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              receive
+ */
+JNIEXPORT jobject JNICALL
+    Java_org_simgrid_msg_Task_receive
+    (JNIEnv *, jclass, jstring, jdouble, jobject);
 
 /**
  * Class               org_simgrid_msg_Task