Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the coupling between main lib and java binding
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Nov 2010 21:44:41 +0000 (21:44 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Nov 2010 21:44:41 +0000 (21:44 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8691 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/java/jmsg.c
src/java/jmsg.h
src/java/simgrid/msg/MsgNative.java
src/simix/smx_context.c

index 43dc519..b44b39f 100644 (file)
@@ -803,6 +803,9 @@ Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls)
   return (jdouble) MSG_get_clock();
 }
 
+/*Hack: let msg load directly the right factory */
+typedef void (*SIMIX_ctx_factory_initializer_t)(smx_context_factory_t *);
+extern SIMIX_ctx_factory_initializer_t factory_initializer_to_use;
 
 JNIEXPORT void JNICALL
 Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs)
@@ -813,6 +816,8 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs)
   jstring jval;
   const char *tmp;
 
+  factory_initializer_to_use = SIMIX_ctx_java_factory_init;
+
   if (jargs)
     argc = (int) (*env)->GetArrayLength(env, jargs);
 
@@ -828,7 +833,6 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs)
   }
 
   MSG_global_init(&argc, argv);
-  SIMIX_context_select_factory("java");
 
   for (index = 0; index < argc; index++)
     free(argv[index]);
@@ -960,34 +964,6 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
   return jtable;
 }
 
-
-JNIEXPORT void JNICALL
-Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,
-                                                jstring jname)
-{
-  char *errmsg = NULL;
-  xbt_ex_t e;
-
-  /* get the C string from the java string */
-  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
-
-  TRY {
-    SIMIX_context_select_factory(name);
-  } CATCH(e) {
-    errmsg = xbt_strdup(e.msg);
-    xbt_ex_free(e);
-  }
-
-  (*env)->ReleaseStringUTFChars(env, jname, name);
-
-  if (errmsg) {
-    char *thrown =
-        bprintf("xbt_select_context_factory() failed: %s", errmsg);
-    free(errmsg);
-    jxbt_throw_jni(env, thrown);
-  }
-}
-
 JNIEXPORT void JNICALL
 Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
                                     jstring jalias, jobject jtask,
index c6ff810..dffe8b9 100644 (file)
@@ -323,9 +323,6 @@ JNIEXPORT void JNICALL
 Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
                                        jstring jplatformFile);
 
-JNIEXPORT void JNICALL
-Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv *, jclass, jstring);
-
 JNIEXPORT void JNICALL
 Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring,
                                            jobject, jdouble);
index 973e4df..e7f7759 100644 (file)
@@ -18,9 +18,6 @@ package simgrid.msg;
  */
 final class MsgNative {
 
-       final static native
-       void selectContextFactory(String name) throws NativeException;
-
        /******************************************************************
         * The natively implemented methods connected to the MSG Process  *
         ******************************************************************/
@@ -428,4 +425,4 @@ final class MsgNative {
         */ 
        final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;
 
-}
\ No newline at end of file
+}
index 15772ca..59638fa 100644 (file)
@@ -84,15 +84,7 @@ int SIMIX_context_select_factory(const char *name)
 
   /* init the desired factory */
   smx_context_factory_t * factory = &simix_global->context_factory;
-  if (!strcmp(name, "java"))
-#ifdef HAVE_JAVA
-    SIMIX_ctx_java_factory_init(factory);
-#else
-    THROW0(not_found_error, 0,
-           "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library");
-#endif                          /* HAVE_JAVA */
-
-  else if (!strcmp(name, "thread"))
+  if (!strcmp(name, "thread"))
 #ifdef CONTEXT_THREADS
     SIMIX_ctx_thread_factory_init(factory);
 #else