Logo AND Algorithmique Numérique Distribuée

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