Logo AND Algorithmique Numérique Distribuée

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