Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
64c0713ad3ea0c8cc99ee21386097f8f5f78c41c
[simgrid.git] / org / simgrid / msg / Msg.java
1 /*
2  * JNI interface to C code for MSG.
3  * 
4  * Copyright 2006,2007,2010,2011 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
28         /* FIXME: kill these C crufts */
29     /** Returns the last error code of the simulation
30      * @return
31      */
32         public final static native int getErrCode();
33
34         /** Everything is right. Keep on going the way ! */
35         public static final int SUCCESS = 0;
36
37         /** Something must be not perfectly clean (but I may be paranoid freak...) */
38         public static final int WARNING = 1;
39
40         /** There has been a problem during your task transfer.
41          *  Either the network is  down or the remote host has been shutdown */
42         public static final int TRANSFERT_FAILURE = 2;
43
44         /** System shutdown. 
45          *  The host on which you are running has just been rebooted.
46          *  Free your data structures and return now ! */
47         public static final int HOST_FAILURE = 3;
48
49         /** Canceled task. This task has been canceled by somebody ! */
50         public static final int TASK_CANCELLLED = 4;
51
52         /** You've done something wrong. You'd better look at it... */
53         public static final int FATAL_ERROR = 5;
54
55     /** Retrieve the simulation time
56      * @return
57      */
58         public final static native double getClock();
59
60     /** Issue an information logging message
61      * @param s
62      */
63         public final static native void info(String s);
64
65         /*********************************************************************************
66          * Deployment and initialization related functions                               *
67          *********************************************************************************/
68
69         /**
70          * The natively implemented method to initialize a MSG simulation.
71          *
72          * @param args            The arguments of the command line of the simulation.
73          *
74          * @see                    Msg.init()
75          */
76         public final static native void init(String[]args);
77
78         /**
79          * Run the MSG simulation, and cleanup everything afterward.
80          *
81          * If you want to chain simulations in the same process, you
82          * should call again createEnvironment and deployApplication afterward.
83          *
84          * @see                    MSG_run, MSG_clean
85          */
86         public final static native void run() ;
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         /**
97          * The method to deploy the simulation.
98          *
99      *
100      * @param deploymentFile
101      */
102         public final static native void deployApplication(String deploymentFile);
103
104     /** Example launcher. You can use it or provide your own launcher, as you wish
105      * @param args
106      * @throws MsgException
107      */
108         static public void main(String[]args) throws MsgException {
109                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
110                 Msg.init(args);
111
112                 if (args.length < 2) {
113                         Msg.info("Usage: Msg platform_file deployment_file");
114                         System.exit(1);
115                 }
116
117                 /* Load the platform and deploy the application */
118                 Msg.createEnvironment(args[0]);
119                 Msg.deployApplication(args[1]);
120                 /* Execute the simulation */
121                 Msg.run();
122         }
123 }