Logo AND Algorithmique Numérique Distribuée

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