Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
complete reorganisation of examples/smpi/NAS
[simgrid.git] / src / bindings / java / org / simgrid / msg / Host.java
1 /* Bindings to the MSG hosts */
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.Storage;
12
13 /**
14  * A host object represents a location (any possible place) where a process may run. 
15  * Thus it is represented as a physical resource with computing capabilities, some 
16  * mailboxes to enable running process to communicate with remote ones, and some private 
17  * data that can be only accessed by local process. An instance of this class is always 
18  * bound with the corresponding native host. All the native hosts are automatically created
19  * during the call of the method Msg.createEnvironment(). This method take as parameter a
20  * platform file which describes all elements of the platform (host, link, root..).
21  * You cannot create a host yourself.
22  *
23  * The best way to get an host instance is to call the static method 
24  * Host.getByName().
25  *
26  * For example to get the instance of the host. If your platform
27  * file description contains an host named "Jacquelin" :
28  *
29  * \verbatim
30 Host jacquelin;
31
32 try { 
33         jacquelin = Host.getByName("Jacquelin");
34 } catch(HostNotFoundException e) {
35         System.err.println(e.toString());
36 }
37 ...
38 \endverbatim
39  *
40  */ 
41 public class Host {
42
43         /**
44          * This attribute represents a bind between a java host object and
45          * a native host. Even if this attribute is public you must never
46          * access to it. It is set automatically during the call of the 
47          * static method Host.getByName().
48          *
49          * @see                         Host.getByName().
50          */ 
51         private long bind;
52         /**
53          * Host name
54          */
55         protected String name;
56
57         /**
58          * User data.
59          */ 
60         private Object data;
61         /**
62          *
63          */
64         protected Host() {
65                 this.bind = 0;
66                 this.data = null;
67         };
68
69         @Override
70         public String toString (){
71                 return this.name; 
72
73         }
74
75         /**
76          * This static method gets an host instance associated with a native
77          * host of your platform. This is the best way to get a java host object.
78          *
79          * @param name          The name of the host to get.
80          *
81          * @return              The host object with the given name.
82          * @exception           HostNotFoundException if the name of the host is not valid.
83          *                                      NativeException if the native version of this method failed.
84          */ 
85         public native static Host getByName(String name) 
86                         throws HostNotFoundException, NullPointerException;
87         /**
88          * This static method returns the count of the installed hosts.
89          *
90          * @return                      The count of the installed hosts.
91          */ 
92         public native static int getCount();
93
94         /**
95          * This static method return an instance to the host of the current process.
96          *
97          * @return                      The host on which the current process is executed.
98          */ 
99         public native static Host currentHost();
100
101         /**
102          * This static method returns all of the hosts of the installed platform.
103          *
104          * @return                      An array containing all the hosts installed.
105          *
106          */ 
107         public native static Host[] all();
108
109         /** 
110          * This static method sets a mailbox to receive in asynchronous mode.
111          * 
112          * All messages sent to this mailbox will be transferred to 
113          * the receiver without waiting for the receive call. 
114          * The receive call will still be necessary to use the received data.
115          * If there is a need to receive some messages asynchronously, and some not, 
116          * two different mailboxes should be used.
117          *
118          * @param mailboxName The name of the mailbox
119          */
120         public static native void setAsyncMailbox(String mailboxName);
121
122
123         /**
124          * This method returns the name of a host.
125          * @return                      The name of the host.
126          *
127          */ 
128         public String getName() {
129                 return name;
130         }
131
132         /**
133          * Sets the data of the host.
134          * @param data
135          */
136         public void setData(Object data) {
137                 this.data = data;
138         } 
139         /**
140          * Gets the data of the host.
141          *
142          * @return The data object associated with the host.
143          */
144         public Object getData() {
145                 return this.data;
146         }
147
148         /**
149          * Checks whether a host has data.
150          *
151          * @return True if the host has an associated data object.
152          */
153         public boolean hasData() {
154                 return null != this.data;
155         }
156
157         /**
158          * This method start the host if it is off
159          */ 
160         public native void on();
161
162         /**
163          * This method stop the host if it is on
164          */ 
165         public native void off();
166
167
168         /**
169          * This method returns the speed of the processor of a host,
170          * regardless of the current load of the machine.
171          *
172          * @return                      The speed of the processor of the host in flops.
173          *
174          */ 
175         public native double getSpeed();
176
177         /**
178          * This method returns the number of core of a host.
179          *
180          * @return                      The speed of the processor of the host in flops.
181          *
182          */ 
183         public native double getCoreNumber();
184
185         /**
186          * Returns the value of a given host property. 
187          */
188         public native String getProperty(String name);
189
190         /**
191          * Change the value of a given host property. 
192          */
193         public native void setProperty(String name, String value);
194
195         /** This method tests if a host is up and running.
196          * @return True if the host is available.
197          */
198         public native boolean isOn();
199
200         /** This methods returns the list of mount point names on an host
201          * @return An array containing all mounted storages on the host
202          */
203         public native Storage[] getMountedStorage();
204
205         /** This methods returns the list of storages attached to an host
206          * @return An array containing all storages (name) attached to the host
207          */
208         public native String[] getAttachedStorage();
209
210         /** Returns the amount of Joules consumed by that host so far */
211         public native double getConsumedEnergy();
212
213         /**
214          * Class initializer, to initialize various JNI stuff
215          */
216         public static native void nativeInit();
217         static {
218                 nativeInit();
219         }       
220