Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove deprecated function getErrCode.
[simgrid.git] / org / simgrid / msg / Msg.java
1 /*
2  * JNI interface to C code for MSG.
3  * 
4  * Copyright 2006,2007,2010,2011 The SimGrid Team.           
5  * All right reserved. 
6  *
7  * This program is free software; you can redistribute 
8  * it and/or modify it under the terms of the license 
9  * (GNU LGPL) which comes with this package.
10  */
11
12 package org.simgrid.msg;
13
14 public final class Msg {
15         /* Statically load the library which contains all native functions used in here */
16         static {
17                 try {
18                         System.loadLibrary("SG_java");
19                 } catch(UnsatisfiedLinkError e) {
20                         System.err.println("Cannot load the bindings to the simgrid library: ");
21                         e.printStackTrace();
22                         System.err.println(
23                                         "Please check your LD_LIBRARY_PATH, or copy the simgrid and SG_java libraries to the current directory");
24                         System.exit(1);
25                 }
26         }
27
28         /** Everything is right. Keep on going the way ! */
29         public static final int SUCCESS = 0;
30
31         /** Something must be not perfectly clean (but I may be paranoid freak...) */
32         public static final int WARNING = 1;
33
34         /** There has been a problem during your task transfer.
35          *  Either the network is  down or the remote host has been shutdown */
36         public static final int TRANSFERT_FAILURE = 2;
37
38         /** System shutdown. 
39          *  The host on which you are running has just been rebooted.
40          *  Free your data structures and return now ! */
41         public static final int HOST_FAILURE = 3;
42
43         /** Canceled task. This task has been canceled by somebody ! */
44         public static final int TASK_CANCELLLED = 4;
45
46         /** You've done something wrong. You'd better look at it... */
47         public static final int FATAL_ERROR = 5;
48
49     /** Retrieve the simulation time
50      * @return
51      */
52         public final static native double getClock();
53
54     /** Issue an information logging message
55      * @param s
56      */
57         public final static native void info(String s);
58
59         /*********************************************************************************
60          * Deployment and initialization related functions                               *
61          *********************************************************************************/
62
63         /**
64          * The natively implemented method to initialize a MSG simulation.
65          *
66          * @param args            The arguments of the command line of the simulation.
67          *
68          * @see                    Msg.init()
69          */
70         public final static native void init(String[]args);
71
72         /**
73          * Run the MSG simulation.
74          *
75          * The simulation is not cleaned afterward (see  
76          * {@link #clean()} if you really insist on cleaning the C side), so you can freely 
77          * retrieve the informations that you want from the simulation. In particular, retrieving the status 
78          * of a process or the current date is perfectly ok. 
79          *
80          * @see                    MSG_run
81          */
82         public final static native void run() ;
83         
84         /**
85          * Cleanup the MSG simulation.
86          * 
87          * This function is only useful if you want to chain the simulations within 
88          * the same environment. But actually, it's not sure at all that cleaning the 
89          * JVM is faster than restarting a new one, so it's probable that using this 
90          * function is not a brilliant idea. Do so at own risk.
91          *      
92          * @see                    MSG_clean
93          */
94         public final static native void clean();
95         
96
97         /**
98          * The native implemented method to create the environment of the simulation.
99          *
100          * @param platformFile    The XML file which contains the description of the environment of the simulation
101          *
102          */
103         public final static native void createEnvironment(String platformFile);
104
105         /**
106          * The method to deploy the simulation.
107          *
108      *
109      * @param deploymentFile
110      */
111         public final static native void deployApplication(String deploymentFile);
112
113     /** Example launcher. You can use it or provide your own launcher, as you wish
114      * @param args
115      * @throws MsgException
116      */
117         static public void main(String[]args) throws MsgException {
118                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
119                 Msg.init(args);
120
121                 if (args.length < 2) {
122                         Msg.info("Usage: Msg platform_file deployment_file");
123                         System.exit(1);
124                 }
125
126                 /* Load the platform and deploy the application */
127                 Msg.createEnvironment(args[0]);
128                 Msg.deployApplication(args[1]);
129                 /* Execute the simulation */
130                 Msg.run();
131         }
132 }