Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eb61988e924685b54e1908df96f068ccaf867c4c
[simgrid.git] / src / bindings / java / org / simgrid / msg / VM.java
1 /*
2  * JNI interface to virtual machine in Simgrid
3  * 
4  * Copyright 2006-2012 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         /* Constructors / destructors */
25     /**
26          * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
27          */
28         public VM(Host host, String name) {
29                 this(host,name,1,1024*1024*1024, -1, null, -1);
30         }
31
32         /**
33          * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
34          */
35         public VM(Host host, String name, int nCore,  long ramSize, 
36                          long netCap, String diskPath, long diskSize){
37                 super();
38                 super.name = name; 
39                 create(host, name, nCore, ramSize, netCap, diskPath, diskSize);
40         }
41
42         protected void finalize() {
43                 destroy();
44         }
45         
46
47         /* JNI / Native code */
48         /* get/set property methods are inherited from the Host class. */
49         
50         /** Returns whether the given VM is currently suspended
51          */     
52         public native int isCreated();
53         
54         /** Returns whether the given VM is currently running
55          */
56         public native int isRunning();
57
58         /** Returns whether the given VM is currently running
59          */
60         public native int isMigrating();
61         
62         /** Returns whether the given VM is currently suspended
63          */     
64         public native int isSuspended();
65                 
66         /** Returns whether the given VM is currently saving
67          */
68         public native int isSaving();
69         
70         /** Returns whether the given VM is currently saved
71          */
72         public native int isSaved();
73
74         /** Returns whether the given VM is currently restoring its state
75          */
76         public native boolean isRestoring();
77         
78         /**
79          * Natively implemented method create the VM.
80          * @param nCore, number of core
81          * @param ramSize, size of the RAM that should be allocated 
82          * @param netCap (not used for the moment)
83          * @param diskPath (not used for the moment)
84          * @param diskSize (not used for the moment)
85          */
86         private native void create(Host host, String name, int nCore, long ramSize, 
87                          long netCap, String diskPath, long diskSize);
88         
89         /**
90          * start the VM
91          */
92         public native void start();
93
94         
95         /**
96          * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
97          * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
98          */
99         public native void shutdown();
100         
101         
102         /** Immediately change the host on which all processes are running
103          *
104          * No migration cost occurs. If you want to simulate this too, you want to use a
105          * Task.send() before or after, depending on whether you want to do cold or hot
106          * migration.
107          */     
108         public native void migrate(Host destination);
109         
110         /** Immediately suspend the execution of all processes within the given VM
111          *
112          * No suspension cost occurs. If you want to simulate this too, you want to
113          * use a \ref File.write() before or after, depending on the exact semantic
114          * of VM suspend to you.
115          */     
116         public native void suspend();
117         
118         /** Immediately resumes the execution of all processes within the given VM
119          *
120          * No resume cost occurs. If you want to simulate this too, you want to
121          * use a \ref File.read() before or after, depending on the exact semantic
122          * of VM resume to you.
123          */
124         public native void resume();
125         
126         /** Immediately suspend the execution of all processes within the given VM 
127          *  and save its state on the persistent HDD
128          *  Not yet implemented (for the moment it behaves like suspend)
129          *  No suspension cost occurs. If you want to simulate this too, you want to
130          *  use a \ref File.write() before or after, depending on the exact semantic
131          *  of VM suspend to you.
132          */     
133         public native void save();
134         
135         /** Immediately resumes the execution of all processes previously saved 
136          * within the given VM
137          *  Not yet implemented (for the moment it behaves like resume)
138          *
139          * No resume cost occurs. If you want to simulate this too, you want to
140          * use a \ref File.read() before or after, depending on the exact semantic
141          * of VM resume to you.
142          */
143         public native void restore();
144         
145
146         /**
147          * Destroy the VM
148          */
149         protected native void destroy();
150
151         
152
153         /**
154          * Class initializer, to initialize various JNI stuff
155          */
156         public static native void nativeInit();
157         static {
158                 nativeInit();
159         }
160 }