Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9dd9f4b9acb26bf8c9ca034869bc7695cdc1b60f
[simgrid.git] / src / java / 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 simgrid.msg;
13 import java.lang.String;
14
15 /**
16  * A host object represents a location (any possible place) where a process may run. 
17  * Thus it is represented as a physical resource with computing capabilities, some 
18  * mailboxes to enable running process to communicate with remote ones, and some private 
19  * data that can be only accessed by local process. An instance of this class is always 
20  * binded with the corresponding native host. All the native hosts are automatically created 
21  * during the call of the method Msg.createEnvironment(). This method take as parameter a
22  * platform file which describes all elements of the platform (host, link, root..).
23  * You cannot create a host yourself.
24  *
25  * The best way to get an host instance is to call the static method 
26  * Host.getByName().
27  *
28  * For example to get the instance of the host. If your platform
29  * file description contains an host named "Jacquelin" :
30  *
31  * \verbatim
32 Host jacquelin;
33
34 try { 
35         jacquelin = Host.getByName("Jacquelin");
36 } catch(HostNotFoundException e) {
37         System.err.println(e.toString());
38 }
39 ...
40 \endverbatim
41  *
42  */ 
43 public class Host {
44
45         /**
46          * This attribute represents a bind between a java host object and
47          * a native host. Even if this attribute is public you must never
48          * access to it. It is set automatically during the call of the 
49          * static method Host.getByName().
50          *
51          * @see                         Host.getByName().
52          */ 
53         public long bind;
54
55
56         /**
57          * User data.
58          */ 
59         private Object data;
60         protected Host() {
61                 this.bind = 0;
62                 this.data = null;
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          * @exception           HostNotFoundException if the name of the host is not valid.
72          *                                      NativeException if the native version of this method failed.
73          */ 
74         public static Host getByName(String name) 
75         throws HostNotFoundException, NativeException {
76                 if (name==null)
77                         throw new NullPointerException("No host can have a null name");
78                 return MsgNative.hostGetByName(name);
79         }
80
81         /**
82          * This static method returns the count of the installed hosts.
83          *
84          * @return                      The count of the installed hosts.
85          *
86          */ 
87         public static int getCount() throws NativeException {
88                 return MsgNative.hostGetCount();
89         }
90
91         /**
92          * This static method return an instance to the host of the current process.
93          *
94          * @return                      The host on which the current process is executed.
95          */ 
96         public static Host currentHost() {
97                 return MsgNative.hostSelf();
98         }
99
100         /**
101          * This static method returns all of the hosts of the installed platform.
102          *
103          * @return                      An array containing all the hosts installed.
104          *
105          * @exception           NativeException if the native version of this method failed.
106          */ 
107         public static Host[] all() throws NativeException {
108                 return MsgNative.allHosts();
109         }
110
111         /**
112          * This method returns the name of a host.
113          *
114          * @return                      The name of the host.
115          *
116          * @exception           NativeException FIXME: check when
117          */ 
118         public String getName() throws NativeException {
119                 return MsgNative.hostGetName(this);
120         }
121
122         /**
123          * Sets the data of the host.
124          *
125          */ 
126         public void setData(Object data) {
127                 this.data = data;
128         } 
129         /**
130          * Gets the data of the host.
131          */ 
132         public Object getData() {
133                 return this.data;
134         }
135
136         /**
137          * Checks whether a host has data.
138          */ 
139         public boolean hasData() {
140                 return null != this.data;
141         }
142
143         /**
144          * This method returns the number of tasks currently running on a host.
145          * The external load is not taken in account.
146          *
147          * @return                      The number of tasks currently running on a host.
148          */ 
149         public int getLoad() {
150                 return MsgNative.hostGetLoad(this);
151         }
152
153         /**
154          * This method returns the speed of the processor of a host,
155          * regardless of the current load of the machine.
156          *
157          * @return                      The speed of the processor of the host in flops.
158          *
159          */ 
160         public double getSpeed() {
161                 return MsgNative.hostGetSpeed(this);
162         }
163
164         /** This method tests if a host is avail. */
165         public boolean isAvail() {
166                 return MsgNative.hostIsAvail(this);
167         }
168