Logo AND Algorithmique Numérique Distribuée

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