Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid-java...
[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         /** This function is useless nowadays, just stop calling it. */
88         @Deprecated
89         public final static void clean(){}
90
91         /**
92          * The native implemented method to create the environment of the simulation.
93          *
94          * @param platformFile    The XML file which contains the description of the environment of the simulation
95          *
96          */
97         public final static native void createEnvironment(String platformFile);
98
99         /**
100          * The method to deploy the simulation.
101          *
102      *
103      * @param deploymentFile
104      */
105         public final static native void deployApplication(String deploymentFile);
106
107     /** Example launcher. You can use it or provide your own launcher, as you wish
108      * @param args
109      * @throws MsgException
110      */
111         static public void main(String[]args) throws MsgException {
112                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
113                 Msg.init(args);
114
115                 if (args.length < 2) {
116                         Msg.info("Usage: Msg platform_file deployment_file");
117                         System.exit(1);
118                 }
119
120                 /* Load the platform and deploy the application */
121                 Msg.createEnvironment(args[0]);
122                 Msg.deployApplication(args[1]);
123                 /* Execute the simulation */
124                 Msg.run();
125         }
126 }