Logo AND Algorithmique Numérique Distribuée

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