Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
replace Vector by ArrayList
[simgrid.git] / src / bindings / java / org / simgrid / msg / VM.java
index 77cdaee..f025de2 100644 (file)
@@ -7,7 +7,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 package org.simgrid.msg;
-
+import java.util.ArrayList;
 
 public class VM extends Host{
        // Please note that we are not declaring a new bind variable 
@@ -17,7 +17,7 @@ public class VM extends Host{
        // GetByName is inherited from the super class Host
 
 
-       private static VM[] vms=null;     
+       private static ArrayList<VM> vms= new ArrayList<>();
        private Host currentHost; 
 
        /* Constructors / destructors */
@@ -46,38 +46,27 @@ public class VM extends Host{
                super.name = name; 
                this.currentHost = host; 
                create(host, name, nCore, ramSize, netCap, diskPath, diskSize, migNetSpeed, dpIntensity);
-               VM.addVM(this);
+               vms.add(this);
        }
 
-       private static void addVM(VM vm){
-               VM[] vmsN=null; 
-               int i=0;
-               if(VM.vms == null)
-                       vmsN = new VM[1]; 
-               else
-                       vmsN = new VM[vms.length+1]; 
-
-               for (i=0; i<vmsN.length-1 ; i ++){
-                       vmsN[i]=vms[i]; 
-               } 
-               vmsN[i]=vm;
-               vms=vmsN;
-       }
        public static VM[] all(){
-               return vms;
+               VM[] allvms = new VM[vms.size()];
+               vms.toArray(allvms);
+               return allvms;
        }
+
        public static VM getVMByName(String name){
-               for (int i=0 ; i < vms.length ; i++){
-                       if (vms[i].getName().equals(name))
-                               return vms[i];          
+               for (VM vm : vms){
+                       if (vm.getName().equals(name))
+                               return vm;
                }
                return null; 
        }
-       @Override
-       public void finalize() {
+       
+       public void destroy() {
                try {
                        nativeFinalize();
-               } catch (Throwable e) {
+               } catch (Exception e) {
                        e.printStackTrace();
                }
        }
@@ -131,10 +120,10 @@ public class VM extends Host{
 
 
        /**
-        * Bound the VM to a certain % of its vcpu capability (e.g. 75% of vm.getSpeed())
-        * @param load percentage (between [0,100]
+        * Set a CPU bound for a given VM.
+        * @param bound in flops/s
         */
-       public native void setBound(int load);
+       public native void setBound(double bound);
 
        /**
         * start the VM