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.
14 /* FIXME: split into internal classes of Msg, Task, Host etc. */
17 * Contains all the native methods related to Process, Host and Task.
19 final class MsgNative {
21 /******************************************************************
22 * The natively implemented methods connected to the MSG Process *
23 ******************************************************************/
25 * The natively implemented method to create an MSG process.
27 * @param process The java process object to bind with the MSG native process.
28 * @param host A valid (binded) host where create the process.
30 * @see Process constructors.
33 void processCreate(Process process, Host host);
36 * The natively implemented method to kill all the process of the simulation.
38 * @param resetPID Should we reset the PID numbers. A negative number means no reset
39 * and a positive number will be used to set the PID of the next newly
42 * @return The function returns the PID of the next created process.
44 final static native int processKillAll(int resetPID);
47 * The natively implemented method to suspend an MSG process.
49 * @param process The valid (binded with a native process) java process to suspend.
51 * @see Process.pause()
53 final static native void processSuspend(Process process);
56 * The natively implemented method to kill a MSG process.
58 * @param process The valid (binded with a native process) java process to kill.
62 final static native void processKill(Process process);
65 * The natively implemented method to resume a suspended MSG process.
67 * @param process The valid (binded with a native process) java process to resume.
70 * @see Process.restart()
72 final static native void processResume(Process process);
75 * The natively implemented method to test if MSG process is suspended.
77 * @param process The valid (binded with a native process) java process to test.
79 * @return If the process is suspended the method retuns true. Otherwise the
80 * method returns false.
82 * @see Process.isSuspended()
84 final static native boolean processIsSuspended(Process process);
87 * The natively implemented method to get the host of a MSG process.
89 * @param process The valid (binded with a native process) java process to get the host.
91 * @return The method returns the host where the process is running.
93 * @exception HostNotFoundException if the SimGrid native code failed (initialization error?).
95 * @see Process.getHost()
97 final static native Host processGetHost(Process process);
100 * The natively implemented method to get a MSG process from his PID.
102 * @param PID The PID of the process to get.
104 * @return The process with the specified PID.
106 * @see Process.getFromPID()
108 final static native Process processFromPID(int PID) ;
111 * The natively implemented method to get the PID of a MSG process.
113 * @param process The valid (binded with a native process) java process to get the PID.
115 * @return The PID of the specified process.
117 * @see Process.getPID()
119 final static native int processGetPID(Process process);
122 * The natively implemented method to get the PPID of a MSG process.
124 * @param process The valid (binded with a native process) java process to get the PID.
126 * @return The PPID of the specified process.
128 * @see Process.getPPID()
130 final static native int processGetPPID(Process process);
133 * The natively implemented method to get the current running process.
135 * @return The current process.
137 * @see Process.currentProcess()
139 final static native Process processSelf();
142 * The natively implemented method to migrate a process from his currnet host to a new host.
144 * @param process The (valid) process to migrate.
145 * @param host A (valid) host where move the process.
148 * @see Process.migrate()
149 * @see Host.getByName()
151 final static native void processChangeHost(Process process, Host host) ;
154 * The natively implemented native to request the current process to sleep
155 * until time seconds have elapsed.
157 * @param seconds The time the current process must sleep.
159 * @exception HostFailureException if the SimGrid native code failed.
161 * @see Process.waitFor()
163 final static native void processWaitFor(double seconds) throws HostFailureException;
166 * The natively implemented native method to exit a process.
168 * @see Process.exit()
170 final static native void processExit(Process process);
173 /******************************************************************
174 * The natively implemented methods connected to the MSG host *
175 ******************************************************************/
178 * The natively implemented method to get an host from his name.
180 * @param name The name of the host to get.
182 * @return The host having the specified name.
184 * @exception HostNotFoundException if there is no such host
187 * @see Host.getByName()
189 final static native Host hostGetByName(String name) throws HostNotFoundException;
192 * The natively implemented method to get the name of an MSG host.
194 * @param host The host (valid) to get the name.
196 * @return The name of the specified host.
198 * @see Host.getName()
200 final static native String hostGetName(Host host);
203 * The natively implemented method to get the number of hosts of the simulation.
205 * @return The number of hosts of the simulation.
207 * @see Host.getNumber()
209 final static native int hostGetCount();
212 * The natively implemented method to get the host of the current runing process.
214 * @return The host of the current running process.
216 * @see Host.currentHost()
218 final static native Host hostSelf();
221 * The natively implemented method to get the speed of a MSG host.
223 * @param host The host to get the host.
225 * @return The speed of the specified host.
227 * @see Host.getSpeed()
230 final static native double hostGetSpeed(Host host);
233 * The natively implemented native method to test if an host is avail.
235 * @param host The host to test.
237 * @return If the host is avail the method returns true.
238 * Otherwise the method returns false.
240 * @see Host.isAvail()
242 final static native boolean hostIsAvail(Host host);
245 * The natively implemented native method to get all the hosts of the simulation.
247 * @return A array which contains all the hosts of simulation.
250 final static native Host[] allHosts();
253 * The natively implemented native method to get the number of running tasks on a host.
255 * @param The host concerned by the operation.
257 * @return The number of running tasks.
259 final static native int hostGetLoad(Host host);
261 /******************************************************************
262 * The natively implemented methods connected to the MSG task *
263 ******************************************************************/
266 * The natively implemented method to create a MSG task.
268 * @param name The name of th task.
269 * @param computeDuration A value of the processing amount (in flop) needed
270 * to process the task. If 0, then it cannot be executed
271 * with the execute() method. This value has to be >= 0.
272 * @param messageSize A value of amount of data (in bytes) needed to transfert
273 * this task. If 0, then it cannot be transfered this task.
274 * If 0, then it cannot be transfered with the get() and put()
275 * methods. This value has to be >= 0.
276 * @param task The java task object to bind with the native task to create.
278 * @exception IllegalArgumentException if compute duration <0 or message size <0
282 final static native void taskCreate(Task task, String name,
283 double computeDuration,
285 throws IllegalArgumentException;
288 * The natively implemented method to get the sender of a task.
290 * @param task The task (valid) to get the sender.
292 * @return The sender of the task.
294 * @see Task.getSender()
296 final static native Process taskGetSender(Task task);
299 * The natively implementd method to get the source of a task.
301 * @param task The task to get the source.
303 * @return The source of the task.
306 * @see Task.getSource()
308 final static native Host taskGetSource(Task task);
311 * The natively implemented method to get the name of the task.
313 * @param task The task to get the name.
315 * @return The name of the specified task.
317 * @see Task.getName()
319 final static native String taskGetName(Task task);
322 * The natively implemented method to cancel a task.
324 * @param task The task to cancel.
327 * @see Task.cancel().
329 final static native void taskCancel(Task task);
332 * The natively implemented method to create a MSG parallel task.
334 * @param name The name of the parallel task.
335 * @param hosts The list of hosts implied by the parallel task.
336 * @param computeDurations The total number of operations that have to be performed
338 * @param messageSizes An array of doubles
340 * @see ParallelTask.create()
342 final static native void parallelTaskCreate(Task pTask, String name,
344 double[]computeDurations,
345 double[]messageSizes)
346 throws NullPointerException, IllegalArgumentException;
349 * The natively implemented method to get the computing amount of the task.
351 * @param task The task to get the computing amount.
353 * @return The computing amount of the specified task.
355 * @see Task.getComputeDuration()
357 final static native double taskGetComputeDuration(Task task);
360 * The natively implemented method to get the remaining computation
362 * @param task The task to get the remaining computation.
364 * @return The remaining computation of the specified task.
366 * @see Task.getRemainingDuration()
368 final static native double taskGetRemainingDuration(Task task);
371 * The natively implemented method to set the priority of a task.
373 * @param task The task to set the priority
375 * @param priority The new priority of the specified task.
377 * @see Task.setPriority()
379 final static native void taskSetPriority(Task task, double priority);
382 * The natively implemented method to destroy a MSG task.
384 * @param The task to destroy.
387 * @see Task.destroy()
389 final static native void taskDestroy(Task task) ;
392 * The natively implemented method to execute a MSG task.
394 * @param task The task to execute.
396 * @exception HostFailureException,TaskCancelledException on error in the C world
398 * @see Task.execute()
400 final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException;
402 /* ****************************************************************
403 * Communication methods thru mailboxes *
404 **************************************************************** */
406 final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException;
407 final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException;
408 final static native int taskListenFrom(String alias);
409 final static native boolean taskListen(String alias);
410 final static native int taskListenFromHost(String alias, Host host);
412 /* ***************************************************************
413 * Task sending methods *
414 *************************************************************** */
417 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
420 * @param alias The alias of the mailbox.
421 * @param task The task to put.
422 * @param max_rate The bounded transmition rate.
424 * @exception NativeException on error in the C world
426 final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;