2 * Bindings to the MSG hosts
4 * Copyright 2006,2007,2010 The SimGrid Team
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.
13 import java.lang.String;
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.
25 * The best way to get an host instance is to call the static method
28 * For example to get the instance of the host. If your platform
29 * file description contains an host named "Jacquelin" :
35 jacquelin = Host.getByName("Jacquelin");
36 } catch(HostNotFoundException e) {
37 System.err.println(e.toString());
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().
51 * @see Host.getByName().
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.
69 * @param name The name of the host to get.
71 * @exception HostNotFoundException if the name of the host is not valid.
72 * MsgException if the native version of this method failed.
74 public static Host getByName(String name)
75 throws HostNotFoundException, NativeException, JniException {
76 return MsgNative.hostGetByName(name);
80 * This static method returns the count of the installed hosts.
82 * @return The count of the installed hosts.
85 public static int getCount() throws NativeException, JniException {
86 return MsgNative.hostGetCount();
90 * This static method return an instance to the host of the current process.
92 * @return The host on which the current process is executed.
94 * @exception MsgException if the native version of this method failed.
96 public static Host currentHost() throws JniException {
97 return MsgNative.hostSelf();
101 * This static method returns all of the hosts of the installed platform.
103 * @return An array containing all the hosts installed.
105 * @exception MsgException if the native version of this method failed.
107 public static Host[] all() throws JniException, NativeException {
108 return MsgNative.allHosts();
112 * This method returns the name of a host.
114 * @return The name of the host.
116 * @exception InvalidHostException if the host is not valid.
118 public String getName() throws NativeException, JniException {
119 return MsgNative.hostGetName(this);
123 * This method sets the data of the host.
126 public void setData(Object data) {
130 * This method gets the data of the host.
132 public Object getData() {
137 * This function tests if a host has data.
139 public boolean hasData() {
140 return null != this.data;
144 * This method returns the number of tasks currently running on a host.
145 * The external load is not taken in account.
147 * @return The number of tasks currently running on a host.
149 * @exception InvalidHostException if the host is invalid.
152 public int getLoad() throws JniException {
153 return MsgNative.hostGetLoad(this);
157 * This method returns the speed of the processor of a host,
158 * regardless of the current load of the machine.
160 * @return The speed of the processor of the host in flops.
162 * @exception InvalidHostException if the host is not valid.
165 public double getSpeed() throws JniException {
166 return MsgNative.hostGetSpeed(this);
170 * This method tests if a host is avail.
172 * @exception JniException if the host is not valid.
174 public boolean isAvail() throws JniException {
175 return MsgNative.hostIsAvail(this);
178 /** Send the given task to mailbox identified by the default alias */
179 public void send(Task task) throws JniException, NativeException {
180 String alias = this.getName() + ":" + Process.currentProcess().msgName();
181 MsgNative.taskSend(alias, task, -1);
184 /** Send the given task to the mailbox associated with the specified alias */
186 public void send(String alias, Task task) throws JniException, NativeException {
187 MsgNative.taskSend(alias, task, -1);
190 /** Send the given task in the mailbox associated with the alias of the current host (waiting at most \a timeout seconds) */
191 public void send(Task task, double timeout) throws JniException, NativeException {
192 String alias = this.getName() + ":" + Process.currentProcess().msgName();
193 MsgNative.taskSend(alias, task, timeout);
196 /** Send the given task to mailbox associated with the specified alias (waiting at most \a timeout seconds) */
197 public void send(String alias, Task task, double timeout) throws JniException, NativeException {
198 MsgNative.taskSend(alias, task, timeout);
201 /** Send the given task to the mailbox associated with the default alias (capping the emision rate to \a maxrate) */
202 public void sendBounded(Task task, double maxrate) throws JniException, NativeException {
203 String alias = this.getName() + ":" + Process.currentProcess().msgName();
205 MsgNative.taskSendBounded(alias, task, maxrate);
208 /** Send the given task to the mailbox associated with the specified alias (capping the emision rate to \a maxrate) */
209 public void sendBounded(String alias, Task task, double maxrate) throws JniException, NativeException {
210 MsgNative.taskSendBounded(alias, task, maxrate);