Logo AND Algorithmique Numérique Distribuée

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