Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename TimeoutFailureException to TimeoutException
[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 /* FIXME: split into internal classes of Msg, Task, Host etc. */
15
16 /**
17  *  Contains all the native methods related to Process, Host and Task.
18  */
19 final class MsgNative {
20
21         final static native
22         void selectContextFactory(String name) throws NativeException;
23
24         /******************************************************************
25          * The natively implemented methods connected to the MSG Process  *
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          * @see  Process constructors.
34          */
35         final static native
36         void processCreate(Process process, Host host);
37
38         /**
39          * The natively implemented method to kill all the process of the simulation.
40          *
41          * @param resetPID        Should we reset the PID numbers. A negative number means no reset
42          *                        and a positive number will be used to set the PID of the next newly
43          *                        created process.
44          *
45          * @return                The function returns the PID of the next created process.
46          */
47         final static native int processKillAll(int resetPID);
48
49         /**
50          * The natively implemented method to suspend an MSG process.
51          *
52          * @param process        The valid (binded with a native process) java process to suspend.
53          *
54          * @exception            NativeException if the SimGrid native code failed.
55          *
56          * @see                 Process.pause()
57          */
58         final static native void processSuspend(Process process) throws NativeException;
59
60         /**
61          * The natively implemented method to kill a MSG process.
62          *
63          * @param process        The valid (binded with a native process) java process to kill.
64          *
65          * @see                 Process.kill()
66          */
67         final static native void processKill(Process process);
68
69         /**
70          * The natively implemented method to resume a suspended MSG process.
71          *
72          * @param process        The valid (binded with a native process) java process to resume.
73          *
74          * @exception            NativeException if the SimGrid native code failed.
75          *
76          * @see                 Process.restart()
77          */
78         final static native void processResume(Process process) throws NativeException;
79
80         /**
81          * The natively implemented method to test if MSG process is suspended.
82          *
83          * @param process        The valid (binded with a native process) java process to test.
84          *
85          * @return                If the process is suspended the method retuns true. Otherwise the
86          *                        method returns false.
87          *
88          * @see                 Process.isSuspended()
89          */
90         final static native boolean processIsSuspended(Process process);
91
92         /**
93          * The natively implemented method to get the host of a MSG process.
94          *
95          * @param process        The valid (binded with a native process) java process to get the host.
96          *
97          * @return                The method returns the host where the process is running.
98          *
99          * @exception            NativeException if the SimGrid native code failed.
100          *
101          * @see                 Process.getHost()
102          */
103         final static native Host processGetHost(Process process) throws NativeException;
104
105         /**
106          * The natively implemented method to get a MSG process from his PID.
107          *
108          * @param PID            The PID of the process to get.
109          *
110          * @return                The process with the specified PID.
111          *
112          * @exception            NativeException if the SimGrid native code failed.
113          *
114          * @see                 Process.getFromPID()
115          */
116         final static native Process processFromPID(int PID) throws NativeException;
117
118         /**
119          * The natively implemented method to get the PID of a MSG process.
120          *
121          * @param process        The valid (binded with a native process) java process to get the PID.
122          *
123          * @return                The PID of the specified process.
124          *
125          * @exception            NativeException if the SimGrid native code failed.
126          *
127          * @see                 Process.getPID()
128          */
129         final static native int processGetPID(Process process) throws NativeException;
130
131         /**
132          * The natively implemented method to get the PPID of a MSG process.
133          *
134          * @param process        The valid (binded with a native process) java process to get the PID.
135          *
136          * @return                The PPID of the specified process.
137          *
138          * @exception            NativeException if the SimGrid native code failed.
139          *
140          * @see                 Process.getPPID()
141          */
142         final static native int processGetPPID(Process process) throws NativeException;
143
144         /**
145          * The natively implemented method to get the current running process.
146          *
147          * @return             The current process.
148          *
149          * @exception            NativeException if the SimGrid native code failed.
150
151          * @see                Process.currentProcess()
152          */
153         final static native Process processSelf() throws NativeException;
154
155         /**
156          * The natively implemented method to migrate a process from his currnet host to a new host.
157          *
158          * @param process        The (valid) process to migrate.
159          * @param host            A (valid) host where move the process.
160          *
161          * @exception            NativeException if the SimGrid native code failed.
162          *
163          * @see                Process.migrate()
164          * @see                Host.getByName()
165          */
166         final static native void processChangeHost(Process process, Host host) throws NativeException;
167
168         /**
169          * The natively implemented native to request the current process to sleep 
170          * until time seconds have elapsed.
171          *
172          * @param seconds        The time the current process must sleep.
173          *
174          * @exception            NativeException if the SimGrid native code failed.
175          *
176          * @see                 Process.waitFor()
177          */
178         final static native void processWaitFor(double seconds) throws NativeException;
179
180         /**
181          * The natively implemented native method to exit a process.
182          *
183          * @see                Process.exit()
184          */
185         final static native void processExit(Process process);
186
187
188         /******************************************************************
189          * The natively implemented methods connected to the MSG host     *
190          ******************************************************************/
191
192         /**
193          * The natively implemented method to get an host from his name.
194          *
195          * @param name            The name of the host to get.
196          *
197          * @return                The host having the specified name.
198          *
199          * @exception            HostNotFoundException if there is no such host
200          *                       NativeException if the SimGrid native code failed.
201          *
202          * @see                Host.getByName()
203          */
204         final static native Host hostGetByName(String name) throws HostNotFoundException, NativeException;
205
206         /**
207          * The natively implemented method to get the name of an MSG host.
208          *
209          * @param host            The host (valid) to get the name.
210          *
211          * @return                The name of the specified host.
212          *
213          * @see                Host.getName()
214          */
215         final static native String hostGetName(Host host);
216
217         /**
218          * The natively implemented method to get the number of hosts of the simulation.
219          *
220          * @return                The number of hosts of the simulation.
221          *
222          * @see                Host.getNumber()
223          */
224         final static native int hostGetCount();
225
226         /**
227          * The natively implemented method to get the host of the current runing process.
228          *
229          * @return                The host of the current running process.
230          *
231          * @see                Host.currentHost()
232          */
233         final static native Host hostSelf();
234
235         /**
236          * The natively implemented method to get the speed of a MSG host.
237          *
238          * @param host            The host to get the host.
239          *
240          * @return                The speed of the specified host.
241          *
242          * @see                Host.getSpeed()
243          */
244
245         final static native double hostGetSpeed(Host host);
246
247         /**
248          * The natively implemented native method to test if an host is avail.
249          *
250          * @param host            The host to test.
251          *
252          * @return                If the host is avail the method returns true. 
253          *                        Otherwise the method returns false.
254          *
255          * @see                Host.isAvail()
256          */
257         final static native boolean hostIsAvail(Host host);
258
259         /**
260          * The natively implemented native method to get all the hosts of the simulation.
261          *
262          * @return                A array which contains all the hosts of simulation.
263          */
264
265         final static native Host[] allHosts();
266
267         /**
268          * The natively implemented native method to get the number of running tasks on a host.
269          *
270          * @param                The host concerned by the operation.
271          *
272          * @return                The number of running tasks.
273          */
274         final static native int hostGetLoad(Host host);
275
276         /******************************************************************
277          * The natively implemented methods connected to the MSG task     *
278          ******************************************************************/
279
280         /**
281          * The natively implemented method to create a MSG task.
282          *
283          * @param name            The name of th task.
284          * @param computeDuration    A value of the processing amount (in flop) needed 
285          *                        to process the task. If 0, then it cannot be executed
286          *                        with the execute() method. This value has to be >= 0.
287          * @param messageSize        A value of amount of data (in bytes) needed to transfert 
288          *                        this task. If 0, then it cannot be transfered this task. 
289          *                        If 0, then it cannot be transfered with the get() and put() 
290          *                        methods. This value has to be >= 0.
291          * @param task            The java task object to bind with the native task to create.
292          *
293          * @exception             IllegalArgumentException if compute duration <0 or message size <0
294          *
295          * @see                    Task.create()
296          */
297         final static native void taskCreate(Task task, String name,
298                         double computeDuration,
299                         double messageSize)
300         throws IllegalArgumentException;
301
302         /**
303          * The natively implemented method to get the sender of a task.
304          *
305          * @param    task            The task (valid) to get the sender.
306          *
307          * @return                The sender of the task.
308          *
309          * @see                    Task.getSender()
310          */
311         final static native Process taskGetSender(Task task);
312
313         /**
314          * The natively implementd method to get the source of a task.
315          *
316          * @param task            The task to get the source.
317          *
318          * @return                The source of the task.
319          *
320          * @exception            NativeException if the SimGrid native code failed.
321          *
322          * @see                    Task.getSource()
323          */
324         final static native Host taskGetSource(Task task) throws NativeException;
325
326         /**
327          * The natively implemented method to get the name of the task.
328          *
329          * @param task            The task to get the name.
330          *
331          * @return                 The name of the specified task.
332          *
333          * @see                    Task.getName()
334          */
335         final static native String taskGetName(Task task);
336
337         /**
338          * The natively implemented method to cancel a task.
339          *
340          * @param task            The task to cancel.
341          *
342          * @exception             NativeException if the cancellation failed.
343          *
344          * @see                    Task.cancel().
345          */
346         final static native void taskCancel(Task task) throws NativeException;
347
348         /**
349          * The natively implemented method to create a MSG parallel task.
350          *
351          * @param name                The name of the parallel task.
352          * @param hosts                The list of hosts implied by the parallel task.
353          * @param computeDurations    The total number of operations that have to be performed
354          *                            on the hosts.
355          * @param messageSizes        An array of doubles
356          *
357          * @see                        ParallelTask.create()
358          */
359         final static native void parallelTaskCreate(Task pTask, String name,
360                         Host[]hosts,
361                         double[]computeDurations,
362                         double[]messageSizes)
363         throws NullPointerException, IllegalArgumentException;
364
365         /**
366          * The natively implemented method to get the computing amount of the task.
367          *
368          * @param task            The task to get the computing amount.
369          *
370          * @return                The computing amount of the specified task.
371          *
372          * @see                    Task.getComputeDuration()
373          */
374         final static native double taskGetComputeDuration(Task task);
375
376         /**
377          * The natively implemented method to get the remaining computation
378          *
379          * @param task            The task to get the remaining computation.
380          *
381          * @return                The remaining computation of the specified task.
382          *
383          * @see                    Task.getRemainingDuration()
384          */
385         final static native double taskGetRemainingDuration(Task task);
386
387         /**
388          * The natively implemented method to set the priority of a task.
389          *
390          * @param task            The task to set the priority
391          *
392          * @param priority        The new priority of the specified task.
393          *
394          * @see                    Task.setPriority()
395          */
396         final static native void taskSetPriority(Task task, double priority);
397
398         /**
399          * The natively implemented method to destroy a MSG task.
400          *
401          * @param                    The task to destroy.
402          *
403          * @exception             NativeException on error in the C world
404          *
405          * @see                    Task.destroy()
406          */
407         final static native void taskDestroy(Task task) throws NativeException;
408
409         /**
410          * The natively implemented method to execute a MSG task.
411          *
412          * @param task            The task to execute.
413          *
414          * @exception             NativeException on error in the C world
415          *
416          * @see                    Task.execute()
417          */
418         final static native void taskExecute(Task task) throws NativeException;
419
420         /* ****************************************************************
421          * Communication methods thru mailboxes                           *
422          **************************************************************** */
423
424         final static native void taskSend(String alias, Task task, double timeout) throws NativeException,TransferFailureException,HostFailureException,TimeoutException;
425         final static native Task taskReceive(String alias, double timeout, Host host) throws NativeException;
426         final static native int taskListenFrom(String alias) throws NativeException;
427         final static native boolean taskListen(String alias);
428         final static native int taskListenFromHost(String alias, Host host);
429
430         /* ***************************************************************
431          * Task sending methods                                          *
432          *************************************************************** */
433
434         /**
435          * The natively implemented method to send a task in a mailbox associated with an alias,  with a bounded transmition
436          * rate.
437          * 
438          * @param alias            The alias of the mailbox.
439          * @param task            The task to put.
440          * @param max_rate        The bounded transmition rate.
441          *
442          * @exception             NativeException on error in the C world
443          */ 
444         final static native void taskSendBounded(String alias, Task task, double maxrate) throws NativeException;
445
446 }