Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
69737f24f09e816c46c6c3b482fc5e953b4aa295
[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 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 automaticaly 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 never need to create an host your self.
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  * @author  Abdelmalek Cherier
43  * @author  Martin Quinson
44  * @since SimGrid 3.3
45  */ 
46   public class Host {
47   
48         /**
49          * This attribute represents a bind between a java host object and
50          * a native host. Even if this attribute is public you must never
51          * access to it. It is set automaticatly during the call of the 
52          * static method Host.getByName().
53          *
54          * @see                         Host.getByName().
55          */ 
56   public long bind;
57
58   
59         /**
60          * User data.
61          */ 
62     private Object data;
63   protected Host() {
64     this.bind = 0;
65     this.data = null;
66   };
67   
68         /**
69          * This static method gets an host instance associated with a native
70          * host of your platform. This is the best way to get a java host object.
71          *
72          * @param name          The name of the host to get.
73          *
74          * @exception           HostNotFoundException if the name of the host is not valid.
75          *                                      MsgException if the native version of this method failed.
76          */ 
77   public static Host getByName(String name) 
78     throws HostNotFoundException, NativeException, JniException {
79     return MsgNative.hostGetByName(name);
80   }
81   
82         /**
83          * This static method returns the number of the installed hosts.
84          *
85          * @return                      The number of the installed hosts.
86          *
87          */ 
88   public static int getNumber() throws NativeException, JniException {
89     return MsgNative.hostGetNumber();
90   }
91   
92         /**
93          * This static method return an instance to the host of the current process.
94          *
95          * @return                      The host on which the current process is executed.
96          *
97          * @exception           MsgException if the native version of this method failed.
98          */ 
99     public static Host currentHost() throws JniException {
100     return MsgNative.hostSelf();
101   }
102   
103         /**
104          * This static method returns all of the hosts of the installed platform.
105          *
106          * @return                      An array containing all the hosts installed.
107          *
108          * @exception           MsgException if the native version of this method failed.
109          */ 
110     public static Host[] all() throws JniException, NativeException {
111     return MsgNative.allHosts();
112   }
113   
114         /**
115          * This method returns the name of a host.
116          *
117          * @return                      The name of the host.
118          *
119          * @exception           InvalidHostException if the host is not valid.
120          */ 
121     public String getName() throws NativeException, JniException {
122     return MsgNative.hostGetName(this);
123   }
124   
125         /**
126          * This method sets the data of the host.
127          *
128          */ 
129     public void setData(Object data) {
130     this.data = data;
131   } 
132         /**
133          * This method gets the data of the host.
134          */ 
135     public Object getData() {
136     return this.data;
137   }
138   
139         /**
140          * This function tests if a host has data.
141          */ 
142     public boolean hasData() {
143     return null != this.data;
144   }
145   
146         /**
147          * This method returns the number of tasks currently running on a host.
148          * The external load is not taken in account.
149          *
150          * @return                      The number of tasks currently running on a host.
151          *
152          * @exception           InvalidHostException if the host is invalid.
153          *
154          */ 
155   public int getLoad() throws JniException {
156     return MsgNative.hostGetLoad(this);
157   }
158   
159         /**
160          * This method returns the speed of the processor of a host,
161          * regardless of the current load of the machine.
162          *
163          * @return                      The speed of the processor of the host in flops.
164          *
165          * @exception           InvalidHostException if the host is not valid.
166          *
167          */ 
168    public double getSpeed() throws JniException {
169     return MsgNative.hostGetSpeed(this);
170   }
171   
172         /**
173          * This method tests if a host is avail.
174          * 
175          * @exception           JniException if the host is not valid.
176          */ 
177     public boolean isAvail() throws JniException {
178     return MsgNative.hostIsAvail(this);
179   }
180   
181    /** Send the given task to the given channel of the host */ 
182    
183     public void put(int channel, Task task) throws JniException,
184     NativeException {
185     MsgNative.hostPut(this, channel, task, -1);
186   } 
187    /** Send the given task to the given channel of the host (waiting at most #timeout seconds) */ 
188    
189     public void put(int channel, Task task,
190                     double timeout) throws JniException, NativeException {
191     MsgNative.hostPut(this, channel, task, timeout);
192   } 
193   
194   
195    /** Send the given task to the given channel of the host (capping the emision rate to #maxrate) */ 
196    
197     public void putBounded(int channel, Task task,
198                            double maxrate) throws JniException,
199     NativeException {
200     MsgNative.hostPutBounded(this, channel, task, maxrate);
201         }
202         
203          /** Send the given task to mailbox identified by the default alias */ 
204         public void send(Task task) throws JniException, NativeException  {
205                 String alias = this.getName() + ":" + Process.currentProcess().msgName();       
206         MsgNative.taskSend(alias, task, -1);
207         } 
208         
209         /** Send the given task to the mailbox associated with the specified alias */ 
210    
211     public void send(String alias, Task task) throws JniException, NativeException {
212         MsgNative.taskSend(alias, task, -1);
213         }
214         
215          /** Send the given task in the mailbox associated with the alias of the current host (waiting at most #timeout seconds) */
216         public void send(Task task, double timeout) throws JniException, NativeException {
217         String alias = this.getName() + ":" + Process.currentProcess().msgName();
218         MsgNative.taskSend(alias, task, timeout);
219         }
220         
221          /** Send the given task to mailbox associated with the specified alias (waiting at most #timeout seconds) */
222     public void send(String alias, Task task, double timeout) throws JniException, NativeException {
223         MsgNative.taskSend(alias, task, timeout);
224         }
225         
226          /** Send the given task to the mailbox associated with the default alias (capping the emision rate to #maxrate) */ 
227         public void sendBounded(Task task, double maxrate) throws JniException, NativeException {
228         String alias = this.getName() + ":" + Process.currentProcess().msgName();
229                         
230         MsgNative.taskSendBounded(alias, task, maxrate);
231         }  
232         
233          /** Send the given task to the mailbox associated with the specified alias (capping the emision rate to #maxrate) */
234         public void sendBounded(String alias, Task task, double maxrate) throws JniException, NativeException {
235         MsgNative.taskSendBounded(alias, task, maxrate);
236         } 
237