* under the terms of the license (GNU LGPL) which comes with this package. */
#include <msg/msg.h>
-#include <simix/context.h>
+#include <simgrid/simix.h>
#include <surf/surfxml_parse.h>
#include "smx_context_java.h"
#include "jmsg.h"
+/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */
+#ifndef JNIEXPORT
+#define JNIEXPORT
+#endif
+#ifndef JNICALL
+#define JNICALL
+#endif
+/* end of eclipse-mandated pimple */
+
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
static JavaVM *__java_vm = NULL;
(xbt_main_func_t) jprocess,
/*data*/ NULL,
host,
+ /*kill_time*/0.,
/*argc, argv, properties*/
0,NULL,NULL);
}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jobject jprocess,
+ jdouble jseconds) {
+ m_process_t process = jprocess_to_native_process(jprocess, env);
+
+ if (!process) {
+ jxbt_throw_notbound(env, "process", jprocess);
+ return;
+ }
+ MSG_error_t rv = MSG_process_sleep((double)jseconds);
+
+ jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
+ bprintf("unexpected error , please report this bug"));
+}
+
+
JNIEXPORT void JNICALL
Java_org_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
jobject jprocess)
XBT_DEBUG("Looking for host '%s'",name);
/* get the host by name (the hosts are created during the grid resolution) */
host = MSG_get_host_by_name(name);
- XBT_DEBUG("MSG gave %p as native host (simdata=%p)", host,host? host->simdata:NULL);
+ XBT_DEBUG("MSG gave %p as native host (smx_host=%p)", host,host? host->smx_host:NULL);
if (!host) { /* invalid name */
jxbt_throw_host_not_found(env, name);
if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */
- /* instanciate a new java host */
+ /* Instantiate a new java host */
jhost = jhost_new_instance(env);
if (!jhost) {
/* Cleanup java hosts */
hosts = MSG_hosts_as_dynar();
for (index = 0; index < xbt_dynar_length(hosts) - 1; index++) {
- jhost = (jobject) xbt_dynar_get_as(hosts,index,m_host_t)->data;
+ jhost = (jobject) MSG_host_get_data(xbt_dynar_get_as(hosts,index,m_host_t));
if (jhost)
jhost_unref(env, jhost);
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_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,
jstring jalias, jobject jtask,
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 */