Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar: don't mask fields with parameters in Java
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 055939e..fc4d205 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2017. 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. */
@@ -60,7 +60,7 @@ public abstract class Process implements Runnable {
        private Host host = null;
 
        /** The arguments of the method function of the process. */
-       private ArrayList<String> args = new ArrayList<>();
+       private ArrayList<String> args_ = new ArrayList<>();
 
        /**
         * Constructs a new process from the name of a host and his name. The method
@@ -119,9 +119,9 @@ public abstract class Process implements Runnable {
                this.host = host;
                this.name = name;
 
-               this.args = new ArrayList<>();
+               this.args_ = new ArrayList<>();
                if (null != args)
-                       this.args.addAll(Arrays.asList(args));
+                       this.args_.addAll(Arrays.asList(args));
        }
        /**
         * Constructs a new process from a host and his name, the arguments of here method function are
@@ -217,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.
         *
@@ -280,7 +285,6 @@ 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() {
           if (bind == 0)
@@ -294,9 +298,9 @@ public abstract class Process implements Runnable {
                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);
+                       args = new String[this.args_.size()];
+                       if (!this.args_.isEmpty()) {
+                               this.args_.toArray(args);
                        }
 
                        this.main(args);