Logo AND Algorithmique Numérique Distribuée

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