Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
75c4952a71e1c888fdc491839b93ee8383f3bd1a
[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 and Task
23  * of the package to build your application.
24  *
25  * @author  Abdelmalek Cherier
26  * @author  Martin Quinson
27  * @since SimGrid 3.3
28  */
29 public final class Msg {
30   /*
31    * Statically load the library which contains all native functions used in here
32    */
33   static {
34     try {
35       System.loadLibrary("simgrid");
36     } catch(UnsatisfiedLinkError e) {
37       System.err.println("Cannot load simgrid library : ");
38       e.printStackTrace();
39       System.err.println("Please check your LD_LIBRARY_PATH, " +
40                          "or copy the library to the current directory");
41       System.exit(1);
42     }
43   }
44
45     /** Returns the last error code of the simulation */
46   public final static native int getErrCode();
47
48     /** Everything is right. Keep on goin the way ! */
49   public static final int SUCCESS = 0;
50
51     /** Something must be not perfectly clean (but I may be paranoid freak...) */
52   public static final int WARNING = 1;
53
54     /** There has been a problem during you task treansfer.
55      *  Either the network is  down or the remote host has been shutdown */
56   public static final int TRANSFERT_FAILURE = 2;
57
58     /** System shutdown. 
59      *  The host on which you are running has just been rebooted.
60      *  Free your datastructures and return now ! */
61   public static final int HOST_FAILURE = 3;
62
63     /** Cancelled task. This task has been cancelled by somebody ! */
64   public static final int TASK_CANCELLLED = 4;
65
66     /** You've done something wrong. You'd better look at it... */
67   public static final int FATAL_ERROR = 5;
68
69
70
71    /** Retrieve the simulation time */
72   public final static native double getClock();
73
74   public final static native void pajeOutput(String pajeFile);
75
76
77    /** Issue an information logging message */
78   public final static native void info(String s);
79
80     /*********************************************************************************
81      * Deployment and initialization related functions                               *
82      *********************************************************************************/
83
84     /**
85      * The natively implemented method to initialize a MSG simulation.
86      *
87      * @param args            The arguments of the command line of the simulation.
88      *
89      * @see                    Msg.init()
90      */
91   public final static native void init(String[]args);
92
93     /**
94      * Run the MSG simulation, and cleanup everything afterward.
95      *
96      * If you want to chain simulations in the same process, you
97      * should call again createEnvironment and deployApplication afterward.
98      *
99      * @see                    MSG_run, MSG_clean
100      */
101   public final static native void run() throws NativeException;
102
103     /**
104      * The native implemented method to create the environment of the simulation.
105      *
106      * @param platformFile    The XML file which contains the description of the environment of the simulation
107      *
108      */
109   public final static native void createEnvironment(String platformFile)
110   throws NativeException;
111   
112    /**
113      * The method to deploy the simulation.
114      *
115      * @param platformFile    The XML file which contains the description of the application to deploy.
116      */
117   public final static native void deployApplication(String deploymentFile)
118   throws NativeException;
119  
120   /* The launcher */
121   static public void main(String[]args) throws MsgException {
122     /* initialize the MSG simulation. Must be done before anything else (even logging). */
123     Msg.init(args);
124
125     if (args.length < 2) {
126       Msg.info("Usage: Msg platform_file deployment_file");
127       System.exit(1);
128     }
129
130     /* Load the platform and deploy the application */
131     Msg.createEnvironment(args[0]);
132     Msg.deployApplication(args[1]);
133
134     /* Execute the simulation */
135     Msg.run();
136   }
137 }