Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / bindings / java / org / simgrid / msg / VM.java
1 /*
2  * JNI interface to Cloud interface 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 {
17         /**
18          * This attribute represents a bind between a java task object and
19          * a native task. Even if this attribute is public you must never
20          * access to it. It is set automatically during the build of the object.
21          */
22         private long bind = 0;
23         
24         private int coreAmount;
25
26         private String name;
27         /**
28          * Create a new empty VM.
29          * NOTE: it is expected that in the future, the coreAmount parameter will be used
30          * to add extra constraints on the execution, but the argument is ignored for now.
31          */
32         public VM(Host host, String name, int coreAmount) {
33                 this.coreAmount = coreAmount;
34                 this.name = name;
35                 start(host,name,coreAmount);
36         }
37         protected void finalize() {
38                 destroy();
39         }
40         /**
41          * Destroy the VM
42          */
43         protected native void destroy();
44         /**
45          * Natively implemented method starting the VM.
46          * @param coreAmount
47          */
48         private native void start(Host host, String name, int coreAmount);
49                 
50         /** Returns whether the given VM is currently suspended
51          */     
52         public native boolean isSuspended();
53         /** Returns whether the given VM is currently running
54          */
55         public native boolean isRunning();
56         /** Add the given process into the VM.
57          * Afterward, when the VM is migrated or suspended or whatever, the process will have the corresponding handling, too.
58          */     
59         public native void bind(Process process);
60         /** Removes the given process from the given VM, and kill it
61          *  Will raise a ProcessNotFound exception if the process were not bound to that VM
62          */     
63         public native void unbind(Process process);
64         /** Immediately change the host on which all processes are running
65          *
66          * No migration cost occurs. If you want to simulate this too, you want to use a
67          * Task.send() before or after, depending on whether you want to do cold or hot
68          * migration.
69          */     
70         public native void migrate(Host destination);
71         /** Immediately suspend the execution of all processes within the given VM
72          *
73          * No suspension cost occurs. If you want to simulate this too, you want to
74          * use a \ref File.write() before or after, depending on the exact semantic
75          * of VM suspend to you.
76          */     
77         public native void suspend();
78         /** Immediately resumes the execution of all processes within the given VM
79          *
80          * No resume cost occurs. If you want to simulate this too, you want to
81          * use a \ref File.read() before or after, depending on the exact semantic
82          * of VM resume to you.
83          */
84         public native void resume();
85         /**
86          * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
87          * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
88          */
89         public native void shutdown();
90         /**
91          * Reboot the VM, restarting all the processes in it.
92          */
93         public native void reboot();
94
95         public String getName() {
96                 return name;
97         }               
98
99         /**
100          * Class initializer, to initialize various JNI stuff
101          */
102         public static native void nativeInit();
103         static {
104                 nativeInit();
105         }
106 }