Logo AND Algorithmique Numérique Distribuée

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