Logo AND Algorithmique Numérique Distribuée

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