Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless fields in Msg
[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     /** Retrieve the simulation time
28      * @return
29      */
30         public final static native double getClock();
31         /**
32          * Issue an "debug" logging message.
33          * @param s message to log.
34          */
35         public final static native void debug(String s);
36     /** Issue an information logging message
37      * @param s
38      */
39         public final static native void info(String s);
40
41         /*********************************************************************************
42          * Deployment and initialization related functions                               *
43          *********************************************************************************/
44
45         /**
46          * The natively implemented method to initialize a MSG simulation.
47          *
48          * @param args            The arguments of the command line of the simulation.
49          *
50          * @see                    Msg.init()
51          */
52         public final static native void init(String[]args);
53
54         /**
55          * Run the MSG simulation.
56          *
57          * The simulation is not cleaned afterward (see  
58          * {@link #clean()} if you really insist on cleaning the C side), so you can freely 
59          * retrieve the informations that you want from the simulation. In particular, retrieving the status 
60          * of a process or the current date is perfectly ok. 
61          *
62          * @see                    MSG_run
63          */
64         public final static native void run() ;
65         
66         /**
67          * Cleanup the MSG simulation.
68          * 
69          * This function is only useful if you want to chain the simulations within 
70          * the same environment. But actually, it's not sure at all that cleaning the 
71          * JVM is faster than restarting a new one, so it's probable that using this 
72          * function is not a brilliant idea. Do so at own risk.
73          *      
74          * @see                    MSG_clean
75          */
76         public final static native void clean();
77         
78
79         /**
80          * The native implemented method to create the environment of the simulation.
81          *
82          * @param platformFile    The XML file which contains the description of the environment of the simulation
83          *
84          */
85         public final static native void createEnvironment(String platformFile);
86
87         /**
88          * The method to deploy the simulation.
89          *
90      *
91      * @param deploymentFile
92      */
93         public final static native void deployApplication(String deploymentFile);
94
95     /** Example launcher. You can use it or provide your own launcher, as you wish
96      * @param args
97      * @throws MsgException
98      */
99         static public void main(String[]args) throws MsgException {
100                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
101                 Msg.init(args);
102
103                 if (args.length < 2) {
104                         Msg.info("Usage: Msg platform_file deployment_file");
105                         System.exit(1);
106                 }
107
108                 /* Load the platform and deploy the application */
109                 Msg.createEnvironment(args[0]);
110                 Msg.deployApplication(args[1]);
111                 /* Execute the simulation */
112                 Msg.run();
113         }
114 }