2 * simgrid.msg.Msg.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
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 /* Contains all the native methods reloaded by Process, Host and Task.
16 * @author Abdelmalek Cherier
17 * @author Martin Quinson
20 final class MsgNative {
24 void selectContextFactory(String name) throws NativeException;
26 /******************************************************************
27 * The natively implemented methods connected to the MSG Process *
28 ******************************************************************/
31 * The natively implemented method to create an MSG process.
33 * @param process The java process object to bind with the MSG native process.
34 * @param host A valid (binded) host where create the process.
36 * @exception simgrid.msg.JniException if JNI stuff goes wrong.
38 * @see Process constructors.
41 void processCreate(Process process, Host host) throws JniException;
44 * The natively implemented method to kill all the process of the simulation.
46 * @param resetPID Should we reset the PID numbers. A negative number means no reset
47 * and a positive number will be used to set the PID of the next newly
50 * @return The function returns the PID of the next created process.
52 final static native int processKillAll(int resetPID);
55 * The natively implemented method to suspend an MSG process.
57 * @param process The valid (binded with a native process) java process to suspend.
59 * @exception JniException if something goes wrong with JNI
60 * NativeException if the SimGrid native code failed.
62 * @see Process.pause()
64 final static native void processSuspend(Process process)
65 throws JniException, NativeException;
68 * The natively implemented method to kill a MSG process.
70 * @param process The valid (binded with a native process) java process to kill.
74 final static native void processKill(Process process)
78 * The natively implemented method to resume a suspended MSG process.
80 * @param process The valid (binded with a native process) java process to resume.
82 * @exception JniException if something goes wrong with JNI
83 * NativeException if the SimGrid native code failed.
85 * @see Process.restart()
87 final static native void processResume(Process process)
88 throws JniException, NativeException;
91 * The natively implemented method to test if MSG process is suspended.
93 * @param process The valid (binded with a native process) java process to test.
95 * @return If the process is suspended the method retuns true. Otherwise the
96 * method returns false.
98 * @exception JniException if something goes wrong with JNI
100 * @see Process.isSuspended()
102 final static native boolean processIsSuspended(Process process) throws
106 * The natively implemented method to get the host of a MSG process.
108 * @param process The valid (binded with a native process) java process to get the host.
110 * @return The method returns the host where the process is running.
112 * @exception JniException if something goes wrong with JNI
113 * NativeException if the SimGrid native code failed.
115 * @see Process.getHost()
117 final static native Host processGetHost(Process process)
118 throws JniException, NativeException;
121 * The natively implemented method to get a MSG process from his PID.
123 * @param PID The PID of the process to get.
125 * @return The process with the specified PID.
127 * @exception NativeException if the SimGrid native code failed.
129 * @see Process.getFromPID()
131 final static native Process processFromPID(int PID) throws NativeException;
134 * The natively implemented method to get the PID of a MSG process.
136 * @param process The valid (binded with a native process) java process to get the PID.
138 * @return The PID of the specified process.
140 * @exception NativeException if the SimGrid native code failed.
142 * @see Process.getPID()
144 final static native int processGetPID(Process process) throws
148 * The natively implemented method to get the PPID of a MSG process.
150 * @param process The valid (binded with a native process) java process to get the PID.
152 * @return The PPID of the specified process.
154 * @exception NativeException if the SimGrid native code failed.
156 * @see Process.getPPID()
158 final static native int processGetPPID(Process process) throws
162 * The natively implemented method to get the current running process.
164 * @return The current process.
166 * @exception NativeException if the SimGrid native code failed.
168 * @see Process.currentProcess()
170 final static native Process processSelf() throws NativeException;
173 * The natively implemented method to get the current running process PID.
175 * @return The PID of the current process.
177 * @see Process.currentProcessPID()
179 final static native int processSelfPID();
182 * The natively implemented method to get the current running process PPID.
184 * @return The PPID of the current process.
186 * @see Process.currentProcessPPID()
188 final static native int processSelfPPID();
191 * The natively implemented method to migrate a process from his currnet host to a new host.
193 * @param process The (valid) process to migrate.
194 * @param host A (valid) host where move the process.
196 * @exception JniException if something goes wrong with JNI
197 * NativeException if the SimGrid native code failed.
199 * @see Process.migrate()
200 * @see Host.getByName()
202 final static native void processChangeHost(Process process, Host host)
203 throws JniException, NativeException;
206 * The natively implemented native to request the current process to sleep
207 * until time seconds have elapsed.
209 * @param seconds The time the current process must sleep.
211 * @exception NativeException if the SimGrid native code failed.
213 * @see Process.waitFor()
215 final static native void processWaitFor(double seconds) throws
219 * The natively implemented native method to exit a process.
221 * @exception JniException if something goes wrong with JNI
223 * @see Process.exit()
225 final static native void processExit(Process process) throws JniException;
228 /******************************************************************
229 * The natively implemented methods connected to the MSG host *
230 ******************************************************************/
233 * The natively implemented method to get an host from his name.
235 * @param name The name of the host to get.
237 * @return The host having the specified name.
239 * @exception JniException if something goes wrong with JNI
240 * HostNotFoundException if there is no such host
241 * NativeException if the SimGrid native code failed.
243 * @see Host.getByName()
245 final static native Host hostGetByName(String name)
246 throws JniException, HostNotFoundException, NativeException;
249 * The natively implemented method to get the name of an MSG host.
251 * @param host The host (valid) to get the name.
253 * @return The name of the specified host.
255 * @exception JniException if something goes wrong with JNI
257 * @see Host.getName()
259 final static native String hostGetName(Host host) throws JniException;
262 * The natively implemented method to get the number of hosts of the simulation.
264 * @return The number of hosts of the simulation.
266 * @see Host.getNumber()
268 final static native int hostGetNumber();
271 * The natively implemented method to get the host of the current runing process.
273 * @return The host of the current running process.
275 * @exception JniException if something goes wrong with JNI
277 * @see Host.currentHost()
279 final static native Host hostSelf() throws JniException;
282 * The natively implemented method to get the speed of a MSG host.
284 * @param host The host to get the host.
286 * @return The speed of the specified host.
288 * @exception JniException if something goes wrong with JNI
290 * @see Host.getSpeed()
293 final static native double hostGetSpeed(Host host) throws JniException;
296 * The natively implemented native method to test if an host is avail.
298 * @param host The host to test.
300 * @return If the host is avail the method returns true.
301 * Otherwise the method returns false.
303 * @exception JniException if something goes wrong with JNI
305 * @see Host.isAvail()
307 final static native boolean hostIsAvail(Host host) throws JniException;
310 * The natively implemented native method to get all the hosts of the simulation.
312 * @exception JniException if something goes wrong with JNI
314 * @return A array which contains all the hosts of simulation.
317 final static native Host[] allHosts() throws JniException;
320 * The natively implemented native method to get the number of running tasks on a host.
322 * @param The host concerned by the operation.
324 * @return The number of running tasks.
326 * @exception JniException if something goes wrong with JNI
329 final static native int hostGetLoad(Host host) throws JniException;
331 /******************************************************************
332 * The natively implemented methods connected to the MSG task *
333 ******************************************************************/
336 * The natively implemented method to create a MSG task.
338 * @param name The name of th task.
339 * @param computeDuration A value of the processing amount (in flop) needed
340 * to process the task. If 0, then it cannot be executed
341 * with the execute() method. This value has to be >= 0.
342 * @param messageSize A value of amount of data (in bytes) needed to transfert
343 * this task. If 0, then it cannot be transfered this task.
344 * If 0, then it cannot be transfered with the get() and put()
345 * methods. This value has to be >= 0.
346 * @param task The java task object to bind with the native task to create.
348 * @exception JniException if something goes wrong with JNI
349 * NullPointerException if the specified name is null.
350 * IllegalArgumentException if compute duration <0 or message size <0
354 final static native void taskCreate(Task task, String name,
355 double computeDuration,
357 throws JniException, NullPointerException, IllegalArgumentException;
360 * The natively implemented method to get the sender of a task.
362 * @param task The task (valid) to get the sender.
364 * @return The sender of the task.
366 * @exception InvalidTaskException is the specified task is not valid. A task
367 * is invalid if it is not binded with a native task.
369 * @see Task.getSender()
371 final static native Process taskGetSender(Task task) throws JniException;
374 * The natively implementd method to get the source of a task.
376 * @param task The task to get the source.
378 * @return The source of the task.
380 * @exception InvalidTaskException is the specified task is not valid. A task
381 * is invalid if it is not binded with a native task.
383 * @see Task.getSource()
385 final static native Host taskGetSource(Task task) throws JniException,
389 * The natively implemented method to get the name of the task.
391 * @param task The task to get the name.
393 * @return The name of the specified task.
395 * @exception InvalidTaskException is the specified task is not valid. A task
396 * is invalid if it is not binded with a native task.
398 * @see Task.getName()
400 final static native String taskGetName(Task task) throws JniException;
403 * The natively implemented method to cancel a task.
405 * @param task The task to cancel.
407 * @exception InvalidTaskException if the specified task is not valid. A task
408 * is invalid if it is not binded with a native task.
409 * MsgException if the cancelation failed.
411 * @see Task.cancel().
413 final static native void taskCancel(Task task) throws JniException,
417 * The natively implemented method to create a MSG parallel task.
419 * @param name The name of the parallel task.
420 * @param hosts The list of hosts implied by the parallel task.
421 * @param computeDurations The total number of operations that have to be performed
423 * @param messageSizes An array of doubles
425 * @see ParallelTask.create()
427 final static native void parallelTaskCreate(Task pTask, String name,
429 double[]computeDurations,
430 double[]messageSizes)
431 throws JniException, NullPointerException, IllegalArgumentException;
434 * The natively implemented method to get the computing amount of the task.
436 * @param task The task to get the computing amount.
438 * @return The computing amount of the specified task.
440 * @exception InvalidTaskException if the specified task is not valid. A task
441 * is invalid if it is not binded with a native task.
442 * MsgException if the cancelation failed.
444 * @see Task.getComputeDuration()
446 final static native double taskGetComputeDuration(Task task) throws
450 * The natively implemented method to get the remaining computation
452 * @param task The task to get the remaining computation.
454 * @return The remaining computation of the specified task.
456 * @exception InvalidTaskException if the specified task is not valid. A task
457 * is invalid if it is not binded with a native task.
458 * MsgException if the cancelation failed.
460 * @see Task.getRemainingDuration()
462 final static native double taskGetRemainingDuration(Task task) throws
466 * The natively implemented method to set the priority of a task.
468 * @param task The task to set the priority
470 * @param priority The new priority of the specified task.
472 * @exception InvalidTaskException if the specified task is not valid. A task
473 * is invalid if it is not binded with a native task.
474 * MsgException if the cancelation failed.
476 * @see Task.setPriority()
478 final static native void taskSetPriority(Task task,
479 double priority) throws
483 * The natively implemented method to destroy a MSG task.
485 * @param The task to destroy.
487 * @exception InvalidTaskException is the specified task is not valid. A task
488 * is invalid if it is not binded with a native task.
489 * MsgException if the destruction failed.
491 * @see Task.destroy()
493 final static native void taskDestroy(Task task) throws JniException,
497 * The natively implemented method to execute a MSG task.
499 * @param task The task to execute.
501 * @exception InvalidTaskException is the specified task is not valid. A task
502 * is invalid if it is not binded with a native task.
503 * MsgException if the destruction failed.
505 * @see Task.execute()
507 final static native void taskExecute(Task task) throws JniException,
511 /******************************************************************
512 * Task reception methods *
513 ******************************************************************/
516 * The natively implemented method to listen on the channel and wait for receiving a task with a timeout.
518 * @param channel The channel to listen.
519 * @param timeout The timeout of the listening.
520 * @param host The specific host from which we accept messages (or NULL for any).
522 * @return The task read from the channel.
524 * @exception MsgException if the listening operation failed.
526 * @see Channel.getWithTimeout()
529 final static native Task taskGet(int channel, double timeout,
530 Host host) throws JniException,
534 /******************************************************************
535 * Task methods relative with the alias *
536 ******************************************************************/
539 final static native void taskSend(String alias, Task task, double timeout)
540 throws JniException, NativeException;
543 final static native Task taskReceive(String alias, double timeout, Host host)
544 throws JniException, NativeException;
546 final static native int taskListenFrom(String alias)
547 throws JniException, NativeException;
550 final static native boolean taskListen(String alias)
553 final static native int taskListenFromHost(String alias, Host host)
559 * The natively implemented method to test whether there is a pending communication on the channel.
561 * @param channel The channel concerned by the operation.
563 * @return The method returns true if there is a pending communication on the specified
564 * channel. Otherwise the method returns false.
566 * @see Channel.hasPendingCommunication()
568 final static native boolean taskProbe(int channel) throws JniException;
571 * The natively implemented method to test whether there is a pending communication on a
572 * channel, and who sent it.
574 * @param The channel concerned by the operation.
576 * @return The method returns -1 if there is no pending communication and
577 * the PID of the process who sent it otherwise.
579 * @see Channel.getCummunicatingProcess()
581 final static native int taskGetCommunicatingProcess(int channel) throws
585 * The natively implemented method to get the number of tasks waiting to be received on a
586 * channel and sent by a host.
588 * @param channel The channel concerned by the operation.
590 * @param host The sender of the tasks.
592 * @return The number of tasks waiting to be received on a channel
593 * and sent by the specified host.
595 * @exception InvalidHostException if the specified host is not valid.
597 * @see Channel.getHostWaiting()
599 final static native int taskProbeHost(int channel,
600 Host host) throws JniException;
603 /******************************************************************
604 * Task emission methods *
605 ******************************************************************/
607 * The natively implemented method to put a task on the channel of an host.
609 * @param host The host on which to send the data
610 * @param channel The channel where to put the task.
611 * @param task The task to put.
612 * @param task Timeout (or <0 if none)
614 * @exception InvalidTaskException if the task is not valid.
615 * InvalidHostException if the host is not valid.
616 * MsgException if the operation failed.
619 final static native void hostPut(Host host, int channel, Task task,
620 double timeout) throws JniException,
625 * The natively implemented method to put a task on channel with a bounded transmition
628 * @param channel The channel where to put the task.
629 * @param task The task to put.
630 * @param host The host containing the channel.
631 * @param max_rate The bounded transmition rate.
633 * @exception InvalidTaskException if the task is not valid.
634 * InvalidHostException if the host is not valid.
635 * MsgException if the operation failed.
637 * @see Channel.putBounded()
639 final static native void hostPutBounded(Host host, int channel, Task task,
640 double max_rate) throws
641 JniException, NativeException;
644 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
647 * @param alias The alias of the mailbox.
648 * @param task The task to put.
649 * @param max_rate The bounded transmition rate.
651 * @exception InvalidTaskException if the task is not valid.
652 * InvalidHostException if the host is not valid.
653 * MsgException if the operation failed.
655 final static native void taskSendBounded(String alias, Task task, double maxrate)
656 throws JniException, NativeException;