Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c442da4260e77d940aa624d2b83ed5cdd1b42f6e
[simgrid.git] / src / bindings / java / org / simgrid / msg / Msg.java
1 /* JNI interface to C code for MSG. */
2
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 package org.simgrid.msg;
10 import org.simgrid.NativeLib;
11
12
13 public final class Msg {
14         /* Statically load the library which contains all native functions used in here */
15         static private boolean isNativeInited = false;
16         public static void nativeInit() {
17                 if (isNativeInited)
18                         return;
19                 try {
20                         NativeLib.nativeInit("winpthread");
21                 } catch (Exception e)  {
22                         if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
23                                 System.err.println("Cannot load winpthread.dll:");
24                                 e.printStackTrace();
25                         }
26                 }
27
28                 NativeLib.nativeInit("simgrid");
29                 NativeLib.nativeInit("simgrid-java");      
30                 isNativeInited = true;
31         }
32
33         static {
34                 nativeInit();
35         }
36
37         /** Retrieve the simulation time
38          * @return The simulation time.
39          */
40         public final static native double getClock();
41         /**
42          * Issue a debug logging message.
43          * @param s message to log.
44          */
45         public final static native void debug(String s);
46         /**
47          * Issue an verbose logging message.
48          * @param s message to log.
49          */
50         public final static native void verb(String s);
51
52         /** Issue an information logging message
53          * @param s
54          */
55         public final static native void info(String s);
56         /**
57          * Issue an warning logging message.
58          * @param s message to log.
59          */
60         public final static native void warn(String s);
61         /**
62          * Issue an error logging message.
63          * @param s message to log.
64          */
65         public final static native void error(String s);
66         /**
67          * Issue an critical logging message.
68          * @param s message to log.
69          */
70         public final static native void critical(String s);
71
72         /*********************************************************************************
73          * Deployment and initialization related functions                               *
74          *********************************************************************************/
75
76         /**
77          * The natively implemented method to initialize a MSG simulation.
78          *
79          * @param args            The arguments of the command line of the simulation.
80          */
81         public final static native void init(String[]args);
82
83         /**
84          * Run the MSG simulation.
85          *
86          * The simulation is not cleaned afterward (see  
87          * {@link #clean()} if you really insist on cleaning the C side), so you can freely 
88          * retrieve the informations that you want from the simulation. In particular, retrieving the status 
89          * of a process or the current date is perfectly ok. 
90          */
91         public final static native void run() ;
92
93         /** This function is useless nowadays, just stop calling it. */
94         @Deprecated
95         public final static void clean(){}
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         public final static native As environmentGetRoutingRoot();
106
107         /**
108          * The method to deploy the simulation.
109          *
110          *
111          * @param deploymentFile
112          */
113         public final static native void deployApplication(String deploymentFile);
114
115         /** Example launcher. You can use it or provide your own launcher, as you wish
116          * @param args
117          * @throws MsgException
118          */
119         static public void main(String[]args) throws MsgException {
120                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
121                 Msg.init(args);
122
123                 if (args.length < 2) {
124                         Msg.info("Usage: Msg platform_file deployment_file");
125                         System.exit(1);
126                 }
127
128                 /* Load the platform and deploy the application */
129                 Msg.createEnvironment(args[0]);
130                 Msg.deployApplication(args[1]);
131                 /* Execute the simulation */
132                 Msg.run();
133         }
134 }