Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
VM: don't take ignored parameter that may fool the users
[simgrid.git] / examples / java / energy / vm / EnergyVMRunner.java
index 32ac1fb..0e636f6 100644 (file)
@@ -5,8 +5,15 @@
 
 package energy.vm;
 
-import org.simgrid.msg.*;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.VM;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.TaskCancelledException;
+import org.simgrid.msg.NativeException;
 
 /* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
 public class EnergyVMRunner extends Process {
@@ -16,11 +23,13 @@ public class EnergyVMRunner extends Process {
       super(host, name); 
     }
 
-    public void main(String[] args) {    
+    @Override
+    public void main(String[] strings) {
       Task  task = new Task(this.getHost().getName()+"-task", 300E6 , 0);
       try {
-        task.execute();   
-      } catch (Exception e) {
+        task.execute();
+      } catch (HostFailureException | TaskCancelledException e) {
+        Msg.error(e.getMessage());
         e.printStackTrace();
       } 
       Msg.info("This worker is done."); 
@@ -31,20 +40,18 @@ public class EnergyVMRunner extends Process {
     super(host, name, args);
   }
 
-  public void main(String[] strings) throws MsgException, HostNotFoundException {
-    double startTime = 0;
-    double endTime = 0;
-
+  @Override
+  public void main(String[] strings) throws HostNotFoundException, HostFailureException {
     /* get hosts */
     Host host1 = Host.getByName("MyHost1");
     Host host2 = Host.getByName("MyHost2");
     Host host3 = Host.getByName("MyHost3");
 
     Msg.info("Creating and starting two VMs");
-    VM vmHost1 = new VM(host1, "vmHost1", 4, 2048, 100, null, 1024 * 20, 10,50);
+    VM vmHost1 = new VM(host1, "vmHost1", 2048, 10, 50);
     vmHost1.start();
 
-    VM vmHost3 = new VM(host3, "vmHost3", 4, 2048, 100, null, 1024 * 20, 10,50);
+    VM vmHost3 = new VM(host3, "vmHost3", 2048, 10, 50);
     vmHost3.start();
 
     Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host");
@@ -65,9 +72,7 @@ public class EnergyVMRunner extends Process {
     Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); 
     waitFor(5); 
 
-    vmHost1.shutdown(); 
-    vmHost3.shutdown(); 
-    vmHost1.finalize(); 
-    vmHost3.finalize(); 
+    vmHost1.destroy(); 
+    vmHost3.destroy(); 
   }
 }