2 * JNI interface to C code for MSG.
4 * Copyright 2006,2007,2010,2011 The SimGrid Team.
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.
12 package org.simgrid.msg;
14 public final class Msg {
15 /* Statically load the library which contains all native functions used in here */
18 System.loadLibrary("SG_java");
19 } catch(UnsatisfiedLinkError e) {
20 System.err.println("Cannot load the bindings to the simgrid library: ");
23 "Please check your LD_LIBRARY_PATH, or copy the simgrid and SG_java libraries to the current directory");
28 /* FIXME: kill these C crufts */
29 /** Returns the last error code of the simulation
32 public final static native int getErrCode();
34 /** Everything is right. Keep on going the way ! */
35 public static final int SUCCESS = 0;
37 /** Something must be not perfectly clean (but I may be paranoid freak...) */
38 public static final int WARNING = 1;
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;
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;
49 /** Canceled task. This task has been canceled by somebody ! */
50 public static final int TASK_CANCELLLED = 4;
52 /** You've done something wrong. You'd better look at it... */
53 public static final int FATAL_ERROR = 5;
55 /** Retrieve the simulation time
58 public final static native double getClock();
60 /** Issue an information logging message
63 public final static native void info(String s);
65 /*********************************************************************************
66 * Deployment and initialization related functions *
67 *********************************************************************************/
70 * The natively implemented method to initialize a MSG simulation.
72 * @param args The arguments of the command line of the simulation.
76 public final static native void init(String[]args);
79 * Run the MSG simulation.
81 * The simulation is not cleaned afterward (see
82 * {@link #clean()} if you really insist on cleaning the C side), so you can freely
83 * retrieve the informations that you want from the simulation. In particular, retrieving the status
84 * of a process or the current date is perfectly ok.
88 public final static native void run() ;
91 * Cleanup the MSG simulation.
93 * This function is only useful if you want to chain the simulations within
94 * the same environment. But actually, it's not sure at all that cleaning the
95 * JVM is faster than restarting a new one, so it's probable that using this
96 * function is not a brilliant idea. Do so at own risk.
100 public final static native void clean();
104 * The native implemented method to create the environment of the simulation.
106 * @param platformFile The XML file which contains the description of the environment of the simulation
109 public final static native void createEnvironment(String platformFile);
112 * The method to deploy the simulation.
115 * @param deploymentFile
117 public final static native void deployApplication(String deploymentFile);
119 /** Example launcher. You can use it or provide your own launcher, as you wish
121 * @throws MsgException
123 static public void main(String[]args) throws MsgException {
124 /* initialize the MSG simulation. Must be done before anything else (even logging). */
127 if (args.length < 2) {
128 Msg.info("Usage: Msg platform_file deployment_file");
132 /* Load the platform and deploy the application */
133 Msg.createEnvironment(args[0]);
134 Msg.deployApplication(args[1]);
135 /* Execute the simulation */