Logo AND Algorithmique Numérique Distribuée

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