Logo AND Algorithmique Numérique Distribuée

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