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.
15 * Contains all the native methods related to Process, Host and Task.
17 final class MsgNative {
21 void selectContextFactory(String name) throws NativeException;
23 /******************************************************************
24 * The natively implemented methods connected to the MSG Process *
25 ******************************************************************/
28 * The natively implemented method to create an MSG process.
30 * @param process The java process object to bind with the MSG native process.
31 * @param host A valid (binded) host where create the process.
33 * @exception simgrid.msg.JniException if JNI stuff goes wrong.
35 * @see Process constructors.
38 void processCreate(Process process, Host host) throws JniException;
41 * The natively implemented method to kill all the process of the simulation.
43 * @param resetPID Should we reset the PID numbers. A negative number means no reset
44 * and a positive number will be used to set the PID of the next newly
47 * @return The function returns the PID of the next created process.
49 final static native int processKillAll(int resetPID);
52 * The natively implemented method to suspend an MSG process.
54 * @param process The valid (binded with a native process) java process to suspend.
56 * @exception JniException if something goes wrong with JNI
57 * NativeException if the SimGrid native code failed.
59 * @see Process.pause()
61 final static native void processSuspend(Process process) throws JniException, NativeException;
64 * The natively implemented method to kill a MSG process.
66 * @param process The valid (binded with a native process) java process to kill.
70 final static native void processKill(Process process)
74 * The natively implemented method to resume a suspended MSG process.
76 * @param process The valid (binded with a native process) java process to resume.
78 * @exception JniException if something goes wrong with JNI
79 * NativeException if the SimGrid native code failed.
81 * @see Process.restart()
83 final static native void processResume(Process process)
84 throws JniException, NativeException;
87 * The natively implemented method to test if MSG process is suspended.
89 * @param process The valid (binded with a native process) java process to test.
91 * @return If the process is suspended the method retuns true. Otherwise the
92 * method returns false.
94 * @exception JniException if something goes wrong with JNI
96 * @see Process.isSuspended()
98 final static native boolean processIsSuspended(Process process) throws
102 * The natively implemented method to get the host of a MSG process.
104 * @param process The valid (binded with a native process) java process to get the host.
106 * @return The method returns the host where the process is running.
108 * @exception JniException if something goes wrong with JNI
109 * NativeException if the SimGrid native code failed.
111 * @see Process.getHost()
113 final static native Host processGetHost(Process process)
114 throws JniException, NativeException;
117 * The natively implemented method to get a MSG process from his PID.
119 * @param PID The PID of the process to get.
121 * @return The process with the specified PID.
123 * @exception NativeException if the SimGrid native code failed.
125 * @see Process.getFromPID()
127 final static native Process processFromPID(int PID) throws NativeException;
130 * The natively implemented method to get the PID of a MSG process.
132 * @param process The valid (binded with a native process) java process to get the PID.
134 * @return The PID of the specified process.
136 * @exception NativeException if the SimGrid native code failed.
138 * @see Process.getPID()
140 final static native int processGetPID(Process process) throws
144 * The natively implemented method to get the PPID of a MSG process.
146 * @param process The valid (binded with a native process) java process to get the PID.
148 * @return The PPID of the specified process.
150 * @exception NativeException if the SimGrid native code failed.
152 * @see Process.getPPID()
154 final static native int processGetPPID(Process process) throws
158 * The natively implemented method to get the current running process.
160 * @return The current process.
162 * @exception NativeException if the SimGrid native code failed.
164 * @see Process.currentProcess()
166 final static native Process processSelf() throws NativeException;
169 * The natively implemented method to get the current running process PID.
171 * @return The PID of the current process.
173 * @see Process.currentProcessPID()
175 final static native int processSelfPID();
178 * The natively implemented method to get the current running process PPID.
180 * @return The PPID of the current process.
182 * @see Process.currentProcessPPID()
184 final static native int processSelfPPID();
187 * The natively implemented method to migrate a process from his currnet host to a new host.
189 * @param process The (valid) process to migrate.
190 * @param host A (valid) host where move the process.
192 * @exception JniException if something goes wrong with JNI
193 * NativeException if the SimGrid native code failed.
195 * @see Process.migrate()
196 * @see Host.getByName()
198 final static native void processChangeHost(Process process, Host host)
199 throws JniException, NativeException;
202 * The natively implemented native to request the current process to sleep
203 * until time seconds have elapsed.
205 * @param seconds The time the current process must sleep.
207 * @exception NativeException if the SimGrid native code failed.
209 * @see Process.waitFor()
211 final static native void processWaitFor(double seconds) throws
215 * The natively implemented native method to exit a process.
217 * @exception JniException if something goes wrong with JNI
219 * @see Process.exit()
221 final static native void processExit(Process process) throws JniException;
224 /******************************************************************
225 * The natively implemented methods connected to the MSG host *
226 ******************************************************************/
229 * The natively implemented method to get an host from his name.
231 * @param name The name of the host to get.
233 * @return The host having the specified name.
235 * @exception JniException if something goes wrong with JNI
236 * HostNotFoundException if there is no such host
237 * NativeException if the SimGrid native code failed.
239 * @see Host.getByName()
241 final static native Host hostGetByName(String name)
242 throws JniException, HostNotFoundException, NativeException;
245 * The natively implemented method to get the name of an MSG host.
247 * @param host The host (valid) to get the name.
249 * @return The name of the specified host.
251 * @exception JniException if something goes wrong with JNI
253 * @see Host.getName()
255 final static native String hostGetName(Host host) throws JniException;
258 * The natively implemented method to get the number of hosts of the simulation.
260 * @return The number of hosts of the simulation.
262 * @see Host.getNumber()
264 final static native int hostGetCount();
267 * The natively implemented method to get the host of the current runing process.
269 * @return The host of the current running process.
271 * @exception JniException if something goes wrong with JNI
273 * @see Host.currentHost()
275 final static native Host hostSelf() throws JniException;
278 * The natively implemented method to get the speed of a MSG host.
280 * @param host The host to get the host.
282 * @return The speed of the specified host.
284 * @exception JniException if something goes wrong with JNI
286 * @see Host.getSpeed()
289 final static native double hostGetSpeed(Host host) throws JniException;
292 * The natively implemented native method to test if an host is avail.
294 * @param host The host to test.
296 * @return If the host is avail the method returns true.
297 * Otherwise the method returns false.
299 * @exception JniException if something goes wrong with JNI
301 * @see Host.isAvail()
303 final static native boolean hostIsAvail(Host host) throws JniException;
306 * The natively implemented native method to get all the hosts of the simulation.
308 * @exception JniException if something goes wrong with JNI
310 * @return A array which contains all the hosts of simulation.
313 final static native Host[] allHosts() throws JniException;
316 * The natively implemented native method to get the number of running tasks on a host.
318 * @param The host concerned by the operation.
320 * @return The number of running tasks.
322 * @exception JniException if something goes wrong with JNI
325 final static native int hostGetLoad(Host host) throws JniException;
327 /******************************************************************
328 * The natively implemented methods connected to the MSG task *
329 ******************************************************************/
332 * The natively implemented method to create a MSG task.
334 * @param name The name of th task.
335 * @param computeDuration A value of the processing amount (in flop) needed
336 * to process the task. If 0, then it cannot be executed
337 * with the execute() method. This value has to be >= 0.
338 * @param messageSize A value of amount of data (in bytes) needed to transfert
339 * this task. If 0, then it cannot be transfered this task.
340 * If 0, then it cannot be transfered with the get() and put()
341 * methods. This value has to be >= 0.
342 * @param task The java task object to bind with the native task to create.
344 * @exception JniException if something goes wrong with JNI
345 * NullPointerException if the specified name is null.
346 * IllegalArgumentException if compute duration <0 or message size <0
350 final static native void taskCreate(Task task, String name,
351 double computeDuration,
353 throws JniException, NullPointerException, IllegalArgumentException;
356 * The natively implemented method to get the sender of a task.
358 * @param task The task (valid) to get the sender.
360 * @return The sender of the task.
362 * @exception InvalidTaskException is the specified task is not valid. A task
363 * is invalid if it is not binded with a native task.
365 * @see Task.getSender()
367 final static native Process taskGetSender(Task task) throws JniException;
370 * The natively implementd method to get the source of a task.
372 * @param task The task to get the source.
374 * @return The source of the task.
376 * @exception InvalidTaskException is the specified task is not valid. A task
377 * is invalid if it is not binded with a native task.
379 * @see Task.getSource()
381 final static native Host taskGetSource(Task task) throws JniException,
385 * The natively implemented method to get the name of the task.
387 * @param task The task to get the name.
389 * @return The name of the specified task.
391 * @exception InvalidTaskException is the specified task is not valid. A task
392 * is invalid if it is not binded with a native task.
394 * @see Task.getName()
396 final static native String taskGetName(Task task) throws JniException;
399 * The natively implemented method to cancel a task.
401 * @param task The task to cancel.
403 * @exception InvalidTaskException if the specified task is not valid. A task
404 * is invalid if it is not binded with a native task.
405 * MsgException if the cancelation failed.
407 * @see Task.cancel().
409 final static native void taskCancel(Task task) throws JniException,
413 * The natively implemented method to create a MSG parallel task.
415 * @param name The name of the parallel task.
416 * @param hosts The list of hosts implied by the parallel task.
417 * @param computeDurations The total number of operations that have to be performed
419 * @param messageSizes An array of doubles
421 * @see ParallelTask.create()
423 final static native void parallelTaskCreate(Task pTask, String name,
425 double[]computeDurations,
426 double[]messageSizes)
427 throws JniException, NullPointerException, IllegalArgumentException;
430 * The natively implemented method to get the computing amount of the task.
432 * @param task The task to get the computing amount.
434 * @return The computing amount of the specified task.
436 * @exception InvalidTaskException if the specified task is not valid. A task
437 * is invalid if it is not binded with a native task.
438 * MsgException if the cancelation failed.
440 * @see Task.getComputeDuration()
442 final static native double taskGetComputeDuration(Task task) throws
446 * The natively implemented method to get the remaining computation
448 * @param task The task to get the remaining computation.
450 * @return The remaining computation of the specified task.
452 * @exception InvalidTaskException if the specified task is not valid. A task
453 * is invalid if it is not binded with a native task.
454 * MsgException if the cancelation failed.
456 * @see Task.getRemainingDuration()
458 final static native double taskGetRemainingDuration(Task task) throws
462 * The natively implemented method to set the priority of a task.
464 * @param task The task to set the priority
466 * @param priority The new priority of the specified task.
468 * @exception InvalidTaskException if the specified task is not valid. A task
469 * is invalid if it is not binded with a native task.
470 * MsgException if the cancelation failed.
472 * @see Task.setPriority()
474 final static native void taskSetPriority(Task task,
475 double priority) throws
479 * The natively implemented method to destroy a MSG task.
481 * @param The task to destroy.
483 * @exception InvalidTaskException is the specified task is not valid. A task
484 * is invalid if it is not binded with a native task.
485 * MsgException if the destruction failed.
487 * @see Task.destroy()
489 final static native void taskDestroy(Task task) throws JniException,
493 * The natively implemented method to execute a MSG task.
495 * @param task The task to execute.
497 * @exception InvalidTaskException is the specified task is not valid. A task
498 * is invalid if it is not binded with a native task.
499 * MsgException if the destruction failed.
501 * @see Task.execute()
503 final static native void taskExecute(Task task) throws JniException,
508 /* ****************************************************************
509 * Communication methods thru mailboxes *
510 **************************************************************** */
513 final static native void taskSend(String alias, Task task, double timeout)
514 throws JniException, NativeException;
517 final static native Task taskReceive(String alias, double timeout, Host host)
518 throws JniException, NativeException;
520 final static native int taskListenFrom(String alias)
521 throws JniException, NativeException;
524 final static native boolean taskListen(String alias)
527 final static native int taskListenFromHost(String alias, Host host)
530 /* ***************************************************************
531 * Task sending methods *
532 *************************************************************** */
535 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
538 * @param alias The alias of the mailbox.
539 * @param task The task to put.
540 * @param max_rate The bounded transmition rate.
542 * @exception InvalidTaskException if the task is not valid.
543 * InvalidHostException if the host is not valid.
544 * MsgException if the operation failed.
546 final static native void taskSendBounded(String alias, Task task, double maxrate)
547 throws JniException, NativeException;