Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9165a103165af06a34911df4a2e0f057e9a65b4d
[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         protected String name;
53
54         /** User data. */ 
55         private Object data;
56         protected Host() {
57                 this.bind = 0;
58                 this.data = null;
59         }
60
61         @Override
62         public String toString (){
63                 return this.name; 
64         }
65
66         /**
67          * This static method gets an host instance associated with a native
68          * host of your platform. This is the best way to get a java host object.
69          *
70          * @param name          The name of the host to get.
71          *
72          * @return              The host object with the given name.
73          * @exception           HostNotFoundException if the name of the host is not valid.
74          */ 
75         public static native Host getByName(String name) throws HostNotFoundException;
76         /** Counts the installed hosts. */ 
77         public static native int getCount();
78
79         /** Returns the host of the current process. */ 
80         public static native Host currentHost();
81
82         /** Returns all hosts of the installed platform. */ 
83         public static native Host[] all();
84
85         /** 
86          * This static method sets a mailbox to receive in asynchronous mode.
87          * 
88          * All messages sent to this mailbox will be transferred to 
89          * the receiver without waiting for the receive call. 
90          * The receive call will still be necessary to use the received data.
91          * If there is a need to receive some messages asynchronously, and some not, 
92          * two different mailboxes should be used.
93          *
94          * @param mailboxName The name of the mailbox
95          */
96         public static native void setAsyncMailbox(String mailboxName);
97
98         public String getName() {
99                 return name;
100         }
101
102         public void setData(Object data) {
103                 this.data = data;
104         } 
105
106         public Object getData() {
107                 return this.data;
108         }
109         /** Returns true if the host has an associated data object. */
110         public boolean hasData() {
111                 return null != this.data;
112         }
113
114         /** Starts the host if it is off */ 
115         public native void on();
116         /** Stops the host if it is on */ 
117         public native void off();
118
119         /**
120          * This method returns the speed of the processor of a host (in flops),
121          * regardless of the current load of the machine.
122          */ 
123         public native double getSpeed();
124         public native double getCoreNumber();
125
126         public native String getProperty(String name);
127         public native void setProperty(String name, String value);
128         /** Tests if an host is up and running. */
129         public native boolean isOn();
130
131         /** Returns the list of mount point names on an host */
132         public native Storage[] getMountedStorage();
133         /** This methods returns the list of storages (names) attached to an host */
134         public native String[] getAttachedStorage();
135
136         /** Returns the amount of Joules consumed by that host so far */
137         public native double getConsumedEnergy();
138         
139         /** Returns the current pstate */
140         public native int getPstate();
141         /** Changes the current pstate */
142         public native void setPstate(int pstate);
143         public native int getPstatesCount();
144         /** Returns the speed of the processor (in flop/s) at the current pstate. See also @ref SURF_plugin_energy. */
145         public native double getCurrentPowerPeak();
146         /** Returns the speed of the processor (in flop/s) at a given pstate. See also @ref SURF_plugin_energy. */
147         public native double getPowerPeakAt(int pstate);
148         
149
150         /** Class initializer, to initialize various JNI stuff */
151         private static native void nativeInit();
152         static {
153                 nativeInit();
154         }       
155