Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Process kills now seems to work. May need some additional checking ...
[simgrid.git] / org / simgrid / msg / Host.java
1 /*
2  * Bindings to the MSG hosts
3  *
4  * Copyright 2006,2007,2010 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  * binded 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         public long bind;
53
54
55         /**
56          * User data.
57          */ 
58         private Object data;
59     /**
60      *
61      */
62     protected Host() {
63                 this.bind = 0;
64                 this.data = null;
65         };
66
67         /**
68          * This static method gets an host instance associated with a native
69          * host of your platform. This is the best way to get a java host object.
70          *
71          * @param name          The name of the host to get.
72          *
73      * @return
74      * @exception               HostNotFoundException if the name of the host is not valid.
75          *                                      NativeException if the native version of this method failed.
76          */ 
77         public static Host getByName(String name) 
78         throws HostNotFoundException {
79         Process.ifInterruptedStop();
80                 if (name==null)
81                         throw new NullPointerException("No host can have a null name");
82                 return MsgNative.hostGetByName(name);
83         }
84
85         /**
86          * This static method returns the count of the installed hosts.
87          *
88          * @return                      The count of the installed hosts.
89          *
90          */ 
91         public static int getCount() {
92         Process.ifInterruptedStop();
93                 return MsgNative.hostGetCount();
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         public static Host currentHost() {
102         Process.ifInterruptedStop();
103                 return MsgNative.hostSelf();
104         }
105
106         /**
107          * This static method returns all of the hosts of the installed platform.
108          *
109          * @return                      An array containing all the hosts installed.
110          *
111          */ 
112         public static Host[] all()  {
113         Process.ifInterruptedStop();
114                 return MsgNative.allHosts();
115         }
116
117         /**
118          * This method returns the name of a host.
119          *
120          * @return                      The name of the host.
121          *
122          */ 
123         public String getName()  {
124         Process.ifInterruptedStop();
125                 return MsgNative.hostGetName(this);
126         }
127
128         /**
129          * Sets the data of the host.
130          *
131      *
132      * @param data
133      */
134         public void setData(Object data) {
135         Process.ifInterruptedStop();
136                 this.data = data;
137         } 
138         /**
139          * Gets the data of the host.
140      *
141      * @return
142      */
143         public Object getData() {
144         Process.ifInterruptedStop();
145                 return this.data;
146         }
147
148         /**
149          * Checks whether a host has data.
150      *
151      * @return
152      */
153         public boolean hasData() {
154         Process.ifInterruptedStop();
155                 return null != this.data;
156         }
157
158         /**
159          * This method returns the number of tasks currently running on a host.
160          * The external load is not taken in account.
161          *
162          * @return                      The number of tasks currently running on a host.
163          */ 
164         public int getLoad() {
165         Process.ifInterruptedStop();
166                 return MsgNative.hostGetLoad(this);
167         }
168
169         /**
170          * This method returns the speed of the processor of a host,
171          * regardless of the current load of the machine.
172          *
173          * @return                      The speed of the processor of the host in flops.
174          *
175          */ 
176         public double getSpeed() {
177         Process.ifInterruptedStop();
178                 return MsgNative.hostGetSpeed(this);
179         }
180
181     /** This method tests if a host is avail.
182      * @return
183      */
184         public boolean isAvail() {
185         Process.ifInterruptedStop();
186                 return MsgNative.hostIsAvail(this);
187         }
188