2 * simgrid.msg.Msg.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
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.
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
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.
25 * @author Abdelmalek Cherier
26 * @author Martin Quinson
29 public final class Msg {
31 * Statically load the library which contains all native functions used in here
35 System.loadLibrary("simgrid");
36 MsgNative.selectContextFactory("java");
37 } catch(NativeException e) {
38 System.err.println(e.toString());
41 } catch(UnsatisfiedLinkError e) {
42 System.err.println("Cannot load simgrid library : ");
44 System.err.println("Please check your LD_LIBRARY_PATH, " +
45 "or copy the library to the current directory");
50 /** Returns the last error code of the simulation */
51 public final static native int getErrCode();
53 /** Everything is right. Keep on goin the way ! */
54 public static final int SUCCESS = 0;
56 /** Something must be not perfectly clean (but I may be paranoid freak...) */
57 public static final int WARNING = 1;
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;
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;
68 /** Cancelled task. This task has been cancelled by somebody ! */
69 public static final int TASK_CANCELLLED = 4;
71 /** You've done something wrong. You'd better look at it... */
72 public static final int FATAL_ERROR = 5;
76 /** Retrieve the simulation time */
77 public final static native double getClock();
79 public final static native void pajeOutput(String pajeFile);
82 /** Issue an information logging message */
83 public final static native void info(String s);
85 /*********************************************************************************
86 * Deployment and initialization related functions *
87 *********************************************************************************/
90 * The natively implemented method to initialize a MSG simulation.
92 * @param args The arguments of the command line of the simulation.
96 public final static native void init(String[]args);
99 * Run the MSG simulation, and cleanup everything afterward.
101 * If you want to chain simulations in the same process, you
102 * should call again createEnvironment and deployApplication afterward.
104 * @see MSG_run, MSG_clean
106 public final static native void run() throws NativeException;
109 * The native implemented method to create the environment of the simulation.
111 * @param platformFile The XML file which contains the description of the environment of the simulation
114 public final static native void createEnvironment(String platformFile)
115 throws NativeException;
119 * The method to deploy the simulation.
121 * @param appFile The XML file which contains the description of the application to deploy.
125 public static void deployApplication(String platformFile) {
128 Class.forName("com.sun.org.apache.xerces.internal.parsers.SAXParser");
129 XMLReader reader = (XMLReader) c.newInstance();
131 reader.setEntityResolver(new DTDResolver());
132 ApplicationHandler handler = new ApplicationHandler();
134 reader.setContentHandler(handler);
135 reader.setFeature("http://xml.org/sax/features/validation", false);
136 reader.parse(platformFile);
138 } catch(Exception e) {
139 /* FIXME: do not swallow exception ! */
140 System.out.println("Exception in Msg.launchApplication()");
141 System.out.println(e);
147 static public void main(String[]args) throws MsgException {
148 /* initialize the MSG simulation. Must be done before anything else (even logging). */
151 if (args.length < 2) {
153 Msg.info("Usage: Msg platform_file deployment_file");
157 /* Load the platform and deploy the application */
158 Msg.createEnvironment(args[0]);
159 Msg.deployApplication(args[1]);
161 /* Execute the simulation */