2 * Contains all the native methods related to Process, Host and Task.
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.
12 package org.simgrid.msg;
14 import org.simgrid.msg.Process;
16 /* FIXME: split into internal classes of Msg, Task, Host etc. */
19 * Contains all the native methods related to Process, Host and Task.
21 final class MsgNative {
23 /******************************************************************
24 * The natively implemented methods connected to the MSG Process *
25 ******************************************************************/
27 * The natively implemented method to create an MSG process.
29 * @param process The java process object to bind with the MSG native process.
30 * @param host A valid (binded) host where create the process.
32 * @see Process constructors.
35 void processCreate(Process process, String hostName) throws HostNotFoundException;
38 * The natively implemented method to kill all the process of the simulation.
40 * @param resetPID Should we reset the PID numbers. A negative number means no reset
41 * and a positive number will be used to set the PID of the next newly
44 * @return The function returns the PID of the next created process.
46 final static native int processKillAll(int resetPID);
49 * The natively implemented method to suspend an MSG process.
51 * @param process The valid (binded with a native process) java process to suspend.
53 * @see Process.pause()
55 final static native void processSuspend(Process process);
58 * The natively implemented method to kill a MSG process.
60 * @param process The valid (binded with a native process) java process to kill.
64 final static native void processKill(Process process);
67 * The natively implemented method to resume a suspended MSG process.
69 * @param process The valid (binded with a native process) java process to resume.
72 * @see Process.restart()
74 final static native void processResume(Process process);
77 * The natively implemented method to test if MSG process is suspended.
79 * @param process The valid (binded with a native process) java process to test.
81 * @return If the process is suspended the method retuns true. Otherwise the
82 * method returns false.
84 * @see Process.isSuspended()
86 final static native boolean processIsSuspended(Process process);
89 * The natively implemented method to get the host of a MSG process.
91 * @param process The valid (binded with a native process) java process to get the host.
93 * @return The method returns the host where the process is running.
95 * @exception HostNotFoundException if the SimGrid native code failed (initialization error?).
97 * @see Process.getHost()
99 final static native Host processGetHost(Process process);
102 * The natively implemented method to get a MSG process from his PID.
104 * @param PID The PID of the process to get.
106 * @return The process with the specified PID.
108 * @see Process.getFromPID()
110 final static native Process processFromPID(int PID) ;
113 * The natively implemented method to get the PID of a MSG process.
115 * @param process The valid (binded with a native process) java process to get the PID.
117 * @return The PID of the specified process.
119 * @see Process.getPID()
121 final static native int processGetPID(Process process);
124 * The natively implemented method to get the PPID of a MSG process.
126 * @param process The valid (binded with a native process) java process to get the PID.
128 * @return The PPID of the specified process.
130 * @see Process.getPPID()
132 final static native int processGetPPID(Process process);
135 * The natively implemented method to get the current running process.
137 * @return The current process.
139 * @see Process.currentProcess()
141 final static native Process processSelf();
144 * The natively implemented method to migrate a process from his currnet host to a new host.
146 * @param process The (valid) process to migrate.
147 * @param host A (valid) host where move the process.
150 * @see Process.migrate()
151 * @see Host.getByName()
153 final static native void processMigrate(Process process, Host host) ;
156 * The natively implemented native to request the current process to sleep
157 * until time seconds have elapsed.
159 * @param seconds The time the current process must sleep.
161 * @exception HostFailureException if the SimGrid native code failed.
163 * @see Process.waitFor()
165 final static native void processWaitFor(double seconds) throws HostFailureException;
168 * The natively implemented native method to exit a process.
170 * @see Process.exit()
172 final static native void processExit(Process process);
175 /******************************************************************
176 * The natively implemented methods connected to the MSG host *
177 ******************************************************************/
180 * The natively implemented method to get an host from his name.
182 * @param name The name of the host to get.
184 * @return The host having the specified name.
186 * @exception HostNotFoundException if there is no such host
189 * @see Host.getByName()
191 final static native Host hostGetByName(String name) throws HostNotFoundException;
194 * The natively implemented method to get the name of an MSG host.
196 * @param host The host (valid) to get the name.
198 * @return The name of the specified host.
200 * @see Host.getName()
202 final static native String hostGetName(Host host);
205 * The natively implemented method to get the number of hosts of the simulation.
207 * @return The number of hosts of the simulation.
209 * @see Host.getNumber()
211 final static native int hostGetCount();
214 * The natively implemented method to get the host of the current runing process.
216 * @return The host of the current running process.
218 * @see Host.currentHost()
220 final static native Host hostSelf();
223 * The natively implemented method to get the speed of a MSG host.
225 * @param host The host to get the host.
227 * @return The speed of the specified host.
229 * @see Host.getSpeed()
232 final static native double hostGetSpeed(Host host);
235 * The natively implemented native method to test if an host is avail.
237 * @param host The host to test.
239 * @return If the host is avail the method returns true.
240 * Otherwise the method returns false.
242 * @see Host.isAvail()
244 final static native boolean hostIsAvail(Host host);
247 * The natively implemented native method to get all the hosts of the simulation.
249 * @return A array which contains all the hosts of simulation.
252 final static native Host[] allHosts();
255 * The natively implemented native method to get the number of running tasks on a host.
257 * @param The host concerned by the operation.
259 * @return The number of running tasks.
261 final static native int hostGetLoad(Host host);
263 /******************************************************************
264 * The natively implemented methods connected to the MSG task *
265 ******************************************************************/
268 * The natively implementd method to get the source of a task.
270 * @param task The task to get the source.
272 * @return The source of the task.
275 * @see Task.getSource()
277 final static native Host taskGetSource(Task task);
280 * The natively implemented method to cancel a task.
282 * @param task The task to cancel.
285 * @see Task.cancel().
287 final static native void taskCancel(Task task);
290 * The natively implemented method to get the computing amount of the task.
292 * @param task The task to get the computing amount.
294 * @return The computing amount of the specified task.
296 * @see Task.getComputeDuration()
298 final static native double taskGetComputeDuration(Task task);
301 * The natively implemented method to get the remaining computation
303 * @param task The task to get the remaining computation.
305 * @return The remaining computation of the specified task.
307 * @see Task.getRemainingDuration()
309 final static native double taskGetRemainingDuration(Task task);
312 * The natively implemented method to set the priority of a task.
314 * @param task The task to set the priority
316 * @param priority The new priority of the specified task.
318 * @see Task.setPriority()
320 final static native void taskSetPriority(Task task, double priority);
323 * The natively implemented method to execute a MSG task.
325 * @param task The task to execute.
327 * @exception HostFailureException,TaskCancelledException on error in the C world
329 * @see Task.execute()
331 final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException;
333 /* ****************************************************************
334 * Communication methods thru mailboxes *
335 **************************************************************** */
337 final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException;
338 final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException;
339 final static native int taskListenFrom(String alias);
340 final static native boolean taskListen(String alias);
341 final static native int taskListenFromHost(String alias, Host host);
343 /* ***************************************************************
344 * Task sending methods *
345 *************************************************************** */
348 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
351 * @param alias The alias of the mailbox.
352 * @param task The task to put.
353 * @param max_rate The bounded transmition rate.
355 * @exception NativeException on error in the C world
357 final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;