From: Frederic Suter Date: Fri, 17 Jun 2016 07:41:22 +0000 (+0200) Subject: reduce Java debt (endless wip) X-Git-Tag: v3_14~976^2~15 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/40d3634e5448cd560a6989d07d10ec30e85cf533 reduce Java debt (endless wip) --- diff --git a/examples/java/app/bittorrent/Main.java b/examples/java/app/bittorrent/Main.java index 7443a7eb3a..021b1c54a8 100644 --- a/examples/java/app/bittorrent/Main.java +++ b/examples/java/app/bittorrent/Main.java @@ -9,7 +9,11 @@ package app.bittorrent; import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; -public class Main{ +class Main{ + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws MsgException { Msg.init(args); if(args.length < 2) { diff --git a/examples/java/app/centralizedmutex/Main.java b/examples/java/app/centralizedmutex/Main.java index 6d8c6d1653..32a584d134 100644 --- a/examples/java/app/centralizedmutex/Main.java +++ b/examples/java/app/centralizedmutex/Main.java @@ -10,6 +10,10 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws NativeException { Msg.init(args); diff --git a/examples/java/app/masterworker/Main.java b/examples/java/app/masterworker/Main.java index cc24eed70f..c1e905c87d 100644 --- a/examples/java/app/masterworker/Main.java +++ b/examples/java/app/masterworker/Main.java @@ -14,9 +14,9 @@ import org.simgrid.msg.NativeException; class Main { public static final int TASK_COMP_SIZE = 10000000; public static final int TASK_COMM_SIZE = 10000000; - /* This only contains the launcher. If you do nothing more than than you can run java simgrid.msg.Msg - * which also contains such a launcher - */ + private Main() { + throw new IllegalAccessError("Utility class"); + } public static void main(String[] args) throws NativeException { /* initialize the MSG simulation. Must be done before anything else (even logging). */ diff --git a/examples/java/app/pingpong/Receiver.java b/examples/java/app/pingpong/Receiver.java index 80d832e156..2617455b45 100644 --- a/examples/java/app/pingpong/Receiver.java +++ b/examples/java/app/pingpong/Receiver.java @@ -21,8 +21,6 @@ public class Receiver extends Process { public void main(String[] args) throws MsgException { Msg.info("hello!"); - double time = Msg.getClock(); - Msg.info("try to get a task"); PingPongTask task = (PingPongTask)Task.receive(getHost().getName()); @@ -31,7 +29,7 @@ public class Receiver extends Process { Msg.info("Got at time "+ timeGot); Msg.info("Was sent at time "+timeSent); - time = timeSent; + double time = timeSent; double communicationTime = timeGot - time; Msg.info("Communication time : " + communicationTime); diff --git a/examples/java/cloud/migration/Daemon.java b/examples/java/cloud/migration/Daemon.java index 68a31f3153..d03d09aed6 100644 --- a/examples/java/cloud/migration/Daemon.java +++ b/examples/java/cloud/migration/Daemon.java @@ -10,29 +10,28 @@ import org.simgrid.msg.*; import org.simgrid.msg.Process; public class Daemon extends Process { - private Task currentTask; - public Daemon(VM vm, int load) { - super((Host)vm,"Daemon"); - currentTask = new Task(this.getHost().getName()+"-daemon-0", this.getHost().getSpeed()*100, 0); - } - public void main(String[] args) throws MsgException { - int i = 1; - while(!Main.isEndOfTest()) { - // TODO the binding is not yet available - try { - currentTask.execute(); - } catch (HostFailureException e) { - e.printStackTrace(); - } catch (TaskCancelledException e) { - System.out.println("task cancelled"); - suspend(); // Suspend the process - } - currentTask = new Task(this.getHost().getName()+"-daemon-"+(i++), this.getHost().getSpeed()*100, 0); -// Msg.info(currentTask.getName()); - } + private Task currentTask; + public Daemon(VM vm, int load) { + super((Host)vm,"Daemon"); + currentTask = new Task(this.getHost().getName()+"-daemon-0", this.getHost().getSpeed()*100, 0); + } + public void main(String[] args) throws MsgException { + int i = 1; + while(!Main.isEndOfTest()) { + // TODO the binding is not yet available + try { + currentTask.execute(); + } catch (HostFailureException e) { + e.printStackTrace(); + } catch (TaskCancelledException e) { + System.out.println("task cancelled"); + suspend(); // Suspend the process } + currentTask = new Task(this.getHost().getName()+"-daemon-"+(i++), this.getHost().getSpeed()*100, 0); + } +} - public double getRemaining(){ - return this.currentTask.getFlopsAmount(); - } + public double getRemaining(){ + return this.currentTask.getFlopsAmount(); + } } diff --git a/examples/java/cloud/migration/Main.java b/examples/java/cloud/migration/Main.java index af1aa2586b..2ae9be046c 100644 --- a/examples/java/cloud/migration/Main.java +++ b/examples/java/cloud/migration/Main.java @@ -14,6 +14,10 @@ import org.simgrid.msg.MsgException; public class Main { private static boolean endOfTest = false; + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void setEndOfTest(){ endOfTest=true; } diff --git a/examples/java/cloud/migration/Test.java b/examples/java/cloud/migration/Test.java index 2e59f4be21..279917e83a 100644 --- a/examples/java/cloud/migration/Test.java +++ b/examples/java/cloud/migration/Test.java @@ -18,22 +18,27 @@ public class Test extends Process{ super(hostname, name); } - public void main(String[] strings) throws MsgException { - double startTime = 0; - double endTime = 0; + public void doMigration(VM vm, Host src, Host dst) throws HostFailureException{ + Msg.info(" - Launch migration from "+ src.getName() +" to " + dst.getName()); + double startTime = Msg.getClock(); + vm.migrate(dst); + double endTime = Msg.getClock(); + Msg.info(" - End of Migration from "+ src.getName() +" to " + dst.getName()+ " (duration:" + + (endTime-startTime)+")"); + } - /* get hosts 1 and 2*/ + public void main(String[] strings) throws MsgException { Host host0 = null; Host host1 = null; - try { + /* get hosts 1 and 2*/ host0 = Host.getByName("PM0"); host1 = Host.getByName("PM1"); }catch (HostNotFoundException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); } - List vms = new ArrayList(); + List vms = new ArrayList<>(); /* Create VM1 */ int dpRate = 70; @@ -47,8 +52,7 @@ public class Test extends Process{ Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see " + "whether it impacts or not the migration time"); - XVM vm1 = null; - vm1 = new XVM(host0, "vm0", + XVM vm1 = new XVM(host0, "vm0", 1, // Nb of vcpu 2048, // Ramsize, 125, // Net Bandwidth @@ -62,7 +66,7 @@ public class Test extends Process{ /* Collocated VMs */ int collocatedSrc = 6; - int vmSrcLoad[] = { + int[] vmSrcLoad = { 80, 0, 90, @@ -71,7 +75,7 @@ public class Test extends Process{ 90, }; - XVM tmp = null; + XVM tmp; for (int i=1 ; i<= collocatedSrc ; i++){ tmp = new XVM(host0, "vm"+i, 1, // Nb of vcpu @@ -88,7 +92,7 @@ public class Test extends Process{ } int collocatedDst = 6; - int vmDstLoad[] = { + int[] vmDstLoad = { 0, 40, 90, @@ -114,31 +118,14 @@ public class Test extends Process{ Msg.info("Round trip of VM1 (load "+load1+"%)"); vm1.setLoad(load1); - Msg.info(" - Launch migration from PM0 to PM1"); - startTime = Msg.getClock(); - vm1.migrate(host1); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from PM0 to PM1 (duration:"+(endTime-startTime)+")"); - Msg.info(" - Launch migration from PM1 to PM0"); - startTime = Msg.getClock(); - vm1.migrate(host0); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from PM1 to PM0 (duration:"+(endTime-startTime)+")"); - + doMigration(vm1, host0, host1); + doMigration(vm1, host1, host0); Msg.info(""); Msg.info(""); Msg.info("Round trip of VM1 (load "+load2+"%)"); vm1.setLoad(load2); - Msg.info(" - Launch migration from PM0 to PM1"); - startTime = Msg.getClock(); - vm1.migrate(host1); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from PM0 to PM1 (duration:"+(endTime-startTime)+")"); - Msg.info(" - Launch migration from PM1 to PM0"); - startTime = Msg.getClock(); - vm1.migrate(host0); - endTime = Msg.getClock(); - Msg.info(" - End of Migration from PM1 to PM0 (duration:"+(endTime-startTime)+")"); + doMigration(vm1, host0, host1); + doMigration(vm1, host1, host0); Main.setEndOfTest(); Msg.info("Forcefully destroy VMs"); diff --git a/examples/java/dht/chord/Main.java b/examples/java/dht/chord/Main.java index 44e242537b..0128a89b11 100644 --- a/examples/java/dht/chord/Main.java +++ b/examples/java/dht/chord/Main.java @@ -8,7 +8,11 @@ package dht.chord; import org.simgrid.msg.Msg; -public class Main { +class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) { Msg.init(args); if(args.length < 2) { diff --git a/examples/java/dht/kademlia/Common.java b/examples/java/dht/kademlia/Common.java index 9ec3d579cb..890899f687 100644 --- a/examples/java/dht/kademlia/Common.java +++ b/examples/java/dht/kademlia/Common.java @@ -29,4 +29,7 @@ public class Common { public final static int MAX_STEPS = 10; public final static int JOIN_BUCKETS_QUERIES = 1; + private Common() { + throw new IllegalAccessError("Utility class"); + } } diff --git a/examples/java/dht/kademlia/Main.java b/examples/java/dht/kademlia/Main.java index ffb9dd46bd..dacbfae0cc 100644 --- a/examples/java/dht/kademlia/Main.java +++ b/examples/java/dht/kademlia/Main.java @@ -8,7 +8,11 @@ package dht.kademlia; import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; -public class Main { +class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws MsgException { Msg.init(args); if(args.length < 2) { diff --git a/examples/java/energy/consumption/Main.java b/examples/java/energy/consumption/Main.java index 1297b9afa8..f403e0d84c 100644 --- a/examples/java/energy/consumption/Main.java +++ b/examples/java/energy/consumption/Main.java @@ -14,6 +14,9 @@ public class Main { public static final double task_comp_size = 10; public static final double task_comm_size = 10; public static final int hostNB = 2 ; + private Main() { + throw new IllegalAccessError("Utility class"); + } public static void main(String[] args) throws MsgException { Msg.energyInit(); diff --git a/examples/java/io/file/Main.java b/examples/java/io/file/Main.java index 998f911dad..c1b72dd362 100644 --- a/examples/java/io/file/Main.java +++ b/examples/java/io/file/Main.java @@ -11,6 +11,10 @@ import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws MsgException { Msg.init(args); if(args.length < 1) { diff --git a/examples/java/io/storage/Main.java b/examples/java/io/storage/Main.java index 9b77b8ddfe..b81a1430ab 100644 --- a/examples/java/io/storage/Main.java +++ b/examples/java/io/storage/Main.java @@ -10,6 +10,10 @@ import org.simgrid.msg.Host; import org.simgrid.msg.MsgException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws MsgException { Msg.init(args); if(args.length < 1) { diff --git a/examples/java/process/kill/Main.java b/examples/java/process/kill/Main.java index 8a1065aff2..f62b469575 100644 --- a/examples/java/process/kill/Main.java +++ b/examples/java/process/kill/Main.java @@ -11,6 +11,10 @@ import org.simgrid.msg.MsgException; import org.simgrid.msg.NativeException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws NativeException { /* initialize the MSG simulation. Must be done before anything else (even logging). */ Msg.init(args); diff --git a/examples/java/process/migration/Main.java b/examples/java/process/migration/Main.java index 66eb2b1687..9498dbc861 100644 --- a/examples/java/process/migration/Main.java +++ b/examples/java/process/migration/Main.java @@ -15,6 +15,10 @@ class Main { protected static Mutex mutex; protected static Process processToMigrate = null; + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws NativeException { Msg.init(args); if(args.length < 1) { diff --git a/examples/java/process/startkilltime/Main.java b/examples/java/process/startkilltime/Main.java index e24ecd1fb1..2168b16262 100644 --- a/examples/java/process/startkilltime/Main.java +++ b/examples/java/process/startkilltime/Main.java @@ -9,6 +9,10 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws NativeException { Msg.init(args); if(args.length < 2) { diff --git a/examples/java/process/suspend/Main.java b/examples/java/process/suspend/Main.java index 22af11311a..04510e852d 100644 --- a/examples/java/process/suspend/Main.java +++ b/examples/java/process/suspend/Main.java @@ -9,6 +9,10 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) { Msg.init(args); if(args.length < 1) { diff --git a/examples/java/task/priority/Main.java b/examples/java/task/priority/Main.java index adf7fc2d10..29133c13e8 100644 --- a/examples/java/task/priority/Main.java +++ b/examples/java/task/priority/Main.java @@ -10,6 +10,10 @@ import org.simgrid.msg.NativeException; /* Demonstrates the use of Task.setPriority to change the computation priority of a task */ public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws NativeException { Msg.init(args); if(args.length < 2) { diff --git a/examples/java/trace/pingpong/Main.java b/examples/java/trace/pingpong/Main.java index bd43e174ac..da7d657207 100644 --- a/examples/java/trace/pingpong/Main.java +++ b/examples/java/trace/pingpong/Main.java @@ -11,6 +11,10 @@ import org.simgrid.msg.MsgException; import org.simgrid.msg.NativeException; public class Main { + private Main() { + throw new IllegalAccessError("Utility class"); + } + public static void main(String[] args) throws MsgException, NativeException { Msg.init(args); if(args.length < 1) { diff --git a/examples/java/trace/pingpong/Receiver.java b/examples/java/trace/pingpong/Receiver.java index 0a57d52496..27716559d1 100644 --- a/examples/java/trace/pingpong/Receiver.java +++ b/examples/java/trace/pingpong/Receiver.java @@ -25,9 +25,6 @@ public class Receiver extends Process { public void main(String[] args) throws MsgException { Msg.info("hello!"); Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing"); - double communicationTime=0; - - double time = Msg.getClock(); /* Wait for the ping */ Msg.info("try to get a task"); @@ -38,9 +35,9 @@ public class Receiver extends Process { Msg.info("Got at time "+ timeGot); Msg.info("Was sent at time "+timeSent); - time=timeSent; + double time=timeSent; - communicationTime=timeGot - time; + double communicationTime=timeGot - time; Msg.info("Communication time : " + communicationTime); Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----"); diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 35527c0333..150b0cc9e6 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -16,7 +16,13 @@ import java.nio.file.Path; public final class NativeLib { /* Statically load the library which contains all native functions used in here */ - static private boolean isNativeInited = false; + private static boolean isNativeInited = false; + static Path tempDir = null; + + private NativeLib() { + throw new IllegalAccessError("Utility class"); + } + public static void nativeInit() { if (isNativeInited) return; @@ -25,7 +31,7 @@ public final class NativeLib { NativeLib.nativeInit("winpthread-1"); NativeLib.nativeInit("simgrid"); - NativeLib.nativeInit("simgrid-java"); + NativeLib.nativeInit("simgrid-java"); isNativeInited = true; } @@ -38,7 +44,7 @@ public final class NativeLib { try { System.loadLibrary(name); } catch (UnsatisfiedLinkError systemException) { - if (! name.equals("boost_context")) { // Ignore when we cannot load boost_context + if (! "boost_context".equals(name)) { // Ignore when we cannot load boost_context System.err.println("\nCannot load the bindings to the "+name+" library in path "+getPath()); Throwable cause = embeededException.getCause(); @@ -48,7 +54,7 @@ public final class NativeLib { else if (cause.getMessage().matches(".*libboost_context.so.*")) System.err.println("HINT: Try to install the boost-context package (sudo apt-get install libboost-context-dev)."); else - System.err.println("Try to install the missing dependencies, which name should appear above."); + System.err.println("Try to install the missing dependencies, which name should appear above."); } else { System.err.println("This jar file does not seem to fit your system, and no usable SimGrid installation found on disk."); } @@ -68,9 +74,9 @@ public final class NativeLib { if (arch.matches("^i[3-6]86$")) arch = "x86"; - else if (arch.equalsIgnoreCase("x86_64")) + else if ("x86_64".equalsIgnoreCase(arch)) arch = "amd64"; - else if (arch.equalsIgnoreCase("AMD64")) + else if ("AMD64".equalsIgnoreCase(arch)) arch = "amd64"; if (os.toLowerCase().startsWith("win")){ @@ -83,31 +89,31 @@ public final class NativeLib { return prefix + "/" + os + "/" + arch + "/"; } - static Path tempDir = null; + private static void loadLib (String name) throws LinkageException { - String Path = NativeLib.getPath(); + String path = NativeLib.getPath(); String filename=name; - InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename); + InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); if (in == null) { filename = "lib"+name+".so"; - in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename); + in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); } if (in == null) { filename = name+".dll"; - in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename); + in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); } if (in == null) { filename = "lib"+name+".dll"; - in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename); + in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); } if (in == null) { filename = "lib"+name+".dylib"; - in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename); + in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); } if (in == null) { - throw new LinkageException("Cannot find library "+name+" in path "+Path+". Sorry, but this jar does not seem to be usable on your machine."); + throw new LinkageException("Cannot find library "+name+" in path "+path+". Sorry, but this jar does not seem to be usable on your machine."); } try { // We must write the lib onto the disk before loading it -- stupid operating systems @@ -121,9 +127,9 @@ public final class NativeLib { /* copy the library in position */ OutputStream out = new FileOutputStream(fileOut); byte[] buffer = new byte[4096]; - int bytes_read; - while ((bytes_read = in.read(buffer)) != -1) // Read until EOF - out.write(buffer, 0, bytes_read); + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) // Read until EOF + out.write(buffer, 0, bytesRead); /* close all file descriptors, and load that shit */ in.close(); @@ -146,13 +152,13 @@ public final class NativeLib { for (File f : dir.listFiles()) if (! f.delete() ) System.err.println("Unable to clean temporary file "+f.getAbsolutePath()+" during shutdown."); - if (! dir.delete() ) + if (! dir.delete() ) System.err.println("Unable to clean temporary file "+dir.getAbsolutePath()+" during shutdown."); } catch(Exception e) { System.err.println("Unable to clean temporary file "+dir.getAbsolutePath()+" during shutdown: "+e.getCause()); e.printStackTrace(); } - } + } } diff --git a/src/bindings/java/org/simgrid/msg/Msg.java b/src/bindings/java/org/simgrid/msg/Msg.java index f4cb975d8b..bd49fd24b4 100644 --- a/src/bindings/java/org/simgrid/msg/Msg.java +++ b/src/bindings/java/org/simgrid/msg/Msg.java @@ -13,19 +13,23 @@ import org.simgrid.NativeLib; public final class Msg { /** Retrieves the simulation time */ - public final static native double getClock(); + public static final native double getClock(); /** Issue a debug logging message. */ - public final static native void debug(String msg); + public static final native void debug(String msg); /** Issue a verbose logging message. */ - public final static native void verb(String msg); + public static final native void verb(String msg); /** Issue an information logging message */ - public final static native void info(String msg); + public static final native void info(String msg); /** Issue a warning logging message. */ - public final static native void warn(String msg); + public static final native void warn(String msg); /** Issue an error logging message. */ - public final static native void error(String msg); + public static final native void error(String msg); /** Issue a critical logging message. */ - public final static native void critical(String s); + public static final native void critical(String s); + + private Msg() { + throw new IllegalAccessError("Utility class"); + } /********************************************************************************* * Deployment and initialization related functions * @@ -35,10 +39,10 @@ public final class Msg { * * @param args The arguments of the command line of the simulation. */ - public final static native void init(String[]args); + public static final native void init(String[]args); /** Tell the kernel that you want to use the energy plugin */ - public final static native void energyInit(); + public static final native void energyInit(); /** Run the MSG simulation. * @@ -47,19 +51,15 @@ public final class Msg { * retrieve the information that you want from the simulation. In particular, retrieving the status * of a process or the current date is perfectly ok. */ - public final static native void run() ; - - /** This function is useless nowadays, just stop calling it. */ - @Deprecated - public final static void clean(){} + public static final native void run() ; /** Create the simulation environment by parsing a platform file. */ - public final static native void createEnvironment(String platformFile); + public static final native void createEnvironment(String platformFile); - public final static native As environmentGetRoutingRoot(); + public static final native As environmentGetRoutingRoot(); /** Starts your processes by parsing a deployment file. */ - public final static native void deployApplication(String deploymentFile); + public static final native void deployApplication(String deploymentFile); /** Example launcher. You can use it or provide your own launcher, as you wish * @param args diff --git a/src/bindings/java/org/simgrid/msg/Process.java b/src/bindings/java/org/simgrid/msg/Process.java index 291ab60818..d9b3b6e87e 100644 --- a/src/bindings/java/org/simgrid/msg/Process.java +++ b/src/bindings/java/org/simgrid/msg/Process.java @@ -7,7 +7,7 @@ package org.simgrid.msg; import java.util.Arrays; -import java.util.Vector; +import java.util.ArrayList; /** * A process may be defined as a code, with some private data, executing @@ -53,7 +53,7 @@ public abstract class Process implements Runnable { * Even if this attribute is public you must never access to it. * It is used to compute the id of an MSG process. */ - public static long nextProcessId = 0; + private static long nextProcessId = 0; /** * Even if this attribute is public you must never access to it. @@ -77,7 +77,7 @@ public abstract class Process implements Runnable { private Host host = null; /** The arguments of the method function of the process. */ - public Vector args; + public ArrayList args; /** Default constructor */ @@ -85,7 +85,7 @@ public abstract class Process implements Runnable { this.id = nextProcessId++; this.name = null; this.bind = 0; - this.args = new Vector(); + this.args = new ArrayList<>(); } @@ -116,7 +116,7 @@ public abstract class Process implements Runnable { * @throws NativeException * */ - public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException { + public Process(String hostname, String name, String[] args) throws HostNotFoundException, NativeException { this(Host.getByName(hostname), name, args); } /** @@ -142,15 +142,15 @@ public abstract class Process implements Runnable { this(); this.host = host; if (host == null) - throw new NullPointerException("Process name cannot be NULL"); + throw new NullPointerException("Host cannot be NULL"); if (name == null) throw new NullPointerException("Process name cannot be NULL"); this.name = name; - this.args = new Vector(); + this.args = new ArrayList<>(); if (null != args) this.args.addAll(Arrays.asList(args)); - } + } /** * Constructs a new process from a host and his name, the arguments of here method function are * specified by the parameter args. @@ -171,12 +171,12 @@ public abstract class Process implements Runnable { throw new NullPointerException("Process name cannot be NULL"); this.name = name; - this.args = new Vector(); + this.args = new ArrayList<>(); if (null != args) this.args.addAll(Arrays.asList(args)); this.startTime = startTime; - this.killTime = killTime; + this.killTime = killTime; } /** * The natively implemented method to create an MSG process. @@ -305,7 +305,7 @@ public abstract class Process implements Runnable { * @param millis the length of time to sleep in milliseconds. * @param nanos additionnal nanoseconds to sleep. */ - public native static void sleep(long millis, int nanos) throws HostFailureException; + public static native void sleep(long millis, int nanos) throws HostFailureException; /** * Makes the current process sleep until time seconds have elapsed. * @param seconds The time the current process must sleep. @@ -331,7 +331,7 @@ public abstract class Process implements Runnable { try { args = new String[this.args.size()]; - if (this.args.size() > 0) { + if (!this.args.isEmpty()) { this.args.toArray(args); }