Logo AND Algorithmique Numérique Distribuée

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