Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8153a4241d61146e35cb9b22fc2c02fb75eb79c9
[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                 NativeLib.nativeInit("simgrid");
20                 NativeLib.nativeInit("simgrid-java");      
21                 isNativeInited = true;
22         }
23
24         static {
25                 nativeInit();
26         }
27
28         /** Retrieve the simulation time
29          * @return The simulation time.
30          */
31         public final static native double getClock();
32         /**
33          * Issue a debug logging message.
34          * @param s message to log.
35          */
36         public final static native void debug(String s);
37         /**
38          * Issue an verbose logging message.
39          * @param s message to log.
40          */
41         public final static native void verb(String s);
42
43         /** Issue an information logging message
44          * @param s
45          */
46         public final static native void info(String s);
47         /**
48          * Issue an warning logging message.
49          * @param s message to log.
50          */
51         public final static native void warn(String s);
52         /**
53          * Issue an error logging message.
54          * @param s message to log.
55          */
56         public final static native void error(String s);
57         /**
58          * Issue an critical logging message.
59          * @param s message to log.
60          */
61         public final static native void critical(String s);
62
63         /*********************************************************************************
64          * Deployment and initialization related functions                               *
65          *********************************************************************************/
66
67         /**
68          * The natively implemented method to initialize a MSG simulation.
69          *
70          * @param args            The arguments of the command line of the simulation.
71          */
72         public final static native void init(String[]args);
73
74         /**
75          * Run the MSG simulation.
76          *
77          * The simulation is not cleaned afterward (see  
78          * {@link #clean()} if you really insist on cleaning the C side), so you can freely 
79          * retrieve the informations that you want from the simulation. In particular, retrieving the status 
80          * of a process or the current date is perfectly ok. 
81          */
82         public final static native void run() ;
83
84         /** This function is useless nowadays, just stop calling it. */
85         @Deprecated
86         public final static void clean(){}
87
88         /**
89          * The native implemented method to create the environment of the simulation.
90          *
91          * @param platformFile    The XML file which contains the description of the environment of the simulation
92          *
93          */
94         public final static native void createEnvironment(String platformFile);
95
96         public final static native As environmentGetRoutingRoot();
97
98         /**
99          * The method to deploy the simulation.
100          *
101          *
102          * @param deploymentFile
103          */
104         public final static native void deployApplication(String deploymentFile);
105
106         /** Example launcher. You can use it or provide your own launcher, as you wish
107          * @param args
108          * @throws MsgException
109          */
110         static public void main(String[]args) throws MsgException {
111                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
112                 Msg.init(args);
113
114                 if (args.length < 2) {
115                         Msg.info("Usage: Msg platform_file deployment_file");
116                         System.exit(1);
117                 }
118
119                 /* Load the platform and deploy the application */
120                 Msg.createEnvironment(args[0]);
121                 Msg.deployApplication(args[1]);
122                 /* Execute the simulation */
123                 Msg.run();
124         }
125 }