From f690616d2664e4eca273b47be00c23258a33d813 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 7 Mar 2017 10:24:36 +0100 Subject: [PATCH 1/1] cleanups to the java actors --- src/bindings/java/jmsg_process.cpp | 15 ++++------ .../java/org/simgrid/msg/Process.java | 28 ++++++++----------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index 63c44a5e35..612e38b552 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -76,20 +76,19 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject { jobject jprocess; /* the global reference to the java process instance */ jstring jname; /* the name of the java process instance */ - const char *name; /* the C name of the process */ - const char *hostname; msg_process_t process; /* the native process to create */ msg_host_t host; /* Where that process lives */ - hostname = env->GetStringUTFChars((jstring) jhostname, 0); + const char* hostname = env->GetStringUTFChars((jstring)jhostname, 0); /* get the name of the java process */ jname = jprocess_get_name(jprocess_arg, env); if (!jname) { - jxbt_throw_null(env, - xbt_strdup("Internal error: Process name cannot be nullptr")); + jxbt_throw_null(env, xbt_strdup("Process name cannot be nullptr")); return; } + const char* name = env->GetStringUTFChars(jname, 0); + name = xbt_strdup(name); /* bind/retrieve the msg host */ host = MSG_host_by_name(hostname); @@ -106,17 +105,13 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject return; } - /* build the C name of the process */ - name = env->GetStringUTFChars(jname, 0); - name = xbt_strdup(name); - /* Retrieve the kill time from the process */ jdouble jkill = env->GetDoubleField(jprocess, jprocess_field_Process_killTime); /* Actually build the MSG process */ process = MSG_process_create_with_environment(name, [](int argc, char** argv) -> int { smx_actor_t process = SIMIX_process_self(); // This is the jprocess passed as environment. - // It would be simplet if we could use a closure. + // It would be simpler if we could use a closure. jobject jprocess = (jobject) MSG_process_get_data(process); simgrid::kernel::context::java_main_jprocess(jprocess); return 0; diff --git a/src/bindings/java/org/simgrid/msg/Process.java b/src/bindings/java/org/simgrid/msg/Process.java index 04b5e03979..752f41ebc5 100644 --- a/src/bindings/java/org/simgrid/msg/Process.java +++ b/src/bindings/java/org/simgrid/msg/Process.java @@ -79,17 +79,11 @@ public abstract class Process implements Runnable { /** The arguments of the method function of the process. */ private ArrayList args = new ArrayList<>(); - - /** Default constructor */ - protected Process() { - this.id = nextProcessId++; - } - /** * Constructs a new process from the name of a host and his name. The method * function of the process doesn't have argument. * - * @param hostname The name of the host of the process to create. + * @param hostname Where to create the process. * @param name The name of the process. * * @exception HostNotFoundException if no host with this name exists. @@ -103,7 +97,7 @@ public abstract class Process implements Runnable { * Constructs a new process from the name of a host and his name. The arguments * of the method function of the process are specified by the parameter args. * - * @param hostname The name of the host of the process to create. + * @param hostname Where to create the process. * @param name The name of the process. * @param args The arguments of the main function of the process. * @@ -117,7 +111,7 @@ public abstract class Process implements Runnable { * Constructs a new process from a host and his name. The method function of the * process doesn't have argument. * - * @param host The host of the process to create. + * @param host Where to create the process. * @param name The name of the process. * */ @@ -128,17 +122,19 @@ public abstract class Process implements Runnable { * Constructs a new process from a host and his name, the arguments of here method function are * specified by the parameter args. * - * @param host The host of the process to create. + * @param host Where to create the process. * @param name The name of the process. * @param args The arguments of main method of the process. */ - public Process(Host host, String name, String[]args) { - this(); - this.host = host; + public Process(Host host, String name, String[]args) + { if (host == null) - throw new NullPointerException("Host cannot be NULL"); + throw new NullPointerException("Cannot create a process on the null host"); if (name == null) - throw new NullPointerException("Process name cannot be NULL"); + throw new NullPointerException("Process name cannot be null"); + + this.id = nextProcessId++; + this.host = host; this.name = name; this.args = new ArrayList<>(); @@ -149,7 +145,7 @@ public abstract class Process implements Runnable { * Constructs a new process from a host and his name, the arguments of here method function are * specified by the parameter args. * - * @param host The host of the process to create. + * @param host Where to create the process. * @param name The name of the process. * @param args The arguments of main method of the process. * @param startTime Start time of the process -- 2.20.1