Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add dsendBounded + sendBounded with timeout
authorJonathan Rouzaud-Cornabas <jonathan.rouzaud-cornabas@ens-lyon.fr>
Tue, 29 Jan 2013 23:45:52 +0000 (00:45 +0100)
committerJonathan Rouzaud-Cornabas <jonathan.rouzaud-cornabas@ens-lyon.fr>
Tue, 29 Jan 2013 23:45:52 +0000 (00:45 +0100)
org/simgrid/msg/Task.java
src/jmsg_task.c
src/jmsg_task.h

index 7cd0d87..022961d 100644 (file)
@@ -187,7 +187,15 @@ public class Task {
         *  with no way to retrieve whether the communication succeeded or not
         * 
         */
-       public native void dsend(String mailbox);       
+       public native void dsendBounded(String mailbox, double maxrate);
+
+
+       /** Send the task asynchronously on the mailbox identified by the specified name, 
+        *  with no way to retrieve whether the communication succeeded or not
+        * 
+        */
+       public native void dsend(String mailbox);
+       
        /**
         * Sends the task on the mailbox identified by the specified name 
         *
@@ -220,7 +228,26 @@ public class Task {
      * @throws HostFailureException
      * @throws TimeoutException
         */
-       public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
+       public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
+              sendBounded(alias,-1,maxrate);
+        }
+
+
+/**
+        * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) with a timeout
+        *
+     * @param alias
+     * @param timeout
+     * @param maxrate 
+     * @throws TransferFailureException
+     * @throws HostFailureException
+     * @throws TimeoutException
+        */
+       public void sendBounded(String alias, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
+              sendBounded(alias,timeout,maxrate);
+        }
+
+
        /**
         * Sends the task on the mailbox asynchronously
         */
index 5bce012..d7a9fea 100644 (file)
@@ -381,27 +381,28 @@ Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask,
 }
 
 JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env, jobject jtask,
-                                           jstring jalias,
-                                           jdouble jmaxRate)
+Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env,jobject jtask,
+                                    jstring jalias,
+                                    jdouble jtimeout,
+                                   jdouble maxrate)
 {
-  msg_task_t task = jtask_to_native_task(jtask, env);
   msg_error_t rv;
-  const char *alias;
+  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  msg_task_t task = jtask_to_native_task(jtask, env);
+
 
   if (!task) {
+    (*env)->ReleaseStringUTFChars(env, jalias, alias);
     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));
-
   xbt_ex_t e;
   TRY {
-    rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
+    rv = MSG_task_send_with_timeout_bounded(task, alias, (double) jtimeout, (double) maxrate);
   }
   CATCH(e) {
     xbt_ex_free(e);
@@ -409,11 +410,10 @@ Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env, jobject jtask,
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
   if (rv != MSG_OK) {
-    jmsg_throw_status(env, rv);
+       jmsg_throw_status(env, rv);
   }
 }
 
-
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
                                        jstring jalias, jdouble jtimeout,
@@ -611,6 +611,29 @@ Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask,
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 }
 
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobject jtask,
+                                jstring jalias, jdouble maxrate) {
+  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  msg_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_bounded(task, alias, msg_task_cancel_on_failed_dsend,(double)maxrate);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+}
+
+
+
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_Task_listen(JNIEnv * env, jclass cls,
                                                                                                           jstring jalias) {
index bd41164..99b83e6 100644 (file)
@@ -191,13 +191,14 @@ 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);
+    Java_org_simgrid_msg_Task_sendBounded
+    (JNIEnv *, jobject, jstring, jdouble, jdouble);
+
 
 /**
  * Class               org_simgrid_msg_Task
@@ -236,6 +237,15 @@ Java_org_simgrid_msg_Task_isendBounded(JNIEnv *env, jobject jtask, jstring jmail
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask,
                                 jstring jalias);
+
+/**
+ * Class               org_simgrid_msg_Task
+ * Method              dsendBounded
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_dsendBounded(JNIEnv * env, jobject jtask,
+                                jstring jalias, jdouble maxrate);
+
 /**
  * Class               org_simgrid_msg_Task
  * Method              listen