* access to it. It is set automatically during the build of the object.
*/
public long bind = 0;
-
+ /**
+ * Task name
+ */
+ protected String name;
/** Default constructor (all fields to 0 or null) */
public Task() {
/* * * *
* * Getters / Setters * *
* * * */
- /** Gets the name of a task
- * FIXME: Cache it.
- * @return
+ /**
+ * Gets the name of a task
*/
- public native String getName();
- /** Gets the sender of the task
+ public String getName() {
+ return name;
+ }
+ /**
+ * Gets the sender of the task
* Returns null if the task hasn't been sent yet
*/
public native Process getSender();
* @param priority The new priority of the task.
*/
public native void setPriority(double priority);
- /* * * *
- * * Communication-related * *
- * * * */
-
/* * * *
* * Computation-related * *
* The natively implemented method to destroy a MSG task.
*/
protected native void destroy();
+ /* * * *
+ * * Communication-related * *
+ * * * */
/** Send the task asynchronously on the mailbox identified by the specified name,
* with no way to retrieve whether the communication succeeded or not
return jhost;
}
-
-JNIEXPORT jstring JNICALL
-Java_org_simgrid_msg_Host_getName(JNIEnv * env,
- jobject jhost) {
- m_host_t host = jhost_get_native(env, jhost);
- const char* name;
-
- if (!host) {
- jxbt_throw_notbound(env, "host", jhost);
- return NULL;
- }
-
- name = MSG_host_get_name(host);
- if (!name)
- xbt_die("This host has no name...");
-
- return (*env)->NewStringUTF(env, name);
-}
-
JNIEXPORT jint JNICALL
Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
xbt_dynar_t hosts = MSG_hosts_as_dynar();
static jmethodID jtask_method_Comm_constructor;
static jfieldID jtask_field_Task_bind;
+static jfieldID jtask_field_Task_name;
static jfieldID jtask_field_Comm_bind;
static jfieldID jtask_field_Comm_taskBind;
static jfieldID jtask_field_Comm_receiving;
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls) {
jclass jtask_class_Comm = (*env)->FindClass(env, "org/simgrid/msg/Comm");
+ jclass jtask_class_Task = (*env)->FindClass(env, "org/simgrid/msg/Task");
jtask_method_Comm_constructor = (*env)->GetMethodID(env, jtask_class_Comm, "<init>", "()V");
//FIXME: Don't use jxbt_get_sfield directly, it is slower.
jtask_field_Task_bind = jxbt_get_sfield(env, "org/simgrid/msg/Task", "bind", "J");
+ jtask_field_Task_name = jxbt_get_jfield(env, jtask_class_Task, "name", "Ljava/lang/String;");
jtask_field_Comm_bind = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "bind", "J");
jtask_field_Comm_taskBind = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "taskBind", "J");
jtask_field_Comm_receiving = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "receiving", "Z");
- if (!jtask_field_Task_bind || !jtask_field_Comm_bind || !jtask_field_Comm_taskBind ||
+ if (!jtask_field_Task_bind || !jtask_class_Task || !jtask_field_Comm_bind || !jtask_field_Comm_taskBind ||
!jtask_field_Comm_receiving || !jtask_method_Comm_constructor) {
jxbt_throw_native(env,bprintf("Can't find some fields in Java class."));
}
(double) jmessageSize, NULL);
if (jname)
(*env)->ReleaseStringUTFChars(env, jname, name);
-
+ /* sets the task name */
+ (*env)->SetObjectField(env, jtask, jtask_field_Task_name, jname);
/* bind & store the task */
jtask_bind(jtask, task, env);
MSG_task_set_data(task, jtask);
messageSizes, NULL);
(*env)->ReleaseStringUTFChars(env, jname, name);
-
+ /* sets the task name */
+ (*env)->SetObjectField(env, jtask, jtask_field_Task_name, jname);
/* associate the java task object and the native task */
jtask_bind(jtask, task, env);