Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[simgrid.git] / src / bindings / java / org / simgrid / msg / VM.java
1 /* JNI interface to virtual machine in Simgrid */
2
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 package org.simgrid.msg;
10
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.Process;
13
14 public class VM extends Host{
15         // Please note that we are not declaring a new bind variable 
16         //(the bind variable has been inherited from the super class Host)
17         
18         /* Static functions */ 
19         // GetByName is inherited from the super class Host
20         
21
22          private static VM[] vms=null;    
23     private Host currentHost; 
24
25         /* Constructors / destructors */
26     /**
27          * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
28          */
29         public VM(Host host, String name) {
30                 this(host,name,1,1024, -1, null, -1,0 , 0);
31         }
32
33         /**
34          * Create a  VM
35          * @param host  Host node
36          * @param name name of the machine
37          * @param nCore number of core
38          * @param ramSize size of the RAM that should be allocated (in MBytes)
39          * @param netCap (not used for the moment)
40          * @param diskPath (not used for the moment)
41          * @param diskSize (not used for the moment)
42          * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
43          * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
44          */
45         public VM(Host host, String name, int nCore,  int ramSize, 
46                         int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity){
47                 super();
48                 super.name = name; 
49                 this.currentHost = host; 
50                 create(host, name, nCore, ramSize, netCap, diskPath, diskSize, migNetSpeed, dpIntensity);
51                 VM.addVM(this);
52         }
53
54         private static void addVM(VM vm){
55                 VM[] vmsN=null; 
56                 int i=0;
57                 if(VM.vms == null)
58                         vmsN = new VM[1]; 
59                 else
60                         vmsN = new VM[vms.length+1]; 
61                 
62                 for (i=0; i<vmsN.length-1 ; i ++){
63                         vmsN[i]=vms[i]; 
64                 } 
65                 vmsN[i]=vm;
66                 vms=vmsN;
67         }
68    public static VM[] all(){
69                 return vms;
70         }
71         public static VM getVMByName(String name){
72                 for (int i=0 ; i < vms.length ; i++){
73                           if (vms[i].getName().equals(name))
74                                         return vms[i];          
75                 }
76                 return null; 
77         }
78         protected void finalize() {
79                 destroy();
80         }
81         
82
83         /* JNI / Native code */
84
85         /* get/set property methods are inherited from the Host class. */
86         
87         /** Returns whether the given VM is currently suspended
88          */     
89         public native int isCreated();
90         
91         /** Returns whether the given VM is currently running
92          */
93         public native int isRunning();
94
95         /** Returns whether the given VM is currently running
96          */
97         public native int isMigrating();
98         
99         /** Returns whether the given VM is currently suspended
100          */     
101         public native int isSuspended();
102                 
103         /** Returns whether the given VM is currently saving
104          */
105         public native int isSaving();
106         
107         /** Returns whether the given VM is currently saved
108          */
109         public native int isSaved();
110
111         /** Returns whether the given VM is currently restoring its state
112          */
113         public native boolean isRestoring();
114         
115         /**
116          * Natively implemented method create the VM.
117          * @param nCore number of core
118          * @param ramSize size of the RAM that should be allocated (in MB)
119          * @param netCap (not used for the moment)
120          * @param diskPath (not used for the moment)
121          * @param diskSize (not used for the moment)
122          * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
123          * @param dpIntensity (dirty page intensity, a percentage of migNetSpeed [0-100],  if you don't know put zero ;))
124          */
125         private native void create(Host host, String name, int nCore, int ramSize, 
126                          int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity);
127
128
129         /**
130          * Bound the VM to a certain % of its vcpu capability (e.g. 75% of vm.getSpeed())
131          * @param load percentage (between [0,100]
132          */
133         public native void setBound(int load);
134
135         /**
136          * start the VM
137          */
138         public native void start();
139
140         
141         /**
142          * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
143          * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
144          */
145         public native void shutdown();
146         
147         /**  
148          * Invoke native migration routine
149         */
150         public native void internalmig(Host destination);
151
152         
153         /** Change the host on which all processes are running
154          * (pre-copy is implemented)
155          */     
156         public void migrate(Host destination){
157                 this.internalmig(destination);
158                 this.currentHost = destination; 
159         }
160         
161         /** Immediately suspend the execution of all processes within the given VM
162          *
163          * No suspension cost occurs. If you want to simulate this too, you want to
164          * use a \ref File.write() before or after, depending on the exact semantic
165          * of VM suspend to you.
166          */     
167         public native void suspend();
168         
169         /** Immediately resumes the execution of all processes within the given VM
170          *
171          * No resume cost occurs. If you want to simulate this too, you want to
172          * use a \ref File.read() before or after, depending on the exact semantic
173          * of VM resume to you.
174          */
175         public native void resume();
176         
177         /** Immediately suspend the execution of all processes within the given VM 
178          *  and save its state on the persistent HDD
179          *  Not yet implemented (for the moment it behaves like suspend)
180          *  No suspension cost occurs. If you want to simulate this too, you want to
181          *  use a \ref File.write() before or after, depending on the exact semantic
182          *  of VM suspend to you.
183          */     
184         public native void save();
185         
186         /** Immediately resumes the execution of all processes previously saved 
187          * within the given VM
188          *  Not yet implemented (for the moment it behaves like resume)
189          *
190          * No resume cost occurs. If you want to simulate this too, you want to
191          * use a \ref File.read() before or after, depending on the exact semantic
192          * of VM resume to you.
193          */
194         public native void restore();
195         
196
197         /**
198          * Destroy the VM
199          */
200         public native void destroy();
201
202         
203
204         /**
205          * Class initializer, to initialize various JNI stuff
206          */
207         public static native void nativeInit();
208         static {
209                 nativeInit();
210         }
211 }