Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1cb47da32e31e56d324ea5d0a9a4ed964dc77809
[simgrid.git] / src / java / simgrid / msg / MsgNative.java
1 /*
2  * simgrid.msg.Msg.java    1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
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 /* Contains all the native methods reloaded by Process, Host and Task.
15  *
16  * @author  Abdelmalek Cherier
17  * @author  Martin Quinson
18  * @since SimGrid 3.3
19  */
20 final class MsgNative {
21
22
23   final static native
24     void selectContextFactory(String name) throws NativeException;
25
26     /******************************************************************
27      * The natively implemented methods connected to the MSG Process  *
28      ******************************************************************/
29
30     /**
31      * The natively implemented method to create an MSG process.
32      *
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.
35      *
36      * @exception  simgrid.msg.JniException if JNI stuff goes wrong.
37      *
38      * @see  Process constructors.
39      */
40   final static native
41     void processCreate(Process process, Host host) throws JniException;
42
43     /**
44      * The natively implemented method to kill all the process of the simulation.
45      *
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
48      *                        created process.
49      *
50      * @return                The function returns the PID of the next created process.
51      */
52   final static native int processKillAll(int resetPID);
53
54     /**
55      * The natively implemented method to suspend an MSG process.
56      *
57      * @param process        The valid (binded with a native process) java process to suspend.
58      *
59      * @exception            JniException if something goes wrong with JNI
60      *                       NativeException if the SimGrid native code failed.
61      *
62      * @see                 Process.pause()
63      */
64   final static native void processSuspend(Process process)
65   throws JniException, NativeException;
66
67     /**
68      * The natively implemented method to kill a MSG process.
69      *
70      * @param process        The valid (binded with a native process) java process to kill.
71      *
72      * @see                 Process.kill()
73      */
74   final static native void processKill(Process process)
75   throws JniException;
76
77     /**
78      * The natively implemented method to resume a suspended MSG process.
79      *
80      * @param process        The valid (binded with a native process) java process to resume.
81      *
82      * @exception            JniException if something goes wrong with JNI
83      *                       NativeException if the SimGrid native code failed.
84      *
85      * @see                 Process.restart()
86      */
87   final static native void processResume(Process process)
88   throws JniException, NativeException;
89
90     /**
91      * The natively implemented method to test if MSG process is suspended.
92      *
93      * @param process        The valid (binded with a native process) java process to test.
94      *
95      * @return                If the process is suspended the method retuns true. Otherwise the
96      *                        method returns false.
97      *
98      * @exception            JniException if something goes wrong with JNI
99      *
100      * @see                 Process.isSuspended()
101      */
102   final static native boolean processIsSuspended(Process process) throws
103     JniException;
104
105     /**
106      * The natively implemented method to get the host of a MSG process.
107      *
108      * @param process        The valid (binded with a native process) java process to get the host.
109      *
110      * @return                The method returns the host where the process is running.
111      *
112      * @exception            JniException if something goes wrong with JNI
113      *                       NativeException if the SimGrid native code failed.
114      *
115      * @see                 Process.getHost()
116      */
117   final static native Host processGetHost(Process process)
118   throws JniException, NativeException;
119
120     /**
121      * The natively implemented method to get a MSG process from his PID.
122      *
123      * @param PID            The PID of the process to get.
124      *
125      * @return                The process with the specified PID.
126      *
127      * @exception            NativeException if the SimGrid native code failed.
128      *
129      * @see                 Process.getFromPID()
130      */
131   final static native Process processFromPID(int PID) throws NativeException;
132
133     /**
134      * The natively implemented method to get the PID of a MSG process.
135      *
136      * @param process        The valid (binded with a native process) java process to get the PID.
137      *
138      * @return                The PID of the specified process.
139      *
140      * @exception            NativeException if the SimGrid native code failed.
141      *
142      * @see                 Process.getPID()
143      */
144   final static native int processGetPID(Process process) throws
145     NativeException;
146
147     /**
148      * The natively implemented method to get the PPID of a MSG process.
149      *
150      * @param process        The valid (binded with a native process) java process to get the PID.
151      *
152      * @return                The PPID of the specified process.
153      *
154      * @exception            NativeException if the SimGrid native code failed.
155      *
156      * @see                 Process.getPPID()
157      */
158   final static native int processGetPPID(Process process) throws
159     NativeException;
160
161     /**
162      * The natively implemented method to get the current running process.
163      *
164      * @return             The current process.
165      *
166      * @exception            NativeException if the SimGrid native code failed.
167
168      * @see                Process.currentProcess()
169      */
170   final static native Process processSelf() throws NativeException;
171
172     /**
173      * The natively implemented method to get the current running process PID.
174      *
175      * @return                The PID of the current process.
176      *
177      * @see                Process.currentProcessPID()
178      */
179   final static native int processSelfPID();
180
181     /**
182      * The natively implemented method to get the current running process PPID.
183      *
184      * @return                The PPID of the current process.
185      *
186      * @see                Process.currentProcessPPID()
187      */
188   final static native int processSelfPPID();
189
190     /**
191      * The natively implemented method to migrate a process from his currnet host to a new host.
192      *
193      * @param process        The (valid) process to migrate.
194      * @param host            A (valid) host where move the process.
195      *
196      * @exception            JniException if something goes wrong with JNI
197      *                       NativeException if the SimGrid native code failed.
198      *
199      * @see                Process.migrate()
200      * @see                Host.getByName()
201      */
202   final static native void processChangeHost(Process process, Host host)
203   throws JniException, NativeException;
204
205     /**
206      * The natively implemented native to request the current process to sleep 
207      * until time seconds have elapsed.
208      *
209      * @param seconds        The time the current process must sleep.
210      *
211      * @exception            NativeException if the SimGrid native code failed.
212      *
213      * @see                 Process.waitFor()
214      */
215   final static native void processWaitFor(double seconds) throws
216     NativeException;
217
218     /**
219      * The natively implemented native method to exit a process.
220      *
221      * @exception            JniException if something goes wrong with JNI
222      *
223      * @see                Process.exit()
224      */
225   final static native void processExit(Process process) throws JniException;
226
227
228     /******************************************************************
229      * The natively implemented methods connected to the MSG host     *
230      ******************************************************************/
231
232     /**
233      * The natively implemented method to get an host from his name.
234      *
235      * @param name            The name of the host to get.
236      *
237      * @return                The host having the specified name.
238      *
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.
242      *
243      * @see                Host.getByName()
244      */
245   final static native Host hostGetByName(String name)
246   throws JniException, HostNotFoundException, NativeException;
247
248     /**
249      * The natively implemented method to get the name of an MSG host.
250      *
251      * @param host            The host (valid) to get the name.
252      *
253      * @return                The name of the specified host.
254      *
255      * @exception            JniException if something goes wrong with JNI
256      *
257      * @see                Host.getName()
258      */
259   final static native String hostGetName(Host host) throws JniException;
260
261     /**
262      * The natively implemented method to get the number of hosts of the simulation.
263      *
264      * @return                The number of hosts of the simulation.
265      *
266      * @see                Host.getNumber()
267      */
268   final static native int hostGetNumber();
269
270     /**
271      * The natively implemented method to get the host of the current runing process.
272      *
273      * @return                The host of the current running process.
274      *
275      * @exception            JniException if something goes wrong with JNI
276      *
277      * @see                Host.currentHost()
278      */
279   final static native Host hostSelf() throws JniException;
280
281     /**
282      * The natively implemented method to get the speed of a MSG host.
283      *
284      * @param host            The host to get the host.
285      *
286      * @return                The speed of the specified host.
287      *
288      * @exception            JniException if something goes wrong with JNI
289      *
290      * @see                Host.getSpeed()
291      */
292
293   final static native double hostGetSpeed(Host host) throws JniException;
294
295     /**
296      * The natively implemented native method to test if an host is avail.
297      *
298      * @param host            The host to test.
299      *
300      * @return                If the host is avail the method returns true. 
301      *                        Otherwise the method returns false.
302      *
303      * @exception            JniException if something goes wrong with JNI
304      *
305      * @see                Host.isAvail()
306      */
307   final static native boolean hostIsAvail(Host host) throws JniException;
308
309     /**
310      * The natively implemented native method to get all the hosts of the simulation.
311      *
312      * @exception            JniException if something goes wrong with JNI
313      *
314      * @return                A array which contains all the hosts of simulation.
315      */
316
317   final static native Host[] allHosts() throws JniException;
318
319     /**
320      * The natively implemented native method to get the number of running tasks on a host.
321      *
322      * @param                The host concerned by the operation.
323      *
324      * @return                The number of running tasks.
325      *
326      * @exception            JniException if something goes wrong with JNI
327      *
328      */
329   final static native int hostGetLoad(Host host) throws JniException;
330
331     /******************************************************************
332      * The natively implemented methods connected to the MSG task     *
333      ******************************************************************/
334
335     /**
336      * The natively implemented method to create a MSG task.
337      *
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.
347      *
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
351      *
352      * @see                    Task.create()
353      */
354   final static native void taskCreate(Task task, String name,
355                                       double computeDuration,
356                                       double messageSize)
357   throws JniException, NullPointerException, IllegalArgumentException;
358
359     /**
360      * The natively implemented method to get the sender of a task.
361      *
362      * @param    task            The task (valid) to get the sender.
363      *
364      * @return                The sender of the task.
365      *
366      * @exception                InvalidTaskException is the specified task is not valid. A task
367      *                        is invalid if it is not binded with a native task.
368      *
369      * @see                    Task.getSender()
370      */
371   final static native Process taskGetSender(Task task) throws JniException;
372
373     /**
374      * The natively implementd method to get the source of a task.
375      *
376      * @param task            The task to get the source.
377      *
378      * @return                The source of the task.
379      *
380      * @exception                InvalidTaskException is the specified task is not valid. A task
381      *                        is invalid if it is not binded with a native task.
382      *
383      * @see                    Task.getSource()
384      */
385   final static native Host taskGetSource(Task task) throws JniException,
386     NativeException;
387
388     /**
389      * The natively implemented method to get the name of the task.
390      *
391      * @param task            The task to get the name.
392      *
393      * @return                 The name of the specified task.
394      *
395      * @exception                InvalidTaskException is the specified task is not valid. A task
396      *                        is invalid if it is not binded with a native task.
397      *
398      * @see                    Task.getName()
399      */
400   final static native String taskGetName(Task task) throws JniException;
401
402     /**
403      * The natively implemented method to cancel a task.
404      *
405      * @param task            The task to cancel.
406      *
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.
410      *
411      * @see                    Task.cancel().
412      */
413   final static native void taskCancel(Task task) throws JniException,
414     NativeException;
415
416     /**
417      * The natively implemented method to create a MSG parallel task.
418      *
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
422      *                            on the hosts.
423      * @param messageSizes        An array of doubles
424      *
425      * @see                        ParallelTask.create()
426      */
427   final static native void parallelTaskCreate(Task pTask, String name,
428                                               Host[]hosts,
429                                               double[]computeDurations,
430                                               double[]messageSizes)
431   throws JniException, NullPointerException, IllegalArgumentException;
432
433     /**
434      * The natively implemented method to get the computing amount of the task.
435      *
436      * @param task            The task to get the computing amount.
437      *
438      * @return                The computing amount of the specified task.
439      *
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.
443      *
444      * @see                    Task.getComputeDuration()
445      */
446   final static native double taskGetComputeDuration(Task task) throws
447     JniException;
448
449     /**
450      * The natively implemented method to get the remaining computation
451      *
452      * @param task            The task to get the remaining computation.
453      *
454      * @return                The remaining computation of the specified task.
455      *
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.
459      *
460      * @see                    Task.getRemainingDuration()
461      */
462   final static native double taskGetRemainingDuration(Task task) throws
463     JniException;
464
465     /**
466      * The natively implemented method to set the priority of a task.
467      *
468      * @param task            The task to set the priority
469      *
470      * @param priority        The new priority of the specified task.
471      *
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.
475      *
476      * @see                    Task.setPriority()
477      */
478   final static native void taskSetPriority(Task task,
479                                            double priority) throws
480     JniException;
481
482     /**
483      * The natively implemented method to destroy a MSG task.
484      *
485      * @param                    The task to destroy.
486      *
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.
490      *
491      * @see                    Task.destroy()
492      */
493   final static native void taskDestroy(Task task) throws JniException,
494     NativeException;
495
496     /**
497      * The natively implemented method to execute a MSG task.
498      *
499      * @param task            The task to execute.
500      *
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.
504      *
505      * @see                    Task.execute()
506      */
507   final static native void taskExecute(Task task) throws JniException,
508     NativeException;
509
510
511     /******************************************************************
512      * Task reception methods                                         *
513      ******************************************************************/
514
515     /**
516      * The natively implemented method to listen on the channel and wait for receiving a task with a timeout.
517      *
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).
521      *
522      * @return         The task read from the channel.
523      *
524      * @exception                MsgException if the listening operation failed.
525      *
526      * @see                    Channel.getWithTimeout()
527      *
528      */
529   final static native Task taskGet(int channel, double timeout,
530                                    Host host) throws JniException,
531     NativeException;
532     
533   
534   /******************************************************************
535      * Task methods relative with the alias                           *
536      ******************************************************************/
537   
538   
539   final static native void taskSend(String alias, Task task, double timeout) 
540   throws JniException, NativeException;
541   
542   
543   final static native Task taskReceive(String alias, double timeout, Host host) 
544   throws JniException, NativeException;
545   
546   final static native int taskListenFrom(String alias) 
547   throws JniException, NativeException;
548   
549   
550   final static native boolean taskListen(String alias) 
551   throws JniException;
552   
553   final static native int taskListenFromHost(String alias, Host host) 
554   throws JniException;
555     
556
557
558     /**
559      * The natively implemented method to test whether there is a pending communication on the channel.
560      *
561      * @param channel            The channel concerned by the operation.
562      *
563      * @return                The method returns true if there is a pending communication on the specified
564      *                        channel. Otherwise the method returns false.
565      *
566      * @see                    Channel.hasPendingCommunication()
567      */
568   final static native boolean taskProbe(int channel) throws JniException;
569
570     /**
571      * The natively implemented method to test whether there is a pending communication on a 
572      * channel, and who sent it.
573      *
574      * @param                    The channel concerned by the operation.
575      *
576      * @return                The method returns -1 if there is no pending communication and 
577      *                        the PID of the process who sent it otherwise.
578      *
579      * @see                    Channel.getCummunicatingProcess()
580      */
581   final static native int taskGetCommunicatingProcess(int channel) throws
582     JniException;
583
584     /**
585      * The natively implemented method to get the number of tasks waiting to be received on a
586      * channel and sent by a host.
587      *
588      * @param channel            The channel concerned by the operation.
589      *
590      * @param host            The sender of the tasks.
591      *
592      * @return                The number of tasks waiting to be received on a channel
593      *                         and sent by the specified host.
594      *
595      * @exception                InvalidHostException if the specified host is not valid.
596      *
597      * @see                    Channel.getHostWaiting()
598      */
599   final static native int taskProbeHost(int channel,
600                                         Host host) throws JniException;
601                                         
602
603     /******************************************************************
604      * Task emission methods                                          *
605      ******************************************************************/
606     /**
607      * The natively implemented method to put a task on the channel of an host.
608      *
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)
613      *
614      * @exception                InvalidTaskException if the task is not valid.
615      *                        InvalidHostException if the host is not valid.
616      *                        MsgException if the operation failed.
617      *
618      */
619   final static native void hostPut(Host host, int channel, Task task,
620                                    double timeout) throws JniException,
621     NativeException;
622
623
624     /**
625      * The natively implemented method to put a task on channel with a bounded transmition
626      * rate.
627      * 
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.
632      *
633      * @exception                InvalidTaskException if the task is not valid.
634      *                        InvalidHostException if the host is not valid.
635      *                        MsgException if the operation failed.
636      *
637      * @see                    Channel.putBounded()
638      */
639   final static native void hostPutBounded(Host host, int channel, Task task,
640                                           double max_rate) throws
641     JniException, NativeException;
642     
643    /**
644      * The natively implemented method to send a task in a mailbox associated with an alias,  with a bounded transmition
645      * rate.
646      * 
647      * @param alias            The alias of the mailbox.
648      * @param task            The task to put.
649      * @param max_rate        The bounded transmition rate.
650      *
651      * @exception                InvalidTaskException if the task is not valid.
652      *                        InvalidHostException if the host is not valid.
653      *                        MsgException if the operation failed.
654      */ 
655   final static native void taskSendBounded(String alias, Task task, double maxrate) 
656   throws JniException, NativeException;
657
658 }