Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This commit concerned the reimplementation of the xbt context switch mechanism.
[simgrid.git] / src / java / simgrid / msg / Host.java
1 /*
2  * simgrid.msg.Host.java        1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
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 simgrid.msg;
13
14 import java.lang.String;
15
16 /**
17  * A host object represents a location (any possible place) where a process may run. 
18  * Thus it is represented as a physical resource with computing capabilities, some 
19  * mailboxes to enable running process to communicate with remote ones, and some private 
20  * data that can be only accessed by local process. An instance of this class is always 
21  * binded with the corresponding native host. All the native hosts are automaticaly created 
22  * during the call of the method Msg.createEnvironment(). This method take as parameter a
23  * platform file which describes all elements of the platform (host, link, root..).
24  * You never need to create an host your self.
25  *
26  * The best way to get an host instance is to call the static method 
27  * Host.getByName().
28  *
29  * For example to get the instance of the host. If your platform
30  * file description contains an host named "Jacquelin" :
31  *
32  *      Host jacquelin;
33  *
34  *      try { 
35  *              jacquelin = Host.getByName("Jacquelin");
36  *      } catch(HostNotFoundException e) {
37  *              System.err.println(e.toString());
38  *      }
39  *      ...
40  *
41  * @author  Abdelmalek Cherier
42  * @author  Martin Quinson
43  * @version 1.00, 07/05/01
44  * @see Grid
45  * @see Simulation
46  * @see Process
47  * @since SimGrid 3.3
48  * @since JDK1.5011
49  */
50 public class Host {
51         /**
52          * This attribute represents a bind between a java host object and
53          * a native host. Even if this attribute is public you must never
54          * access to it. It is set automaticatly during the call of the 
55          * static method Host.getByName().
56          *
57          * @see                         Host.getByName().
58          */
59         public long bind;
60         
61         /**
62          * User data.
63          */
64         private Object data;
65         
66         protected Host() {
67                 this.bind = 0;
68                 this.data = null;
69         };
70         
71         /**
72          * This static method gets an host instance associated with a native
73          * host of your platform. This is the best way to get a java host object.
74          *
75          * @param name          The name of the host to get.
76          *
77          * @exception           HostNotFoundException if the name of the host is not valid.
78          *                                      MsgException if the native version of this method failed.
79          */                     
80         public static Host getByName(String name)
81             throws HostNotFoundException, NativeException, JniException {
82
83             return Msg.hostGetByName(name);
84         }
85         
86         /**
87          * This static method returns the number of the installed hosts.
88          *
89          * @return                      The number of the installed hosts.
90          *
91          */
92         public static int getNumber()  throws NativeException, JniException {
93                 return Msg.hostGetNumber();
94         }
95         
96         /**
97          * This static method return an instance to the host of the current process.
98          *
99          * @return                      The host on which the current process is executed.
100          *
101          * @exception           MsgException if the native version of this method failed.
102          */
103         public static Host currentHost()   throws JniException{
104                 return Msg.hostSelf();
105         }
106         
107         /**
108          * This static method returns all of the hosts of the installed platform.
109          *
110          * @return                      An array containing all the hosts installed.
111          *
112          * @exception           MsgException if the native version of this method failed.
113          */
114         public static Host[] all()  throws JniException, NativeException{
115                 return Msg.allHosts();
116         }
117         
118         /**
119          * This method returns the name of a host.
120          *
121          * @return                      The name of the host.
122          *
123          * @exception           InvalidHostException if the host is not valid.
124          */
125         public String getName()  throws NativeException, JniException{
126                 return Msg.hostGetName(this);
127         }
128         
129         /**
130          * This method sets the data of the host.
131          *
132          */
133          public void setData(Object data) {
134                 this.data = data;
135         }
136         
137         /**
138          * This method gets the data of the host.
139          */
140         public Object getData() {
141                 return this.data;
142         }
143         
144         /**
145          * This function tests if a host has data.
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          * @exception           InvalidHostException if the host is invalid.
158          *
159          */
160         public int getLoad() throws JniException{
161                 return Msg.hostGetLoad(this);
162         }
163         
164         /**
165          * This method returns the speed of the processor of a host,
166          * regardless of the current load of the machine.
167          *
168          * @return                      The speed of the processor of the host in flops.
169          *
170          * @exception           InvalidHostException if the host is not valid.
171          *
172          */
173
174         public double getSpeed() throws JniException {
175                 return Msg.hostGetSpeed(this);
176         }
177         
178         /**
179          * This method tests if a host is avail.
180          * 
181          * @return                      If the host is avail the method returns true.
182          *                                      Otherwise the method returns false.
183          *
184          * @exception           JniException if the host is not valid.
185          *
186          *
187          */                      
188         public boolean isAvail()throws JniException {
189                 return Msg.hostIsAvail(this);
190         }
191         
192 }