Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move some functions from MsgNative to Task again,to depopulate MsgNative/jmsg.c
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 4 May 2012 15:07:20 +0000 (17:07 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Fri, 4 May 2012 15:07:20 +0000 (17:07 +0200)
org/simgrid/msg/MsgNative.java
org/simgrid/msg/Task.java
src/jmsg.c
src/jmsg.h
src/jmsg_process.c
src/jmsg_process.h
src/jmsg_task.c
src/jmsg_task.h

index c93dd88..3231615 100644 (file)
@@ -264,17 +264,6 @@ final class MsgNative {
         * The natively implemented methods connected to the MSG task     *
         ******************************************************************/
 
-       /**
-        * 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.
-        *
-        * @see                    Task.getSender()
-        */
-       final static native Process taskGetSender(Task task);
-
        /**
         * The natively implementd method to get the source of a task.
         *
@@ -287,17 +276,6 @@ final class MsgNative {
         */
        final static native Host taskGetSource(Task task);
 
-       /**
-        * 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.
-        *
-        * @see                    Task.getName()
-        */
-       final static native String taskGetName(Task task);
-
        /**
         * The natively implemented method to cancel a task.
         *
@@ -378,6 +356,4 @@ final class MsgNative {
         */ 
        final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;
 
-       final static native void taskDSend(String mailbox, Task task);
-
 }
index 441ccb7..3abdfdc 100644 (file)
@@ -104,10 +104,8 @@ public class Task {
      */
        public native String getName();
        /** Gets the sender of the task */ 
-       Process getSender() {
-               return MsgNative.taskGetSender(this);
-       }
-    /** Gets the source of the task
+       public native Process getSender();
+       /** Gets the source of the task
      * @return
      */
        public Host getSource()  {
@@ -177,10 +175,7 @@ public class Task {
         *  with no way to retrieve whether the communication succeeded or not
         * 
         */
-       public void dsend(String mailbox) {
-               MsgNative.taskDSend(mailbox, this);
-       } 
-       
+       public native void dsend(String mailbox);       
        /**
         * Sends the task on the mailbox identified by the specified name 
         *
@@ -290,36 +285,17 @@ public class Task {
 
        /**
         * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
-        *
-     *
-     * @param mailbox
-     * @return
      */
-       public static int listenFrom(String mailbox)  {
-               return MsgNative.taskListenFrom(mailbox);
-       }
+       public native static int listenFrom(String mailbox);
        /**
         * Listen whether there is a waiting task on the mailbox identified by the specified alias
-        *
-     *
-     * @param mailbox
-     * @return
      */
-       public static boolean listen(String mailbox)   {
-               return MsgNative.taskListen(mailbox);
-       }
+       public native static boolean listen(String mailbox);
 
        /**
         * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host.
-        *
-     *
-     * @param alias
-     * @param host
-     * @return
      */
-       public static int listenFromHost(String alias, Host host)   {
-               return MsgNative.taskListenFromHost(alias, host);
-       }
+       public native static int listenFromHost(String alias, Host host);
        
        /**
         * Class initializer, to initialize various JNI stuff
index 87706b5..ac07bfb 100644 (file)
 #include <simgrid/simix.h>
 #include <surf/surfxml_parse.h>
 
+
 #include "smx_context_java.h"
 
 #include "jmsg_process.h"
+
 #include "jmsg_host.h"
 #include "jmsg_task.h"
 #include "jmsg_application_handler.h"
@@ -33,7 +35,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 static JavaVM *__java_vm = NULL;
 
-static jobject native_to_java_process(m_process_t process);
 
 JavaVM *get_java_VM(void)
 {
@@ -49,11 +50,6 @@ JNIEnv *get_current_thread_env(void)
   return env;
 }
 
-static jobject native_to_java_process(m_process_t process)
-{
-  return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
-}
-
 /*
  * The MSG process connected functions implementation.                                 
  */
@@ -513,23 +509,6 @@ Java_org_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
  * The MSG task connected functions implementation.                                    *
  ***************************************************************************************/
 
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls,
-                                         jobject jtask)
-{
-  m_process_t process;
-
-  m_task_t task = jtask_to_native_task(jtask, env);
-
-  if (!task) {
-    jxbt_throw_notbound(env, "task", jtask);
-    return NULL;
-  }
-
-  process = MSG_task_get_sender(task);
-  return (jobject) native_to_java_process(process);
-}
-
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
                                          jobject jtask)
@@ -552,21 +531,6 @@ Java_org_simgrid_msg_MsgNative_taskGetSource(JNIEnv * env, jclass cls,
   return (jobject) MSG_host_get_data(host);
 }
 
-
-JNIEXPORT jstring JNICALL
-Java_org_simgrid_msg_MsgNative_taskGetName(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 NULL;
-  }
-
-  return (*env)->NewStringUTF(env, MSG_task_get_name(task));
-}
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls,
                                       jobject jtask)
@@ -856,29 +820,6 @@ static void msg_task_cancel_on_failed_dsend(void*t) {
        MSG_task_destroy(task);
 }
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskDSend(JNIEnv * env, jclass cls,
-                                    jstring jalias, jobject jtask)
-{
-
-  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));
-  MSG_task_dsend(task, alias, msg_task_cancel_on_failed_dsend);
-
-  (*env)->ReleaseStringUTFChars(env, jalias, alias);
-}
-
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
index d5a231f..5b4172b 100644 (file)
@@ -205,14 +205,6 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_taskGetSender
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_taskGetSource
     (JNIEnv *, jclass, jobject);
 
-/*
- * Class               simgrid_msg_Msg
- * Method              taskGetName
- * Signature   (Lsimgrid/msg/Task;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_simgrid_msg_MsgNative_taskGetName
-    (JNIEnv *, jclass, jobject);
-
 /*
  * Class               simgrid_msg_Msg
  * Method              taskCancel
@@ -258,10 +250,6 @@ JNIEXPORT jobject JNICALL
     Java_org_simgrid_msg_MsgNative_taskReceive
     (JNIEnv *, jclass, jstring, jdouble, jobject);
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskDSend(JNIEnv * env, jclass cls,
-                                    jstring jalias, jobject jtask);
-
 JNIEXPORT void JNICALL
     Java_org_simgrid_msg_MsgNative_taskSend
     (JNIEnv *, jclass, jstring, jobject, jdouble);
index c73bfb7..f0c7489 100644 (file)
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
+jobject native_to_java_process(m_process_t process)
+{
+  return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
+}
+
 jobject jprocess_new_global_ref(jobject jprocess, JNIEnv * env)
 {
   return (*env)->NewGlobalRef(env, jprocess);
index 101c248..8288346 100644 (file)
@@ -13,6 +13,8 @@
 #include <msg/msg.h>
 #include <simgrid/simix.h>
 
+jobject native_to_java_process(m_process_t process);
+
 /**
  * This function returns a global reference to the  java process instance 
  * specified by the parameter jprocess.
index 573a2dc..068a747 100644 (file)
@@ -7,9 +7,13 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "jmsg.h"
+
+#include "smx_context_java.h"
+
+#include "jmsg_host.h"
 #include "jmsg_task.h"
+
 #include "jxbt_utilities.h"
-#include "jmsg_host.h"
 
 #include <msg/msg.h>
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
@@ -190,6 +194,22 @@ Java_org_simgrid_msg_Task_getName(JNIEnv * env,
   return (*env)->NewStringUTF(env, MSG_task_get_name(task));
 }
 
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Task_getSender(JNIEnv * env,
+                                         jobject jtask) {
+  m_process_t process;
+
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+  if (!task) {
+    jxbt_throw_notbound(env, "task", jtask);
+    return NULL;
+  }
+
+  process = MSG_task_get_sender(task);
+  return (jobject) native_to_java_process(process);
+}
+
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox) {
        msg_comm_t comm;
@@ -263,3 +283,89 @@ Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox) {
 
        return jcomm;
 }
+
+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_Task_dsend(JNIEnv * env, jobject jtask,
+                                jstring jalias) {
+
+  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));
+  MSG_task_dsend(task, alias, msg_task_cancel_on_failed_dsend);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+}
+
+JNIEXPORT jboolean JNICALL
+Java_org_simgrid_msg_Task_listen(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_Task_listenFromHost(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_Task_listenFrom(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;
+}
index 53c11a3..020caa7 100644 (file)
@@ -74,6 +74,15 @@ m_task_t jtask_to_native_task(jobject jtask, JNIEnv * env);
  *                                             Otherwise the function returns false.
  */
 jboolean jtask_is_valid(jobject jtask, JNIEnv * env);
+
+/*
+ * Class               org_simgrid_msg_Task
+ * Method              nativeInit
+ * Signature   ();
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls);
+
 /*
  * Class               org_simgrid_msg_Task
  * Method              create
@@ -108,11 +117,12 @@ JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName
 
 /*
  * Class               org_simgrid_msg_Task
- * Method              nativeInit
- * Signature   ();
+ * Method              getSender
+ * Signature   ()Lsimgrid/msg/Process;
  */
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls);
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_getSender
+    (JNIEnv *, jobject);
+
 /**
  * Class               org_simgrid_msg_Task
  * Method              irecv
@@ -127,5 +137,33 @@ Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox);
  */
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox);
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              dsend
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask,
+                                jstring jalias);
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              listen
+ */
+JNIEXPORT jboolean JNICALL
+Java_org_simgrid_msg_Task_listen(JNIEnv *, jclass, jstring);
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              listenFromHost
+ */
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Task_listenFromHost(JNIEnv *, jclass, jstring,
+                                              jobject);
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              listenFrom
+ */
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Task_listenFrom(JNIEnv *, jclass, jstring);
+
+
 
 #endif                          /* !MSG_JTASK_H */