as sufficiently prevalent for us to not dupplicate its features.
* Make Process.kill(process) an instance method, not a static one
* Fix a bug around Process.kill()
- * Add dsend and simulatedSleep to the bindings.
-
+ * Add the asynchronous API to the bindings.
+ * Add "sleep" in Process with Thread-like syntax/use.
+ * Change the way the Process are created in ApplicationHandler: a full
+constructor is now needed for your child classes.
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
SimGrid-java (3.6) unstable; urgency=low
public class Forwarder extends Process {
-
+ public Forwarder(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 3) {
Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
import java.util.ArrayList;
import org.simgrid.msg.Comm;
+import org.simgrid.msg.Host;
import org.simgrid.msg.Process;
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
import org.simgrid.msg.Process;;
public class Master extends Process {
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 4) {
Msg.info("Master needs 4 arguments");
import org.simgrid.msg.Process;
public class Slave extends Process {
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
if (args.length < 1) {
Msg.info("Slave needs 1 argument (its number)");
public class Forwarder extends Process {
-
+ public Forwarder(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 3) {
Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
import org.simgrid.msg.Process;;
public class Master extends Process {
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 4) {
Msg.info("Master needs 4 arguments");
import org.simgrid.msg.Process;
public class Slave extends Process {
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
if (args.length < 1) {
Msg.info("Slave needs 1 argument (its number)");
import org.simgrid.msg.Process;
public class Master extends Process {
+ public Master(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
public void main(String[] args) throws MsgException {
if (args.length < 4) {
Msg.info("Master needs 4 arguments");
import org.simgrid.msg.*;
public class Slave extends org.simgrid.msg.Process {
- public void main(String[] args) throws MsgException {
+ public Slave(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
+ public void main(String[] args) throws MsgException {
if (args.length < 1) {
Msg.info("Slave needs 1 argument (its number)");
System.exit(1);
public class Coordinator extends Process {
-
+ public Coordinator(String hostname, String name) throws HostNotFoundException {
+ super(hostname, name);
+ }
LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
int CsToServe;
import org.simgrid.msg.Process;
public class Node extends Process {
-
+ public Node(String hostname, String name) throws HostNotFoundException {
+ super(hostname, name);
+ }
public void request(double CStime) throws MsgException {
RequestTask req = new RequestTask(this.name);
Msg.info("Send a request to the coordinator");
import org.simgrid.msg.Process;
public class Receiver extends Process {
-
+ public Receiver(String hostname, String name) throws HostNotFoundException {
+ super(hostname, name);
+ }
final double commSizeLat = 1;
final double commSizeBw = 100000000;
import org.simgrid.msg.Process;
public class Sender extends Process {
-
+ public Sender(String hostname, String name) throws HostNotFoundException {
+ super(hostname, name);
+ }
private final double commSizeLat = 1;
final double commSizeBw = 100000000;
*/
package org.simgrid.msg;
-
import java.util.Hashtable;
import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
public final class ApplicationHandler {
}
/**
- *
+ * Method called to create the process
*/
@SuppressWarnings("unchecked")
public static void createProcess() {
try {
Class<Process> cls = (Class<Process>) Class.forName(function);
-
- Process process = cls.newInstance();
- process.name = function;
- process.id = org.simgrid.msg.Process.nextProcessId++;
-
- process.create(hostName);
- Vector<String> args_ = args;
- int size = args_.size();
-
- for (int index = 0; index < size; index++)
- process.args.add(args_.get(index));
-
- process.properties = properties;
- properties = new Hashtable<String,String>();
-
- } catch(HostNotFoundException e) {
+ Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class});
+ String[] args_ = args.toArray(new String[args.size()]);
+ Process process = constructor.newInstance(Host.getByName(hostName), function, args_);
+ }
+ catch (NoSuchMethodException e) {
+ throw new RuntimeException("Can't find the correct constructor for the class " + function + ". \n" +
+ "Is there a constructor with the signature: \"Host host, String name, String[]args\" in the class ?");
+ }
+ catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ catch(HostNotFoundException e) {
System.out.println(e.toString());
e.printStackTrace();
throw new RuntimeException("The impossible happened (yet again): the host that I have were not found",e);
}
+ this.properties = new Hashtable<String,String>();
+
}
/**
* The natively implemented method to create an MSG process.
* FIXME: Not optimal, maybe we should have two native functions.
* @param millis the length of time to sleep in milliseconds.
*/
- public static void sleep(long millis) {
+ public static void sleep(long millis) {
sleep(millis,0);
}
/**
return;
}
MSG_error_t rv = MSG_process_sleep((double)jseconds);
-
- jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
- bprintf("unexpected error , please report this bug"));
-
+ if (rv != MSG_OK) {
+// smx_ctx_java_stop(smx_ctx_java_self());
+ }
}
JNIEXPORT void JNICALL
static smx_context_t my_current_context = NULL;
-static smx_context_t smx_ctx_java_self(void);
static smx_context_t
smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
char **argv,
(*factory)->get_data = smx_ctx_base_get_data;
}
-static smx_context_t smx_ctx_java_self(void)
+smx_context_t smx_ctx_java_self(void)
{
return my_current_context;
}
context->jenv = get_current_thread_env();
jprocess_start(((smx_ctx_java_t) context)->jprocess,
get_current_thread_env());
- }else{
+ }
+ else {
my_current_context = (smx_context_t)context;
}
context->super.data = data;
void SIMIX_ctx_java_factory_init(smx_context_factory_t *factory);
void smx_ctx_java_stop(smx_context_t context);
-
+smx_context_t smx_ctx_java_self(void);
SG_END_DECL()
#endif /* !_XBT_CONTEXT_JAVA_H */