Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ef973105d5e830727c9457706c6be0508559eb3d
[simgrid.git] / org / simgrid / msg / Msg.java
1 /*
2  * JNI interface to C code for MSG.
3  * 
4  * Copyright 2006,2007,2010 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 /**
15  *
16  * @author lbobelin
17  */
18 public final class Msg {
19         /* Statically load the library which contains all native functions used in here */
20         static {
21                 try {
22                         System.loadLibrary("SG_java");
23                 } catch(UnsatisfiedLinkError e) {
24                         System.err.println("Cannot load the bindings to the simgrid library: ");
25                         e.printStackTrace();
26                         System.err.println(
27                                         "Please check your LD_LIBRARY_PATH, or copy the simgrid and SG_java libraries to the current directory");
28                         System.exit(1);
29                 }
30         }
31
32         /* FIXME: kill these C crufts */
33     /** Returns the last error code of the simulation
34      * @return
35      */
36         public final static native int getErrCode();
37
38         /** Everything is right. Keep on going the way ! */
39         public static final int SUCCESS = 0;
40
41         /** Something must be not perfectly clean (but I may be paranoid freak...) */
42         public static final int WARNING = 1;
43
44         /** There has been a problem during your task transfer.
45          *  Either the network is  down or the remote host has been shutdown */
46         public static final int TRANSFERT_FAILURE = 2;
47
48         /** System shutdown. 
49          *  The host on which you are running has just been rebooted.
50          *  Free your data structures and return now ! */
51         public static final int HOST_FAILURE = 3;
52
53         /** Canceled task. This task has been canceled by somebody ! */
54         public static final int TASK_CANCELLLED = 4;
55
56         /** You've done something wrong. You'd better look at it... */
57         public static final int FATAL_ERROR = 5;
58
59     /** Retrieve the simulation time
60      * @return
61      */
62         public final static native double getClock();
63
64     /** Issue an information logging message
65      * @param s
66      */
67         public final static native void info(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          * @see                    Msg.init()
79          */
80         public final static native void init(String[]args);
81
82         /**
83          * Run the MSG simulation, and cleanup everything afterward.
84          *
85          * If you want to chain simulations in the same process, you
86          * should call again createEnvironment and deployApplication afterward.
87          *
88          * @see                    MSG_run, MSG_clean
89          */
90         public final static native void run() ;
91
92         /**
93          * The native implemented method to create the environment of the simulation.
94          *
95          * @param platformFile    The XML file which contains the description of the environment of the simulation
96          *
97          */
98         public final static native void createEnvironment(String platformFile);
99
100         /**
101          * The method to deploy the simulation.
102          *
103      *
104      * @param deploymentFile
105      */
106         public final static native void deployApplication(String deploymentFile);
107
108     /** Example launcher. You can use it or provide your own launcher, as you wish
109      * @param args
110      * @throws MsgException
111      */
112         static public void main(String[]args) throws MsgException {
113                 /* initialize the MSG simulation. Must be done before anything else (even logging). */
114                 Msg.init(args);
115
116                 if (args.length < 2) {
117                         Msg.info("Usage: Msg platform_file deployment_file");
118                         System.exit(1);
119                 }
120
121                 /* Load the platform and deploy the application */
122                 Msg.createEnvironment(args[0]);
123                 Msg.deployApplication(args[1]);
124                 /* Execute the simulation */
125                 Msg.run();
126         }
127 }