Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
67925846e74f86de82161a5c86ee3e0355594e89
[simgrid.git] / src / java / simgrid / msg / MsgNative.java
1 /*
2  * Contains all the native methods related to Process, Host and Task.
3  *
4  * Copyright 2006,2007,2010 The SimGrid Team           
5  * All right reserved. 
6  *
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. 
10  */
11
12 package simgrid.msg;
13
14 /**
15  *  Contains all the native methods related to Process, Host and Task.
16  */
17 final class MsgNative {
18
19
20         final static native
21         void selectContextFactory(String name) throws NativeException;
22
23         /******************************************************************
24          * The natively implemented methods connected to the MSG Process  *
25          ******************************************************************/
26
27         /**
28          * The natively implemented method to create an MSG process.
29          *
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.
32          *
33          * @exception  simgrid.msg.JniException if JNI stuff goes wrong.
34          *
35          * @see  Process constructors.
36          */
37         final static native
38         void processCreate(Process process, Host host) throws JniException;
39
40         /**
41          * The natively implemented method to kill all the process of the simulation.
42          *
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
45          *                        created process.
46          *
47          * @return                The function returns the PID of the next created process.
48          */
49         final static native int processKillAll(int resetPID);
50
51         /**
52          * The natively implemented method to suspend an MSG process.
53          *
54          * @param process        The valid (binded with a native process) java process to suspend.
55          *
56          * @exception            JniException if something goes wrong with JNI
57          *                       NativeException if the SimGrid native code failed.
58          *
59          * @see                 Process.pause()
60          */
61         final static native void processSuspend(Process process) throws JniException, NativeException;
62
63         /**
64          * The natively implemented method to kill a MSG process.
65          *
66          * @param process        The valid (binded with a native process) java process to kill.
67          *
68          * @see                 Process.kill()
69          */
70         final static native void processKill(Process process)
71         throws JniException;
72
73         /**
74          * The natively implemented method to resume a suspended MSG process.
75          *
76          * @param process        The valid (binded with a native process) java process to resume.
77          *
78          * @exception            JniException if something goes wrong with JNI
79          *                       NativeException if the SimGrid native code failed.
80          *
81          * @see                 Process.restart()
82          */
83         final static native void processResume(Process process)
84         throws JniException, NativeException;
85
86         /**
87          * The natively implemented method to test if MSG process is suspended.
88          *
89          * @param process        The valid (binded with a native process) java process to test.
90          *
91          * @return                If the process is suspended the method retuns true. Otherwise the
92          *                        method returns false.
93          *
94          * @exception            JniException if something goes wrong with JNI
95          *
96          * @see                 Process.isSuspended()
97          */
98         final static native boolean processIsSuspended(Process process) throws
99         JniException;
100
101         /**
102          * The natively implemented method to get the host of a MSG process.
103          *
104          * @param process        The valid (binded with a native process) java process to get the host.
105          *
106          * @return                The method returns the host where the process is running.
107          *
108          * @exception            JniException if something goes wrong with JNI
109          *                       NativeException if the SimGrid native code failed.
110          *
111          * @see                 Process.getHost()
112          */
113         final static native Host processGetHost(Process process)
114         throws JniException, NativeException;
115
116         /**
117          * The natively implemented method to get a MSG process from his PID.
118          *
119          * @param PID            The PID of the process to get.
120          *
121          * @return                The process with the specified PID.
122          *
123          * @exception            NativeException if the SimGrid native code failed.
124          *
125          * @see                 Process.getFromPID()
126          */
127         final static native Process processFromPID(int PID) throws NativeException;
128
129         /**
130          * The natively implemented method to get the PID of a MSG process.
131          *
132          * @param process        The valid (binded with a native process) java process to get the PID.
133          *
134          * @return                The PID of the specified process.
135          *
136          * @exception            NativeException if the SimGrid native code failed.
137          *
138          * @see                 Process.getPID()
139          */
140         final static native int processGetPID(Process process) throws
141         NativeException;
142
143         /**
144          * The natively implemented method to get the PPID of a MSG process.
145          *
146          * @param process        The valid (binded with a native process) java process to get the PID.
147          *
148          * @return                The PPID of the specified process.
149          *
150          * @exception            NativeException if the SimGrid native code failed.
151          *
152          * @see                 Process.getPPID()
153          */
154         final static native int processGetPPID(Process process) throws
155         NativeException;
156
157         /**
158          * The natively implemented method to get the current running process.
159          *
160          * @return             The current process.
161          *
162          * @exception            NativeException if the SimGrid native code failed.
163
164          * @see                Process.currentProcess()
165          */
166         final static native Process processSelf() throws NativeException;
167
168         /**
169          * The natively implemented method to get the current running process PID.
170          *
171          * @return                The PID of the current process.
172          *
173          * @see                Process.currentProcessPID()
174          */
175         final static native int processSelfPID();
176
177         /**
178          * The natively implemented method to get the current running process PPID.
179          *
180          * @return                The PPID of the current process.
181          *
182          * @see                Process.currentProcessPPID()
183          */
184         final static native int processSelfPPID();
185
186         /**
187          * The natively implemented method to migrate a process from his currnet host to a new host.
188          *
189          * @param process        The (valid) process to migrate.
190          * @param host            A (valid) host where move the process.
191          *
192          * @exception            JniException if something goes wrong with JNI
193          *                       NativeException if the SimGrid native code failed.
194          *
195          * @see                Process.migrate()
196          * @see                Host.getByName()
197          */
198         final static native void processChangeHost(Process process, Host host)
199         throws JniException, NativeException;
200
201         /**
202          * The natively implemented native to request the current process to sleep 
203          * until time seconds have elapsed.
204          *
205          * @param seconds        The time the current process must sleep.
206          *
207          * @exception            NativeException if the SimGrid native code failed.
208          *
209          * @see                 Process.waitFor()
210          */
211         final static native void processWaitFor(double seconds) throws
212         NativeException;
213
214         /**
215          * The natively implemented native method to exit a process.
216          *
217          * @exception            JniException if something goes wrong with JNI
218          *
219          * @see                Process.exit()
220          */
221         final static native void processExit(Process process) throws JniException;
222
223
224         /******************************************************************
225          * The natively implemented methods connected to the MSG host     *
226          ******************************************************************/
227
228         /**
229          * The natively implemented method to get an host from his name.
230          *
231          * @param name            The name of the host to get.
232          *
233          * @return                The host having the specified name.
234          *
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.
238          *
239          * @see                Host.getByName()
240          */
241         final static native Host hostGetByName(String name)
242         throws JniException, HostNotFoundException, NativeException;
243
244         /**
245          * The natively implemented method to get the name of an MSG host.
246          *
247          * @param host            The host (valid) to get the name.
248          *
249          * @return                The name of the specified host.
250          *
251          * @exception            JniException if something goes wrong with JNI
252          *
253          * @see                Host.getName()
254          */
255         final static native String hostGetName(Host host) throws JniException;
256
257         /**
258          * The natively implemented method to get the number of hosts of the simulation.
259          *
260          * @return                The number of hosts of the simulation.
261          *
262          * @see                Host.getNumber()
263          */
264         final static native int hostGetCount();
265
266         /**
267          * The natively implemented method to get the host of the current runing process.
268          *
269          * @return                The host of the current running process.
270          *
271          * @exception            JniException if something goes wrong with JNI
272          *
273          * @see                Host.currentHost()
274          */
275         final static native Host hostSelf() throws JniException;
276
277         /**
278          * The natively implemented method to get the speed of a MSG host.
279          *
280          * @param host            The host to get the host.
281          *
282          * @return                The speed of the specified host.
283          *
284          * @exception            JniException if something goes wrong with JNI
285          *
286          * @see                Host.getSpeed()
287          */
288
289         final static native double hostGetSpeed(Host host) throws JniException;
290
291         /**
292          * The natively implemented native method to test if an host is avail.
293          *
294          * @param host            The host to test.
295          *
296          * @return                If the host is avail the method returns true. 
297          *                        Otherwise the method returns false.
298          *
299          * @exception            JniException if something goes wrong with JNI
300          *
301          * @see                Host.isAvail()
302          */
303         final static native boolean hostIsAvail(Host host) throws JniException;
304
305         /**
306          * The natively implemented native method to get all the hosts of the simulation.
307          *
308          * @exception            JniException if something goes wrong with JNI
309          *
310          * @return                A array which contains all the hosts of simulation.
311          */
312
313         final static native Host[] allHosts() throws JniException;
314
315         /**
316          * The natively implemented native method to get the number of running tasks on a host.
317          *
318          * @param                The host concerned by the operation.
319          *
320          * @return                The number of running tasks.
321          *
322          * @exception            JniException if something goes wrong with JNI
323          *
324          */
325         final static native int hostGetLoad(Host host) throws JniException;
326
327         /******************************************************************
328          * The natively implemented methods connected to the MSG task     *
329          ******************************************************************/
330
331         /**
332          * The natively implemented method to create a MSG task.
333          *
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.
343          *
344          * @exception             JniException if something goes wrong with JNI
345          *                        IllegalArgumentException if compute duration <0 or message size <0
346          *
347          * @see                    Task.create()
348          */
349         final static native void taskCreate(Task task, String name,
350                         double computeDuration,
351                         double messageSize)
352         throws JniException, IllegalArgumentException;
353
354         /**
355          * The natively implemented method to get the sender of a task.
356          *
357          * @param    task            The task (valid) to get the sender.
358          *
359          * @return                The sender of the task.
360          *
361          * @exception                InvalidTaskException is the specified task is not valid. A task
362          *                        is invalid if it is not binded with a native task.
363          *
364          * @see                    Task.getSender()
365          */
366         final static native Process taskGetSender(Task task) throws JniException;
367
368         /**
369          * The natively implementd method to get the source of a task.
370          *
371          * @param task            The task to get the source.
372          *
373          * @return                The source of the task.
374          *
375          * @exception                InvalidTaskException is the specified task is not valid. A task
376          *                        is invalid if it is not binded with a native task.
377          *
378          * @see                    Task.getSource()
379          */
380         final static native Host taskGetSource(Task task) throws JniException,
381         NativeException;
382
383         /**
384          * The natively implemented method to get the name of the task.
385          *
386          * @param task            The task to get the name.
387          *
388          * @return                 The name of the specified task.
389          *
390          * @exception                InvalidTaskException is the specified task is not valid. A task
391          *                        is invalid if it is not binded with a native task.
392          *
393          * @see                    Task.getName()
394          */
395         final static native String taskGetName(Task task) throws JniException;
396
397         /**
398          * The natively implemented method to cancel a task.
399          *
400          * @param task            The task to cancel.
401          *
402          * @exception                InvalidTaskException if the specified task is not valid. A task
403          *                        is invalid if it is not binded with a native task.
404          *                        MsgException if the cancelation failed.
405          *
406          * @see                    Task.cancel().
407          */
408         final static native void taskCancel(Task task) throws JniException,
409         NativeException;
410
411         /**
412          * The natively implemented method to create a MSG parallel task.
413          *
414          * @param name                The name of the parallel task.
415          * @param hosts                The list of hosts implied by the parallel task.
416          * @param computeDurations    The total number of operations that have to be performed
417          *                            on the hosts.
418          * @param messageSizes        An array of doubles
419          *
420          * @see                        ParallelTask.create()
421          */
422         final static native void parallelTaskCreate(Task pTask, String name,
423                         Host[]hosts,
424                         double[]computeDurations,
425                         double[]messageSizes)
426         throws JniException, NullPointerException, IllegalArgumentException;
427
428         /**
429          * The natively implemented method to get the computing amount of the task.
430          *
431          * @param task            The task to get the computing amount.
432          *
433          * @return                The computing amount of the specified task.
434          *
435          * @exception                InvalidTaskException if the specified task is not valid. A task
436          *                        is invalid if it is not binded with a native task.
437          *                        MsgException if the cancelation failed.
438          *
439          * @see                    Task.getComputeDuration()
440          */
441         final static native double taskGetComputeDuration(Task task) throws
442         JniException;
443
444         /**
445          * The natively implemented method to get the remaining computation
446          *
447          * @param task            The task to get the remaining computation.
448          *
449          * @return                The remaining computation of the specified task.
450          *
451          * @exception                InvalidTaskException if the specified task is not valid. A task
452          *                        is invalid if it is not binded with a native task.
453          *                        MsgException if the cancelation failed.
454          *
455          * @see                    Task.getRemainingDuration()
456          */
457         final static native double taskGetRemainingDuration(Task task) throws
458         JniException;
459
460         /**
461          * The natively implemented method to set the priority of a task.
462          *
463          * @param task            The task to set the priority
464          *
465          * @param priority        The new priority of the specified task.
466          *
467          * @exception                InvalidTaskException if the specified task is not valid. A task
468          *                        is invalid if it is not binded with a native task.
469          *                        MsgException if the cancelation failed.
470          *
471          * @see                    Task.setPriority()
472          */
473         final static native void taskSetPriority(Task task,
474                         double priority) throws
475                         JniException;
476
477         /**
478          * The natively implemented method to destroy a MSG task.
479          *
480          * @param                    The task to destroy.
481          *
482          * @exception                InvalidTaskException is the specified task is not valid. A task
483          *                        is invalid if it is not binded with a native task.
484          *                        MsgException if the destruction failed.
485          *
486          * @see                    Task.destroy()
487          */
488         final static native void taskDestroy(Task task) throws JniException,
489         NativeException;
490
491         /**
492          * The natively implemented method to execute a MSG task.
493          *
494          * @param task            The task to execute.
495          *
496          * @exception                InvalidTaskException is the specified task is not valid. A task
497          *                        is invalid if it is not binded with a native task.
498          *                        MsgException if the destruction failed.
499          *
500          * @see                    Task.execute()
501          */
502         final static native void taskExecute(Task task) throws JniException,
503         NativeException;
504
505
506
507         /* ****************************************************************
508          * Communication methods thru mailboxes                           *
509          **************************************************************** */
510
511
512         final static native void taskSend(String alias, Task task, double timeout) 
513         throws JniException, NativeException;
514
515
516         final static native Task taskReceive(String alias, double timeout, Host host) 
517         throws JniException, NativeException;
518
519         final static native int taskListenFrom(String alias) 
520         throws JniException, NativeException;
521
522
523         final static native boolean taskListen(String alias) 
524         throws JniException;
525
526         final static native int taskListenFromHost(String alias, Host host) 
527         throws JniException;
528
529         /* ***************************************************************
530          * Task sending methods                                          *
531          *************************************************************** */
532
533         /**
534          * The natively implemented method to send a task in a mailbox associated with an alias,  with a bounded transmition
535          * rate.
536          * 
537          * @param alias            The alias of the mailbox.
538          * @param task            The task to put.
539          * @param max_rate        The bounded transmition rate.
540          *
541          * @exception                InvalidTaskException if the task is not valid.
542          *                        InvalidHostException if the host is not valid.
543          *                        MsgException if the operation failed.
544          */ 
545         final static native void taskSendBounded(String alias, Task task, double maxrate) 
546         throws JniException, NativeException;
547
548 }