Logo AND Algorithmique Numérique Distribuée

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