Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix try to fix the JAVA crap!
[simgrid.git] / src / java / simgrid / msg / Msg.java
1 /*
2  * simgrid.msg.Msg.java    1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
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 import org.xml.sax.*;
14
15 /** 
16  * MSG was the first distributed programming environment 
17  * provided within SimGrid. While almost realistic, it 
18  * remains quite simple.
19  * This class contains all the declaration of the natives methods
20  * of the MSG API.
21  * All of these methods are statics. You can't directly use these methods
22  * but it is recommanded to use the classes Process, Host and Task
23  * of the package to build your application.
24  *
25  * @author  Abdelmalek Cherier
26  * @author  Martin Quinson
27  * @since SimGrid 3.3
28  */
29 public final class Msg {
30   /*
31    * Statically load the library which contains all native functions used in here
32    */
33   static {
34     try {
35       System.loadLibrary("simgrid");
36       //MsgNative.selectContextFactory("java");
37  /*   } catch(NativeException e) {
38       System.err.println(e.toString());
39       e.printStackTrace();
40       System.exit(1);*/
41     } catch(UnsatisfiedLinkError e) {
42       System.err.println("Cannot load simgrid library : ");
43       e.printStackTrace();
44       System.err.println("Please check your LD_LIBRARY_PATH, " +
45                          "or copy the library to the current directory");
46       System.exit(1);
47     }
48   }
49
50     /** Returns the last error code of the simulation */
51   public final static native int getErrCode();
52
53     /** Everything is right. Keep on goin the way ! */
54   public static final int SUCCESS = 0;
55
56     /** Something must be not perfectly clean (but I may be paranoid freak...) */
57   public static final int WARNING = 1;
58
59     /** There has been a problem during you task treansfer.
60      *  Either the network is  down or the remote host has been shutdown */
61   public static final int TRANSFERT_FAILURE = 2;
62
63     /** System shutdown. 
64      *  The host on which you are running has just been rebooted.
65      *  Free your datastructures and return now ! */
66   public static final int HOST_FAILURE = 3;
67
68     /** Cancelled task. This task has been cancelled by somebody ! */
69   public static final int TASK_CANCELLLED = 4;
70
71     /** You've done something wrong. You'd better look at it... */
72   public static final int FATAL_ERROR = 5;
73
74
75
76    /** Retrieve the simulation time */
77   public final static native double getClock();
78
79   public final static native void pajeOutput(String pajeFile);
80
81
82    /** Issue an information logging message */
83   public final static native void info(String s);
84
85     /*********************************************************************************
86      * Deployment and initialization related functions                               *
87      *********************************************************************************/
88
89     /**
90      * The natively implemented method to initialize a MSG simulation.
91      *
92      * @param args            The arguments of the command line of the simulation.
93      *
94      * @see                    Msg.init()
95      */
96   public final static native void init(String[]args);
97
98     /**
99      * Run the MSG simulation, and cleanup everything afterward.
100      *
101      * If you want to chain simulations in the same process, you
102      * should call again createEnvironment and deployApplication afterward.
103      *
104      * @see                    MSG_run, MSG_clean
105      */
106   public final static native void run() throws NativeException;
107
108     /**
109      * The native implemented method to create the environment of the simulation.
110      *
111      * @param platformFile    The XML file which contains the description of the environment of the simulation
112      *
113      */
114   public final static native void createEnvironment(String platformFile)
115   throws NativeException;
116   
117    /**
118      * The method to deploy the simulation.
119      *
120      * @param platformFile    The XML file which contains the description of the application to deploy.
121      */
122   public final static native void deployApplication(String deploymentFile)
123   throws NativeException;
124  
125   /* The launcher */
126   static public void main(String[]args) throws MsgException {
127     /* initialize the MSG simulation. Must be done before anything else (even logging). */
128     Msg.init(args);
129
130     if (args.length < 2) {
131
132       Msg.info("Usage: Msg platform_file deployment_file");
133       System.exit(1);
134     }
135
136     /* Load the platform and deploy the application */
137       Msg.createEnvironment(args[0]);
138     Msg.deployApplication(args[1]);
139
140     /* Execute the simulation */
141     Msg.run();
142   }
143 }