X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f690616d2664e4eca273b47be00c23258a33d813..bef9e56fd601b15454f003bb8d0b66db491ddf9f:/src/bindings/java/org/simgrid/msg/Process.java diff --git a/src/bindings/java/org/simgrid/msg/Process.java b/src/bindings/java/org/simgrid/msg/Process.java index 752f41ebc5..6c06550e87 100644 --- a/src/bindings/java/org/simgrid/msg/Process.java +++ b/src/bindings/java/org/simgrid/msg/Process.java @@ -1,5 +1,4 @@ -/* Copyright (c) 2006-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -48,27 +47,11 @@ public abstract class Process implements Runnable { */ private long bind = 0; /** Indicates if the process is started */ - boolean started; - /** - * Even if this attribute is public you must never access to it. - * It is used to compute the id of an MSG process. - */ - private static long nextProcessId = 0; - - /** - * Even if this attribute is public you must never access to it. - * It is compute automatically during the creation of the object. - * The native functions use this identifier to synchronize the process. - */ - private long id; /** Time at which the process should be created */ protected double startTime = 0; - /** Time at which the process should be killed. - * - * Set at creation, and used internally by SimGrid - */ - private double killTime = -1; + /** Time at which the process should be killed */ + private double killTime = -1; // Used from the C world private String name = null; @@ -124,22 +107,21 @@ public abstract class Process implements Runnable { * * @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 argsParam The arguments of main method of the process. */ - public Process(Host host, String name, String[]args) + public Process(Host host, String name, String[]argsParam) { if (host == null) - throw new NullPointerException("Cannot create a process on the null host"); + throw new IllegalArgumentException("Cannot create a process on the null host"); if (name == null) - throw new NullPointerException("Process name cannot be null"); + throw new IllegalArgumentException("Process name cannot be null"); - this.id = nextProcessId++; this.host = host; this.name = name; this.args = new ArrayList<>(); - if (null != args) - this.args.addAll(Arrays.asList(args)); + if (null != argsParam) + this.args.addAll(Arrays.asList(argsParam)); } /** * Constructs a new process from a host and his name, the arguments of here method function are @@ -158,10 +140,11 @@ public abstract class Process implements Runnable { this.killTime = killTime; } /** - * The natively implemented method to create an MSG process. - * @param hostName A valid (bound) host where create the process. + * The native method to create an MSG process. + * @param host where to create the process. */ - protected native void create(String hostName) throws HostNotFoundException; + protected native void create(Host host); + /** * This method kills all running process of the simulation. * @@ -234,8 +217,13 @@ public abstract class Process implements Runnable { * */ public int getPID() { + if (pid == -1) // Don't traverse the JNI barrier if you already have the answer + pid = nativeGetPID(); return pid; } + // This should not be used: the PID is supposed to be initialized from the C directly when the actor is created, + // but this sometimes fail, so let's play nasty but safe here. + private native int nativeGetPID(); /** * This method returns the PID of the parent of a process. * @@ -297,28 +285,21 @@ public abstract class Process implements Runnable { /** * This method actually creates and run the process. * It is a noop if the process is already launched. - * @throws HostNotFoundException */ - public final void start() throws HostNotFoundException { - if (!started) { - started = true; - create(host.getName()); - } + public final void start() { + if (bind == 0) + create(host); } - /** This method runs the process. Il calls the method function that you must overwrite. */ + /** This method runs the process. It calls the method function that you must overwrite. */ @Override public void run() { - String[] args = null; /* do not fill it before the signal or this.args will be empty */ - try { - args = new String[this.args.size()]; - if (!this.args.isEmpty()) { - this.args.toArray(args); - } + String[] argsArray = new String[this.args.size()]; + this.args.toArray(argsArray); - this.main(args); + this.main(argsArray); } catch(MsgException e) { e.printStackTrace(); @@ -331,7 +312,7 @@ public abstract class Process implements Runnable { } /** - * The main function of the process (to implement). + * The main function of the process (to implement by the user). * * @param args * @throws MsgException