Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
VM: don't take ignored parameter that may fool the users
[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 import java.util.ArrayList;
11
12 public class VM extends Host{
13         // Please note that we are not declaring a new bind variable 
14         //(the bind variable has been inherited from the super class Host)
15
16         /* Static functions */ 
17         // GetByName is inherited from the super class Host
18
19
20         private static ArrayList<VM> vms= new ArrayList<>();
21         private Host currentHost; 
22
23         /* Constructors / destructors */
24         /**
25          * Create a `basic' VM (i.e. 1GB of RAM, other values are not taken into account).
26          */
27         public VM(Host host, String name) {
28                 this(host,name,1024, 0, 0);
29         }
30
31         /**
32          * Create a  VM
33          * @param host  Host node
34          * @param name name of the machine
35          * @param ramSize size of the RAM that should be allocated (in MBytes)
36          * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
37          * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
38          */
39         public VM(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity){
40                 super();
41                 super.name = name; 
42                 this.currentHost = host; 
43                 create(host, name, ramSize, migNetSpeed, dpIntensity);
44                 vms.add(this);
45         }
46
47         public static VM[] all(){
48                 VM[] allvms = new VM[vms.size()];
49                 vms.toArray(allvms);
50                 return allvms;
51         }
52
53         public static VM getVMByName(String name){
54                 for (VM vm : vms){
55                         if (vm.getName().equals(name))
56                                 return vm;
57                 }
58                 return null; 
59         }
60         
61         public void destroy() {
62                 nativeFinalize();
63         }
64         private native void nativeFinalize();
65
66
67         /* JNI / Native code */
68
69         /* get/set property methods are inherited from the Host class. */
70
71         /** Returns whether the given VM is currently suspended
72          */     
73         public native int isCreated();
74
75         /** Returns whether the given VM is currently running
76          */
77         public native int isRunning();
78
79         /** Returns whether the given VM is currently running
80          */
81         public native int isMigrating();
82
83         /** Returns whether the given VM is currently suspended
84          */     
85         public native int isSuspended();
86
87         /** Returns whether the given VM is currently saving
88          */
89         public native int isSaving();
90
91         /** Returns whether the given VM is currently saved
92          */
93         public native int isSaved();
94
95         /** Returns whether the given VM is currently restoring its state
96          */
97         public native boolean isRestoring();
98
99         /**
100          * Natively implemented method create the VM.
101          * @param ramSize size of the RAM that should be allocated (in MB)
102          * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
103          * @param dpIntensity (dirty page intensity, a percentage of migNetSpeed [0-100],  if you don't know put zero ;))
104          */
105         private native void create(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity);
106
107
108         /**
109          * Set a CPU bound for a given VM.
110          * @param bound in flops/s
111          */
112         public native void setBound(double bound);
113
114         /**
115          * start the VM
116          */
117         public native void start();
118
119
120         /**
121          * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
122          * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
123          */
124         public native void shutdown();
125
126         /**  
127          * Invoke native migration routine
128          */
129         public native void internalmig(Host destination) throws Exception; // TODO add throws DoubleMigrationException (i.e. when you call migrate on a VM that is already migrating);
130
131
132
133         /** Change the host on which all processes are running
134          * (pre-copy is implemented)
135          */     
136         public void migrate(Host destination) throws HostFailureException{
137                 try {
138                         this.internalmig(destination);
139                 } catch (Exception e){
140                   Msg.info("Migration of VM "+this.getName()+" to "+destination.getName()+" is impossible ("+e.getMessage()+")");
141                   throw new HostFailureException();
142                 }
143                 // If the migration correcly returned, then we should change the currentHost value. 
144                 this.currentHost = destination; 
145         }
146
147         /** Immediately suspend the execution of all processes within the given VM
148          *
149          * No suspension cost occurs. If you want to simulate this too, you want to
150          * use a \ref File.write() before or after, depending on the exact semantic
151          * of VM suspend to you.
152          */     
153         public native void suspend();
154
155         /** Immediately resumes the execution of all processes within the given VM
156          *
157          * No resume cost occurs. If you want to simulate this too, you want to
158          * use a \ref File.read() before or after, depending on the exact semantic
159          * of VM resume to you.
160          */
161         public native void resume();
162
163         /** Immediately suspend the execution of all processes within the given VM 
164          *  and save its state on the persistent HDD
165          *  Not yet implemented (for the moment it behaves like suspend)
166          *  No suspension cost occurs. If you want to simulate this too, you want to
167          *  use a \ref File.write() before or after, depending on the exact semantic
168          *  of VM suspend to you.
169          */     
170         public native void save();
171
172         /** Immediately resumes the execution of all processes previously saved 
173          * within the given VM
174          *  Not yet implemented (for the moment it behaves like resume)
175          *
176          * No resume cost occurs. If you want to simulate this too, you want to
177          * use a \ref File.read() before or after, depending on the exact semantic
178          * of VM resume to you.
179          */
180         public native void restore();
181
182
183         /**
184          * Class initializer, to initialize various JNI stuff
185          */
186         public static native void nativeInit();
187         static {
188                 nativeInit();
189         }
190 }