Logo AND Algorithmique Numérique Distribuée

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