Logo AND Algorithmique Numérique Distribuée

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