Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add Process.getProperty, Host.getProperty, Host.setProperty (update Changelog)
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 5 Jul 2012 13:26:22 +0000 (15:26 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 5 Jul 2012 13:31:20 +0000 (15:31 +0200)
ChangeLog
org/simgrid/msg/Host.java
org/simgrid/msg/Process.java
src/jmsg_host.c
src/jmsg_host.h
src/jmsg_process.c
src/jmsg_process.h

index a84a2f2..8402234 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,7 +11,8 @@ SimGrid-java (3.8) unstable; urgency=low
 clouds)
  * Change the meaning of Process.restart: now restart the process from the start, like MSG_process_restart in C.
  * Add Process.setAutoRestart: handling of process restart when failed host comes back.
-
+ * Add Process.getProperty, Host.getProperty, Host.getProperty: allows you to retrieve the properties of the processes/hosts
  * Introduce a new context factory based on Coroutines (read the doc to know how to use it): simulations are expected to run up to five times faster.
 SimGrid-java (3.7.1) stable; urgency=low
   
index 0adb866..136f4b2 100644 (file)
@@ -151,7 +151,14 @@ public class Host {
         *
         */ 
        public native double getSpeed();
-
+       /**
+        * @brief Returns the value of a given host property. 
+        */
+       public native String getProperty(String name);
+       /**
+        * @brief Change the value of a given host property. 
+        */
+       public native void setProperty(String name, String value);
     /** This method tests if a host is avail.
      * @return
      */
index c2f9dcd..e8ed072 100644 (file)
@@ -78,9 +78,7 @@ public abstract class Process implements Runnable {
         * Kill time of the process
         */
        public double killTime = -1;
-
-    public Hashtable<String,String> properties;
-
+       
        /**
         * The name of the process.                                                     
         */
@@ -110,7 +108,6 @@ public abstract class Process implements Runnable {
                this.name = null;
                this.bind = 0;
                this.args = new Vector<String>();
-               this.properties = null;
        }
 
 
@@ -173,8 +170,6 @@ public abstract class Process implements Runnable {
                this.args = new Vector<String>();
                if (null != args)
                        this.args.addAll(Arrays.asList(args));
-               
-               this.properties = new Hashtable<String,String>();
        }       
        /**
         * Constructs a new process from a host and his name, the arguments of here method function are
@@ -197,9 +192,7 @@ public abstract class Process implements Runnable {
                this.args = new Vector<String>();
                if (null != args)
                        this.args.addAll(Arrays.asList(args));
-               
-               this.properties = new Hashtable<String,String>();
-               
+                               
                this.startTime = startTime;
                this.killTime = killTime;               
        }
@@ -300,6 +293,11 @@ public abstract class Process implements Runnable {
        public int getPPID()  {
                return ppid;
        }
+       /**
+        * @brief Returns the value of a given process property. 
+        */
+       public native String getProperty(String name);
+       
        /**
         * Set the kill time of the process
         * @param killTime the time when the process is killed
index c776b2b..8cd7da1 100644 (file)
@@ -7,6 +7,7 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/str.h"
+#include "msg/msg.h"
 #include "jmsg.h"
 #include "jmsg_host.h"
 #include "jxbt_utilities.h"
@@ -184,6 +185,45 @@ Java_org_simgrid_msg_Host_getLoad(JNIEnv * env, jobject jhost) {
 
   return (jint) MSG_get_host_msgload(host);
 }
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) {
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (!host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return NULL;
+  }
+  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+
+  const char *property = MSG_host_get_property_value(host, name);
+  if (!property) {
+    return NULL;
+  }
+
+  jobject jproperty = (*env)->NewStringUTF(env, property);
+
+  (*env)->ReleaseStringUTFChars(env, jname, name);
+
+  return jproperty;
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue) {
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (!host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return;
+  }
+  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+  const char *value_java = (*env)->GetStringUTFChars(env, jvalue, 0);
+  char *value = strdup(value_java);
+
+  MSG_host_set_property_value(host,name,value,xbt_free);
+
+  (*env)->ReleaseStringUTFChars(env, jvalue, value);
+  (*env)->ReleaseStringUTFChars(env, jname, name);
+
+}
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_Host_isAvail(JNIEnv * env, jobject jhost) {
   msg_host_t host = jhost_get_native(env, jhost);
index 0ac429b..0dc01c2 100644 (file)
@@ -142,7 +142,20 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed
 JNIEXPORT jint JNICALL
 Java_org_simgrid_msg_Host_getLoad(JNIEnv * env,
                                        jobject jhost);
-
+/*
+ * Class        org_simgrid_msg_Host
+ * Method       getProperty
+ * Signature    (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname);
+/*
+ * Class        org_simgrid_msg_Host
+ * Method       setProperty
+ * Signature    (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jobject jvalue);
 /*
  * Class               org_simgrid_msg_Host
  * Method              isAvail
index a071d98..7773eeb 100644 (file)
@@ -184,13 +184,33 @@ Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls,
   jobject jprocess = native_to_java_process(process);
 
   if (!jprocess) {
-    jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
+    jxbt_throw_jni(env, "get process failed");
     return NULL;
   }
 
   return jprocess;
 }
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) {
+  msg_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return NULL;
+  }
+  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
 
+  const char *property = MSG_process_get_property_value(process, name);
+  if (!property) {
+    return NULL;
+  }
+
+  jobject jproperty = (*env)->NewStringUTF(env, property);
+
+  (*env)->ReleaseStringUTFChars(env, jname, name);
+
+  return jproperty;
+}
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Process_currentProcess(JNIEnv * env, jclass cls)
 {
index 9dc05d5..cfc7051 100644 (file)
@@ -172,7 +172,13 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll
  */
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID
     (JNIEnv *, jclass, jint);
-
+/*
+ * Class        org_simgrid_msg_Process
+ * Method       waitFor
+ * Signature    (D)V
+ */
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname);
 /*
  * Class               org_simgrid_msg_Process
  * Method              currentProcess