Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This commit concerned the reimplementation of the xbt context switch mechanism.
[simgrid.git] / src / java / simgrid / msg / Msg.java
1 /*
2  * simgrid.msg.Msg.java    1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
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 import org.xml.sax.*;
14
15 /** 
16  * MSG was the first distributed programming environment 
17  * provided within SimGrid. While almost realistic, it 
18  * remains quite simple.
19  * This class contains all the declaration of the natives methods
20  * of the MSG API.
21  * All of these methods are statics. You can't directly use these methods
22  * but it is recommanded to use the classes Process, Host, Task and ParallelTask
23  * of the package to build your application.
24  *
25  * @author  Abdelmalek Cherier
26  * @author  Martin Quinson
27  * @version 1.00, 07/05/01
28  * @see Host
29  * @see Process
30  * @see Task
31  * @see ParallelTask
32  * @since SimGrid 3.3
33  * @since JDK1.5011 
34  */
35 public final class Msg {
36     /**
37      * The natively implemented method to get the last error code of the simulation.
38      *
39      * @return     The last error code of the simulation.
40      */
41     final static native int getErrCode();
42     
43     /**
44      * Errors returned by the method Msg.getErrCode().
45      */
46     
47     /* Everything is right. Keep on goin the way !                                
48      *
49      */
50     public static final int SUCCESS                = 0;
51     
52     /* Something must be not perfectly clean. But I 
53      * may be paranoid freak... !    
54      */
55     public static final int WARNING                = 1;
56     
57     /* There has been a problem during you task treansfer.
58      * Either the network is  down or the remote host has 
59      * been shutdown.
60      */
61     public static final int TRANSFERT_FAILURE    = 2;
62     
63     /**
64      * System shutdown. The host on which you are running
65      * has just been rebooted. Free your datastructures and
66      * return now !
67      */
68     public static final int HOST_FAILURE        = 3;
69     
70     /**
71      * Cancelled task. This task has been cancelled by somebody !
72      */
73     public static final int TASK_CANCELLLED        = 4;
74     
75     /**
76      * You've done something wrong. You'd better look at it...
77      */
78     public static final int FATAL_ERROR            = 5;
79     
80     /**
81      * Staticaly load the SIMGRID4JAVA library
82      *  which contains all native functions used in here
83      */
84     static {
85         try {
86             System.loadLibrary("simgrid");
87             Msg.selectContextFactory("jcontext_factory");
88         } catch(NativeException e)
89         {
90                   System.err.println(e.toString());
91                   e.printStackTrace();
92                   System.exit(1);
93         } catch(UnsatisfiedLinkError e){
94             System.err.println("Cannot load simgrid library : ");
95             e.printStackTrace();
96             System.err.println("Please check your LD_LIBRARY_PATH, "+
97                                "or copy the library to the current directory");
98             System.exit(1);
99         }
100     }
101     
102     final static native 
103     void selectContextFactory(String name) throws NativeException;
104     
105     /******************************************************************
106      * The natively implemented methods connected to the MSG Process  *
107      ******************************************************************/
108      
109     /**
110      * The natively implemented method to create an MSG process.
111      *
112      * @param process The java process object to bind with the MSG native process.
113      * @param host    A valid (binded) host where create the process.
114      *
115      * @exception  simgrid.msg.JniException if JNI stuff goes wrong.
116      *
117      * @see  Process constructors.
118      */
119     final static native 
120         void processCreate(Process process, Host host) throws JniException;
121      
122     /**
123      * The natively implemented method to kill all the process of the simulation.
124      *
125      * @param resetPID        Should we reset the PID numbers. A negative number means no reset
126      *                        and a positive number will be used to set the PID of the next newly
127      *                        created process.
128      *
129      * @return                The function returns the PID of the next created process.
130      */
131     final static native int processKillAll(int resetPID);
132        
133     /**
134      * The natively implemented method to suspend an MSG process.
135      *
136      * @param process        The valid (binded with a native process) java process to suspend.
137      *
138      * @exception            JniException if something goes wrong with JNI
139      *                       NativeException if the SimGrid native code failed.
140      *
141      * @see                 Process.pause()
142      */
143     final static native void processSuspend(Process process) 
144         throws JniException, NativeException;
145      
146     /**
147      * The natively implemented method to kill a MSG process.
148      *
149      * @param process        The valid (binded with a native process) java process to kill.
150      *
151      * @see                 Process.kill()
152      */
153     final static native void processKill(Process process)
154         throws JniException;
155      
156     /**
157      * The natively implemented method to resume a suspended MSG process.
158      *
159      * @param process        The valid (binded with a native process) java process to resume.
160      *
161      * @exception            JniException if something goes wrong with JNI
162      *                       NativeException if the SimGrid native code failed.
163      *
164      * @see                 Process.restart()
165      */
166     final static native void processResume(Process process)
167         throws JniException, NativeException;
168      
169     /**
170      * The natively implemented method to test if MSG process is suspended.
171      *
172      * @param process        The valid (binded with a native process) java process to test.
173      *
174      * @return                If the process is suspended the method retuns true. Otherwise the
175      *                        method returns false.
176      *
177      * @exception            JniException if something goes wrong with JNI
178      *
179      * @see                 Process.isSuspended()
180      */
181     final static native boolean processIsSuspended(Process process) throws JniException;
182      
183     /**
184      * The natively implemented method to get the host of a MSG process.
185      *
186      * @param process        The valid (binded with a native process) java process to get the host.
187      *
188      * @return                The method returns the host where the process is running.
189      *
190      * @exception            JniException if something goes wrong with JNI
191      *                       NativeException if the SimGrid native code failed.
192      *
193      * @see                 Process.getHost()
194      */
195     final static native Host processGetHost(Process process)
196         throws JniException, NativeException;
197      
198     /**
199      * The natively implemented method to get a MSG process from his PID.
200      *
201      * @param PID            The PID of the process to get.
202      *
203      * @return                The process with the specified PID.
204      *
205      * @exception            NativeException if the SimGrid native code failed.
206      *
207      * @see                 Process.getFromPID()
208      */
209     final static native Process processFromPID(int PID) throws NativeException;
210      
211     /**
212      * The natively implemented method to get the PID of a MSG process.
213      *
214      * @param process        The valid (binded with a native process) java process to get the PID.
215      *
216      * @return                The PID of the specified process.
217      *
218      * @exception            NativeException if the SimGrid native code failed.
219      *
220      * @see                 Process.getPID()
221      */
222     final static native int processGetPID(Process process) throws NativeException;
223      
224     /**
225      * The natively implemented method to get the PPID of a MSG process.
226      *
227      * @param process        The valid (binded with a native process) java process to get the PID.
228      *
229      * @return                The PPID of the specified process.
230      *
231      * @exception            NativeException if the SimGrid native code failed.
232      *
233      * @see                 Process.getPPID()
234      */
235     final static native int processGetPPID(Process process) throws NativeException;
236      
237     /**
238      * The natively implemented method to get the current running process.
239      *
240      * @return             The current process.
241      *
242      * @exception            NativeException if the SimGrid native code failed.
243
244      * @see                Process.currentProcess()
245      */
246     final static native Process processSelf() throws NativeException;
247      
248     /**
249      * The natively implemented method to get the current running process PID.
250      *
251      * @return                The PID of the current process.
252      *
253      * @see                Process.currentProcessPID()
254      */
255     final static native int processSelfPID();
256      
257     /**
258      * The natively implemented method to get the current running process PPID.
259      *
260      * @return                The PPID of the current process.
261      *
262      * @see                Process.currentProcessPPID()
263      */
264     final static native int processSelfPPID();
265      
266     /**
267      * The natively implemented method to migrate a process from his currnet host to a new host.
268      *
269      * @param process        The (valid) process to migrate.
270      * @param host            A (valid) host where move the process.
271      *
272      * @exception            JniException if something goes wrong with JNI
273      *                       NativeException if the SimGrid native code failed.
274      *
275      * @see                Process.migrate()
276      * @see                Host.getByName()
277      */
278     final static native void processChangeHost(Process process,Host host) 
279         throws JniException, NativeException;
280      
281     /**
282      * Process synchronization. The process wait the signal of the simulator to start.
283      * 
284      * @exception            JniException if something goes wrong with JNI
285      */
286     final static native void waitSignal(Process process) throws JniException;
287      
288     /**
289      * The natively implemented native to request the current process to sleep 
290      * until time seconds have elapsed.
291      *
292      * @param seconds        The time the current process must sleep.
293      *
294      * @exception            NativeException if the SimGrid native code failed.
295      *
296      * @see                 Process.waitFor()
297      */
298     final static native void processWaitFor(double seconds) throws NativeException;
299      
300     /**
301      * The natively implemented native method to exit a process.
302      *
303      * @exception            JniException if something goes wrong with JNI
304      *
305      * @see                Process.exit()
306      */
307     final static native void processExit(Process process) throws JniException;
308       
309      
310     /******************************************************************
311      * The natively implemented methods connected to the MSG host     *
312      ******************************************************************/
313      
314     /**
315      * The natively implemented method to get an host from his name.
316      *
317      * @param name            The name of the host to get.
318      *
319      * @return                The host having the specified name.
320      *
321      * @exception            JniException if something goes wrong with JNI
322      *                       HostNotFoundException if there is no such host
323      *                       NativeException if the SimGrid native code failed.
324      *
325      * @see                Host.getByName()
326      */
327     final static native Host hostGetByName(String name) 
328         throws JniException, HostNotFoundException, NativeException;
329      
330     /**
331      * The natively implemented method to get the name of an MSG host.
332      *
333      * @param host            The host (valid) to get the name.
334      *
335      * @return                The name of the specified host.
336      *
337      * @exception            JniException if something goes wrong with JNI
338      *
339      * @see                Host.getName()
340      */
341     final static native String hostGetName(Host host) throws JniException;
342      
343     /**
344      * The natively implemented method to get the number of hosts of the simulation.
345      *
346      * @return                The number of hosts of the simulation.
347      *
348      * @see                Host.getNumber()
349      */
350     final static native int hostGetNumber();
351      
352     /**
353      * The natively implemented method to get the host of the current runing process.
354      *
355      * @return                The host of the current running process.
356      *
357      * @exception            JniException if something goes wrong with JNI
358      *
359      * @see                Host.currentHost()
360      */
361     final static native Host hostSelf() throws JniException;
362      
363     /**
364      * The natively implemented method to get the speed of a MSG host.
365      *
366      * @param host            The host to get the host.
367      *
368      * @return                The speed of the specified host.
369      *
370      * @exception            JniException if something goes wrong with JNI
371      *
372      * @see                Host.getSpeed()
373      */
374       
375     final static native double hostGetSpeed(Host host) throws JniException;
376      
377     /**
378      * The natively implemented native method to test if an host is avail.
379      *
380      * @param host            The host to test.
381      *
382      * @return                If the host is avail the method returns true. 
383      *                        Otherwise the method returns false.
384      *
385      * @exception            JniException if something goes wrong with JNI
386      *
387      * @see                Host.isAvail()
388      */
389     final static native boolean hostIsAvail(Host host) throws JniException;
390      
391     /**
392      * The natively implemented native method to get all the hosts of the simulation.
393      *
394      * @exception            JniException if something goes wrong with JNI
395      *
396      * @return                A array which contains all the hosts of simulation.
397      */
398      
399     final static native Host[] allHosts() throws JniException;
400      
401     /**
402      * The natively implemented native method to get the number of running tasks on a host.
403      *
404      * @param                The host concerned by the operation.
405      *
406      * @return                The number of running tasks.
407      *
408      * @exception            JniException if something goes wrong with JNI
409      *
410      */
411     final static native int hostGetLoad(Host host) throws JniException;
412      
413     /******************************************************************
414      * The natively implemented methods connected to the MSG task     *
415      ******************************************************************/
416       
417     /**
418      * The natively implemented method to create a MSG task.
419      *
420      * @param name            The name of th task.
421      * @param computeDuration    A value of the processing amount (in flop) needed 
422      *                        to process the task. If 0, then it cannot be executed
423      *                        with the execute() method. This value has to be >= 0.
424      * @param messageSize        A value of amount of data (in bytes) needed to transfert 
425      *                        this task. If 0, then it cannot be transfered this task. 
426      *                        If 0, then it cannot be transfered with the get() and put() 
427      *                        methods. This value has to be >= 0.
428      * @param task            The java task object to bind with the native task to create.
429      *
430      * @exception             JniException if something goes wrong with JNI
431      *                        NullPointerException if the specified name is null.
432      *                        IllegalArgumentException if compute duration <0 or message size <0
433      *
434      * @see                    Task.create()
435      */
436     final static native void taskCreate(Task task,String name,double computeDuration, double messageSize)
437         throws JniException, NullPointerException, IllegalArgumentException;
438       
439     /**
440      * The natively implemented method to get the sender of a task.
441      *
442      * @param    task            The task (valid) to get the sender.
443      *
444      * @return                The sender of the task.
445      *
446      * @exception                InvalidTaskException is the specified task is not valid. A task
447      *                        is invalid if it is not binded with a native task.
448      *
449      * @see                    Task.getSender()
450      */
451     final static native Process taskGetSender(Task task) throws JniException;
452       
453     /**
454      * The natively implementd method to get the source of a task.
455      *
456      * @param task            The task to get the source.
457      *
458      * @return                The source of the task.
459      *
460      * @exception                InvalidTaskException is the specified task is not valid. A task
461      *                        is invalid if it is not binded with a native task.
462      *
463      * @see                    Task.getSource()
464      */
465     final static native Host taskGetSource(Task task) throws JniException, NativeException;
466       
467     /**
468      * The natively implemented method to get the name of the task.
469      *
470      * @param task            The task to get the name.
471      *
472      * @return                 The name of the specified task.
473      *
474      * @exception                InvalidTaskException is the specified task is not valid. A task
475      *                        is invalid if it is not binded with a native task.
476      *
477      * @see                    Task.getName()
478      */
479     final static native String taskGetName(Task task) throws JniException;
480       
481     /**
482      * The natively implemented method to cancel a task.
483      *
484      * @param task            The task to cancel.
485      *
486      * @exception                InvalidTaskException if the specified task is not valid. A task
487      *                        is invalid if it is not binded with a native task.
488      *                        MsgException if the cancelation failed.
489      *
490      * @see                    Task.cancel().
491      */
492     final static native void taskCancel(Task task) throws JniException, NativeException;
493       
494     /**
495      * The natively implemented method to get the computing amount of the task.
496      *
497      * @param task            The task to get the computing amount.
498      *
499      * @return                The computing amount of the specified task.
500      *
501      * @exception                InvalidTaskException if the specified task is not valid. A task
502      *                        is invalid if it is not binded with a native task.
503      *                        MsgException if the cancelation failed.
504      *
505      * @see                    Task.getComputeDuration()
506      */
507     final static native double taskGetComputeDuration(Task task) throws JniException;
508       
509     /**
510      * The natively implemented method to get the remaining computation
511      *
512      * @param task            The task to get the remaining computation.
513      *
514      * @return                The remaining computation of the specified task.
515      *
516      * @exception                InvalidTaskException if the specified task is not valid. A task
517      *                        is invalid if it is not binded with a native task.
518      *                        MsgException if the cancelation failed.
519      *
520      * @see                    Task.getRemainingDuration()
521      */
522     final static native double taskGetRemainingDuration(Task task) throws JniException;
523       
524     /**
525      * The natively implemented method to set the priority of a task.
526      *
527      * @param task            The task to set the prirotity
528      *
529      * @param priority        The new priority of the specified task.
530      *
531      * @exception                InvalidTaskException if the specified task is not valid. A task
532      *                        is invalid if it is not binded with a native task.
533      *                        MsgException if the cancelation failed.
534      *
535      * @see                    Task.setPriority()
536      */
537     final static native void taskSetPriority(Task task,double priority) throws JniException;
538       
539     /**
540      * The natively implemented method to destroy a MSG task.
541      *
542      * @param                    The task to destroy.
543      *
544      * @exception                InvalidTaskException is the specified task is not valid. A task
545      *                        is invalid if it is not binded with a native task.
546      *                        MsgException if the destruction failed.
547      *
548      * @see                    Task.destroy()
549      */
550     final static native void taskDestroy(Task task) throws JniException, NativeException;
551       
552     /**
553      * The natively implemented method to execute a MSG task.
554      *
555      * @param task            The task to execute.
556      *
557      * @exception                InvalidTaskException is the specified task is not valid. A task
558      *                        is invalid if it is not binded with a native task.
559      *                        MsgException if the destruction failed.
560      *
561      * @see                    Task.execute()
562      */
563     final static native void taskExecute(Task task) throws JniException, NativeException;
564       
565       
566      
567     /**************************************************************************
568      * The natively implemented methods connected to the MSG parallel task     *
569      ***************************************************************************/
570       
571     /**
572      * The natively implemented method to create a MSG parallel task.
573      *
574      * @param name                The name of the parallel task.
575      * @param hosts                The list of hosts implied by the parallel task.
576      * @param computeDurations    The total number of operations that have to be performed
577      *                            on the hosts.
578      * @param messageSizes        An array of doubles
579      *
580      * @see                        ParallelTask.create()
581      */
582     final static native void parallelTaskCreate(ParallelTask parallelTask, String name, 
583                                                        Host[] hosts, double[] computeDurations, double[] messageSizes)
584         throws JniException, NullPointerException, IllegalArgumentException;
585       
586     /**
587      * The natively implemented method to get the sender of a parallel task.
588      *
589      * @param    parallelTask    The parallel task (valid) to get the sender.
590      *
591      * @return                The sender of the parallel task.
592      *
593      * @see                    ParallelTask.getSender()
594      */
595     final static native Process parallelTaskGetSender(ParallelTask parallelTask) throws JniException;
596       
597     /**
598      * The natively implementd method to get the source of a parallel task.
599      *
600      * @param parallelTask    The parallel task to get the source.
601      *
602      * @return                The source of the parallel task.
603      *
604      * @see                    ParallelTask.getSource()
605      */
606     final static native Host parallelTaskGetSource(ParallelTask parallelTask) throws JniException;
607       
608     /**
609      * The natively implemented method to get the name of the parallel task.
610      *
611      * @param parallelTask    The parallel task to get the name.
612      *
613      * @return                 The name of the specified parallel task.
614      *
615      * @see                    ParallelTask.getName()
616      */
617     final static native String parallelTaskGetName(ParallelTask parallelTask) throws JniException;
618       
619     /**
620      * The natively implemented method to cancel a parallel task.
621      *
622      * @param parallelTask    The parallel task to cancel.
623      *
624      * @see                    ParallelTask.cancel().
625      */
626     final static native void parallelTaskCancel(ParallelTask parallelTask) throws JniException,NativeException;
627       
628     /**
629      * The natively implemented method to get the computing amount of the task.
630      *
631      * @param parallelTask    The parallel task to get the computing amount.
632      *
633      * @return                The computing amount of the specified parallel task.
634      *
635      * @see                    ParallelTask.getComputeDuration()
636      */
637     final static native double parallelTaskGetComputeDuration(ParallelTask parallelTask) throws JniException;
638       
639     /**
640      * The natively implemented method to get the remaining computation
641      *
642      * @param parallelTask    The parallel task to get the remaining computation.
643      *
644      * @return                The remaining computation of the specified parallel task.
645      *
646      * @see                    ParallelTask.getRemainingDuration()
647      */
648     final static native double parallelTaskGetRemainingDuration(ParallelTask parallelTask) throws JniException;
649       
650     /**
651      * The natively implemented method to set the priority of a parallel task.
652      *
653      * @param parallelTask    The parallel task to set the prirotity
654      *
655      * @param priority        The new priority of the specified parallel task.
656      *
657      * @see                    ParallelTask.setPriority()
658      */
659     final static native void parallelTaskSetPriority(ParallelTask parallelTask,double priority) throws JniException;
660       
661     /**
662      * The natively implemented method to destroy a MSG parallel task.
663      *
664      * @param parallelTask    The parallel task to destroy.
665      *
666      * @see                    ParallelTask.destroy()
667      */
668     final static native void parallelTaskDestroy(ParallelTask parallelTask) throws JniException,NativeException;
669       
670     /**
671      * The natively implemented method to execute a MSG parallel task.
672      *
673      * @param parallelTask    The parallel task to execute.
674      *
675      * @see                    ParallelTask.execute()
676      */
677     final static native void parallelTaskExecute(ParallelTask parallelTask) throws JniException, NativeException;
678       
679     /******************************************************************
680      * The natively implemented methods connected to the MSG channel  *
681      ******************************************************************/
682       
683     /**
684      * The natively implemented method to listen on the channel and wait for receiving a task.
685      *
686      * @param channel            The channel to listen            
687      *
688      * @return                The task readed from the channel.
689      *
690      * @exception                MsgException if the listening operation failed.
691      *
692      * @see                    Channel.get()
693      */
694     final static native Task channelGet(Channel channel) throws JniException,NativeException;
695       
696     /**
697      * The natively implemented method to listen on the channel and wait for receiving a task with a timeout.
698      *
699      * @param channel            The channel to listen.
700      * @param timeout            The timeout of the listening.
701      *
702      * @return                The task readed from the channel.
703      *
704      * @exception                MsgException if the listening operation failed.
705      *
706      * @see                    Channel.getWithTimeout()
707      *
708      */ 
709     final static native Task channelGetWithTimeout(Channel channel,double timeout) throws JniException,NativeException;
710       
711       
712     /**
713      * The natively implemented method to listen on the channel of a specific host.
714      *
715      * @param    channel            The channel to listen.
716      *
717      * @param host            The specific host.
718      *
719      * @return                The task readed from the channel of the specific host.
720      *
721      * @exception                InvalidHostException if the specified host is not valid.
722      *                        MsgException if the listening operation failed.
723      *
724      * @see                    Channel.getFromHost()
725      */    
726     final static native Task channelGetFromHost(Channel channel,Host host) throws JniException,NativeException;
727       
728     /**
729      * The natively implemented method to test whether there is a pending communication on the channel.
730      *
731      * @param channel            The channel concerned by the operation.
732      *
733      * @return                The method returns true if there is a pending communication on the specified
734      *                        channel. Otherwise the method returns false.
735      *
736      * @see                    Channel.hasPendingCommunication()
737      */                
738     final static native boolean channelHasPendingCommunication(Channel channel) throws JniException;
739       
740     /**
741      * The natively implemented method to test whether there is a pending communication on a 
742      * channel, and who sent it.
743      *
744      * @param                    The channel concerned by the operation.
745      *
746      * @return                The method returns -1 if there is no pending communication and 
747      *                        the PID of the process who sent it otherwise.
748      *
749      * @see                    Channel.getCummunicatingProcess()
750      */
751     final static native int channelGetCommunicatingProcess(Channel channel) throws JniException;
752       
753     /**
754      * The natively implemented method to get the number of tasks waiting to be received on a
755      * channel and sent by a host.
756      *
757      * @param channel            The channel concerned by the operation.
758      *
759      * @param host            The sender of the tasks.
760      *
761      * @return                The number of tasks waiting to be received on a channel
762      *                         and sent by the specified host.
763      *
764      * @exception                InvalidHostException if the specified host is not valid.
765      *
766      * @see                    Channel.getHostWaiting()
767      */
768     final static native int channelGetHostWaitingTasks(Channel channel,Host host) throws JniException;
769       
770     /**
771      * The natively implemented method to put a task on the channel of an host.
772      *
773      * @param channel            The channel where to put the task.
774      * @param task            The task to put.
775      * @param host            The host of the specified channel.
776      *
777      * @exception                InvalidTaskException if the task is not valid.
778      *                        InvalidHostException if the host is not valid.
779      *                        MsgException if the operation failed.
780      *
781      * @see                    Channel.put()
782      */                
783     final static native void channelPut(Channel channel,Task task,Host host) throws JniException,NativeException;
784       
785     /**
786      * The natively implemented method to put a task on a channel of an  host (with a timeout 
787      * on the waiting of the destination host) and waits for the end of the transmission.
788      *
789      * @param channel            The channel where to put the task.
790      * @param task            The task to put.
791      * @param host            The host containing the channel.
792      * @param timeout            The timeout of the transmission.
793      *
794      * @exception                InvalidTaskException if the task is not valid.
795      *                        InvalidHostException if the host is not valid.
796      *                        MsgException if the operation failed.
797      *
798      * @see                    Channel.putWithTimeout()
799      */
800     final static native void channelPutWithTimeout(Channel channel,Task task,Host host,double timeout) throws JniException,NativeException;
801       
802     /**
803      * The natively implemented method to put a task on channel with a bounded transmition
804      * rate.
805      * 
806      * @param channel            The channel where to put the task.
807      * @param task            The task to put.
808      * @param host            The host containing the channel.
809      * @param max_rate        The bounded transmition rate.
810      *
811      * @exception                InvalidTaskException if the task is not valid.
812      *                        InvalidHostException if the host is not valid.
813      *                        MsgException if the operation failed.
814      *
815      * @see                    Channel.putBounded()
816      */
817     final static native void channelPutBounded(Channel channel,Task task,Host host,double max_rate) throws JniException,NativeException;
818       
819     /**
820      * The natively implemented method to wait for at most timeout seconds for a task reception
821      * on channel. The PID is updated with the PID of the first process.
822      *
823      * @param channel            The channel concerned by the operation.
824      * @param timeout            The maximum time to wait for a task before
825      *                         giving up.
826      *
827      * @exception                MsgException if the reception operation failed.
828      *
829      * @see                    Channel.wait()
830      */
831     final static native int channelWait(Channel channel, double timeout) throws JniException,NativeException;
832       
833     /**
834      * The natively implemented method to set the number of channel used by all the process
835      * of the simulation.
836      *
837      * @param channelNumber    The channel number of the process.
838      *
839      * @see                    Channel.setNumber()
840      */
841     final static native void channelSetNumber(int channelNumber);
842       
843     /**
844      * The natively implemented method to get the number of channel of the process of the simulation.
845      *
846      * @return                The number of channel per process.
847      *
848      * @see                    Channel.getNumber()
849      */
850     final static native int channelGetNumber();
851              
852     /*********************************************************************************
853      * Additional native methods                                                      *
854      **********************************************************************************/
855       
856     /**
857      * The natively implemented method to get the simulation time.
858      *
859      * @param                    The simulation time.
860      */
861     public final static native double getClock();
862       
863     public final static native void pajeOutput(String pajeFile);
864       
865        
866     public final static native void info(String s);
867                         
868     /*********************************************************************
869      * The natively implemented methods connected to the MSG simulation  *
870      *********************************************************************/
871        
872     /**
873      * The natively implemented method to initialize a MSG simulation.
874      *
875      * @param args            The arguments of the command line of the simulation.
876      *
877      * @see                    Msg.init()
878      */
879     public final static native void init(String[] args);
880        
881     /**
882      * Run the MSG simulation, and cleanup everything afterward.
883      *
884      * If you want to chain simulations in the same process, you
885      * should call again createEnvironment and deployApplication afterward.
886      *
887      * @see                    MSG_run, MSG_clean
888      */
889     public final static native void run() throws NativeException;
890        
891     /**
892      * The native implemented method to create the environment of the simulation.
893      *
894      * @param platformFile    The XML file which contains the description of the environment of the simulation
895      *
896      */
897     public final static native void createEnvironment(String platformFile) throws NativeException;
898        
899        
900     /**
901      * The method to deploy the simulation.
902      *
903      * @param appFile        The XML file which contains the description of the application to deploy.
904      */
905        
906         
907     public static void deployApplication(String platformFile) {
908         try {
909             Class c = Class.forName("com.sun.org.apache.xerces.internal.parsers.SAXParser");
910             XMLReader reader = (XMLReader)c.newInstance();
911             reader.setEntityResolver(new DTDResolver());
912             ApplicationHandler handler = new ApplicationHandler();
913             reader.setContentHandler(handler);
914             reader.setFeature("http://xml.org/sax/features/validation", false);
915             reader.parse(platformFile);
916
917         } catch(Exception e) {
918             /* FIXME: do not swallow exception ! */
919             System.out.println("Exception in Msg.launchApplication()");
920             System.out.println(e);
921             e.printStackTrace();
922         }        
923     }                    
924
925     /* The launcher */
926     static public void main(String[]args) throws MsgException {
927         /* initialize the MSG simulation. Must be done before anything else (even logging). */
928         Msg.init(args);
929
930         if(args.length < 2) {
931                 
932             Msg.info("Usage: Msg platform_file deployment_file");
933             System.exit(1);
934         }
935                 
936         /* specify the number of channel for the process of the simulation. */
937         Channel.setNumber(1);
938                 
939         /* Load the platform and deploy the application */
940         Msg.createEnvironment(args[0]);
941         Msg.deployApplication(args[1]);
942                 
943         /* Execute the simulation */
944         Msg.run();
945     }
946 }