From: Samuel Lepetit Date: Thu, 5 Jul 2012 13:26:22 +0000 (+0200) Subject: Add Process.getProperty, Host.getProperty, Host.setProperty (update Changelog) X-Git-Tag: v3_9_90~569^2~19^2~11 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b73d1f8d2cab3df6d8fc87c058c5257f5ce0ad5c?ds=sidebyside Add Process.getProperty, Host.getProperty, Host.setProperty (update Changelog) --- diff --git a/ChangeLog b/ChangeLog index a84a2f2e1e..8402234499 100644 --- 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 diff --git a/org/simgrid/msg/Host.java b/org/simgrid/msg/Host.java index 0adb8662b9..136f4b28df 100644 --- a/org/simgrid/msg/Host.java +++ b/org/simgrid/msg/Host.java @@ -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 */ diff --git a/org/simgrid/msg/Process.java b/org/simgrid/msg/Process.java index c2f9dcd7d9..e8ed072546 100644 --- a/org/simgrid/msg/Process.java +++ b/org/simgrid/msg/Process.java @@ -78,9 +78,7 @@ public abstract class Process implements Runnable { * Kill time of the process */ public double killTime = -1; - - public Hashtable 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(); - this.properties = null; } @@ -173,8 +170,6 @@ public abstract class Process implements Runnable { this.args = new Vector(); if (null != args) this.args.addAll(Arrays.asList(args)); - - this.properties = new Hashtable(); } /** * 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(); if (null != args) this.args.addAll(Arrays.asList(args)); - - this.properties = new Hashtable(); - + 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 diff --git a/src/jmsg_host.c b/src/jmsg_host.c index c776b2b1d1..8cd7da1837 100644 --- a/src/jmsg_host.c +++ b/src/jmsg_host.c @@ -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); diff --git a/src/jmsg_host.h b/src/jmsg_host.h index 0ac429bb5e..0dc01c25da 100644 --- a/src/jmsg_host.h +++ b/src/jmsg_host.h @@ -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 diff --git a/src/jmsg_process.c b/src/jmsg_process.c index a071d98831..7773eeb1ea 100644 --- a/src/jmsg_process.c +++ b/src/jmsg_process.c @@ -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) { diff --git a/src/jmsg_process.h b/src/jmsg_process.h index 9dc05d5b1c..cfc705139b 100644 --- a/src/jmsg_process.h +++ b/src/jmsg_process.h @@ -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