Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve the doc of the host plugin API
[simgrid.git] / src / bindings / java / org / simgrid / msg / Host.java
1 /* Bindings to the MSG hosts */
2
3 /* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 package org.simgrid.msg;
9
10 import org.simgrid.msg.Storage;
11
12 /**
13  * A host object represents a location (any possible place) where a process may run.
14  * Thus it is represented as a physical resource with computing capabilities, some
15  * mailboxes to enable running process to communicate with remote ones, and some private
16  * data that can be only accessed by local process. An instance of this class is always
17  * bound with the corresponding native host. All the native hosts are automatically created
18  * during the call of the method Msg.createEnvironment(). This method take as parameter a
19  * platform file which describes all elements of the platform (host, link, root..).
20  * You cannot create a host yourself.
21  *
22  * The best way to get an host instance is to call the static method
23  * Host.getByName().
24  *
25  * For example to get the instance of the host. If your platform
26  * file description contains an host named "Jacquelin" :
27  *
28  * \verbatim
29 Host jacquelin;
30
31 try {
32         jacquelin = Host.getByName("Jacquelin");
33 } catch(HostNotFoundException e) {
34         System.err.println(e.toString());
35 }
36 ...
37 \endverbatim
38  *
39  */
40 public class Host {
41
42         /**
43          * This attribute represents a bind between a java host object and
44          * a native host. Even if this attribute is public you must never
45          * access to it. It is set automatically during the call of the
46          * static method Host.getByName().
47          *
48          * @see                         Host.getByName().
49          */
50         private long bind;
51         protected String name;
52
53         /** User data. */
54         private Object data;
55         protected Host() {
56                 this.bind = 0;
57                 this.data = null;
58         }
59
60         @Override
61         public String toString (){
62                 return this.name;
63         }
64
65         /**
66          * This static method gets an host instance associated with a native
67          * host of your platform. This is the best way to get a java host object.
68          *
69          * @param name          The name of the host to get.
70          *
71          * @return              The host object with the given name.
72          * @exception           HostNotFoundException if the name of the host is not valid.
73          */
74         public static native Host getByName(String name) throws HostNotFoundException;
75         /** Counts the installed hosts. */
76         public static native int getCount();
77
78         /** Returns the host of the current process. */
79         public static native Host currentHost();
80
81         /** Returns all hosts of the installed platform. */
82         public static native Host[] all();
83
84         /**
85          * This static method sets a mailbox to receive in asynchronous mode.
86          *
87          * All messages sent to this mailbox will be transferred to
88          * the receiver without waiting for the receive call.
89          * The receive call will still be necessary to use the received data.
90          * If there is a need to receive some messages asynchronously, and some not,
91          * two different mailboxes should be used.
92          *
93          * @param mailboxName The name of the mailbox
94          */
95         public static native void setAsyncMailbox(String mailboxName);
96
97         public String getName() {
98                 return name;
99         }
100
101         public void setData(Object data) {
102                 this.data = data;
103         }
104
105         public Object getData() {
106                 return this.data;
107         }
108         /** Returns true if the host has an associated data object. */
109         public boolean hasData() {
110                 return null != this.data;
111         }
112
113         /** Starts the host if it is off */
114         public native void on();
115         /** Stops the host if it is on */
116         public native void off();
117
118         /**
119          * This method returns the speed of the processor of a host (in flops),
120          * regardless of the current load of the machine.
121          */
122         public native double getSpeed();
123         public native double getCoreNumber();
124
125         public native String getProperty(String name);
126         public native void setProperty(String name, String value);
127         /** Tests if an host is up and running. */
128         public native boolean isOn();
129
130         /** Returns the list of mount point names on an host */
131         public native Storage[] getMountedStorage();
132         /** This methods returns the list of storages (names) attached to an host */
133         public native String[] getAttachedStorage();
134
135         /** After this call, sg_host_get_consumed_energy() will not interrupt your process
136          * (until after the next clock update).
137          */
138         public static native void updateAllEnergyConsumptions();
139         /** Returns the amount of Joules consumed by that host so far
140          *
141          * Please note that since the consumption is lazily updated, it may require a simcall to update it.
142          * The result is that the actor requesting this value will be interrupted,
143          * the value will be updated in kernel mode before returning the control to the requesting actor.
144          */
145         public native double getConsumedEnergy();
146
147         /** Returns the current load of the host, as a ratio = achieved_flops / (core_current_speed * core_amount)
148          *      
149          * See simgrid::plugin::HostLoad::get_current_load() for the full documentation.
150          */
151         public native double getCurrentLoad();
152         /** Returns the number of flops computed of the host since the beginning of the simulation */
153         public native double getComputedFlops();
154         /** Returns the average load of the host as a ratio since the beginning of the simulation*/
155         public native double getAvgLoad();
156    
157         /** Returns the current pstate */
158         public native int getPstate();
159         /** Changes the current pstate */
160         public native void setPstate(int pstate);
161         public native int getPstatesCount();
162         /** Returns the speed of the processor (in flop/s) at the current pstate. See also @ref plugin_energy. */
163         public native double getCurrentPowerPeak();
164         /** Returns the speed of the processor (in flop/s) at a given pstate. See also @ref plugin_energy. */
165         public native double getPowerPeakAt(int pstate);
166
167         /** Returns the current computation load (in flops per second) */
168         public native double getLoad();
169
170         /** Class initializer, to initialize various JNI stuff */
171         private static native void nativeInit();
172         static {
173                 nativeInit();
174         }       
175 }