Logo AND Algorithmique Numérique Distribuée

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