* @since SimGrid 3.3
* @since JDK1.5011
*/
-public final class ApplicationHandler extends DefaultHandler
-{
-
- /*
- * This class is used to create the processes descibed in the deployment file.
- */
- class ProcessFactory
- {
- /**
+public final class ApplicationHandler extends DefaultHandler {
+
+ /*
+ * This class is used to create the processes descibed in the deployment file.
+ */
+ class ProcessFactory {
+ /**
* The vector which contains the arguments of the main function
* of the process object.
*/
- public Vector args;
-
- /**
+ public Vector args;
+
+ /**
* The name of the host of the process.
- */
- private String hostName;
-
- /**
+ */
+ private String hostName;
+
+ /**
* The function of the process.
*/
- private String function;
-
- /**
+ private String function;
+
+ /**
* Default constructor.
*/
- public ProcessFactory(){
- this.args = new Vector();
- this.hostName = null;
- this.function = null;
- }
-
- /**
+ public ProcessFactory() {
+ this.args = new Vector();
+ this.hostName = null;
+ this.function = null;
+ }
+ /**
* This method is called by the start element handler.
* It sets the host and the function of the process to create,
* and clear the vector containing the arguments of the
* @function The function of the process to create.
*
*/
- public void setProcessIdentity(String hostName, String function){
- this.hostName = hostName;
- this.function = function;
-
- if(!args.isEmpty())
- args.clear();
- }
-
- /**
+ public void setProcessIdentity(String hostName, String function) {
+ this.hostName = hostName;
+ this.function = function;
+
+ if (!args.isEmpty())
+ args.clear();
+ }
+ /**
* This method is called by the startElement() handler.
* It stores the argument of the function of the next
* process to create in the vector of arguments.
*
* @arg The argument to add.
*
- */
- public void registerProcessArg(String arg){
- this.args.add(arg);
- }
-
- public void createProcess(){
- try {
-
- Class cls = Class.forName(this.function);
- simgrid.msg.Process process = (simgrid.msg.Process)cls.newInstance();
- process.name = process.getName(); //this.function;
- process.id = simgrid.msg.Process.nextProcessId++;
- Host host = Host.getByName(this.hostName);
- Msg.processCreate(process,host);
- Vector args = processFactory.args;
- int size = args.size();
-
- for(int index = 0; index < size; index++)
- process.args.add(args.get(index));
-
- } catch(JniException e)
- {
- System.out.println(e.toString());
- e.printStackTrace();
-
- } catch(NativeException e)
- {
- System.out.println(e.toString());
- e.printStackTrace();
-
- } catch(HostNotFoundException e) {
- System.out.println(e.toString());
- e.printStackTrace();
-
- } catch(ClassNotFoundException e) {
- System.out.println(this.function + " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)");
- e.printStackTrace();
-
- } catch(InstantiationException e) {
- System.out.println("instantiation exception");
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- System.out.println("illegal access exception");
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- System.out.println("illegal argument exception");
- e.printStackTrace();
- }
-
- }
- }
-
- /*
- * the ProcessFactory object used to create the processes.
- */
- private ProcessFactory processFactory;
-
- public ApplicationHandler() {
- super();
+ */ public void registerProcessArg(String arg) {
+ this.args.add(arg);
+ }
+
+ public void createProcess() {
+ try {
+
+ Class cls = Class.forName(this.function);
+
+ simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
+ process.name = process.getName(); //this.function;
+ process.id = simgrid.msg.Process.nextProcessId++;
+ Host host = Host.getByName(this.hostName);
+
+ Msg.processCreate(process, host);
+ Vector args = processFactory.args;
+ int size = args.size();
+
+ for (int index = 0; index < size; index++)
+ process.args.add(args.get(index));
+
+ } catch(JniException e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+
+ } catch(NativeException e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+
+ } catch(HostNotFoundException e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+
+ } catch(ClassNotFoundException e) {
+ System.out.println(this.function +
+ " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)");
+ e.printStackTrace();
+
+ } catch(InstantiationException e) {
+ System.out.println("instantiation exception");
+ e.printStackTrace();
+ } catch(IllegalAccessException e) {
+ System.out.println("illegal access exception");
+ e.printStackTrace();
+ } catch(IllegalArgumentException e) {
+ System.out.println("illegal argument exception");
+ e.printStackTrace();
+ }
+
}
+ }
+
+ /*
+ * the ProcessFactory object used to create the processes.
+ */
+ private ProcessFactory processFactory;
+
+ public ApplicationHandler() {
+ super();
+ }
/**
* instanciates the process factory
*/
- public void startDocument(){
- this.processFactory = new ProcessFactory();
- }
-
- public void characters(char[] caracteres, int debut, int longueur) {} // NOTHING TODO
-
+ public void startDocument() {
+ this.processFactory = new ProcessFactory();
+ }
+
+ public void characters(char[]caracteres, int debut, int longueur) {
+ } // NOTHING TODO
+
/**
* element handlers
*/
- public void startElement(String nameSpace, String localName,String qName,Attributes attr) {
- if(localName.equals("process"))
- onProcessIdentity(attr);
- else if(localName.equals("argument"))
- onProcessArg(attr);
- }
-
+ public void startElement(String nameSpace, String localName, String qName,
+ Attributes attr) {
+ if (localName.equals("process"))
+ onProcessIdentity(attr);
+ else if (localName.equals("argument"))
+ onProcessArg(attr);
+ }
+
/**
* process attributs handler.
*/
- public void onProcessIdentity(Attributes attr) {
- processFactory.setProcessIdentity(attr.getValue(0),attr.getValue(1));
- }
-
- /**
+ public void onProcessIdentity(Attributes attr) {
+ processFactory.setProcessIdentity(attr.getValue(0), attr.getValue(1));
+ }
+
+ /**
* process arguments handler.
*/
- public void onProcessArg(Attributes attr) {
- processFactory.registerProcessArg(attr.getValue(0));
- }
-
+ public void onProcessArg(Attributes attr) {
+ processFactory.registerProcessArg(attr.getValue(0));
+ }
+
/**
* creates the process
*/
- public void endElement(String nameSpace, String localName,String qName) {
- if(localName.equals("process"))
-{
- processFactory.createProcess();
- }
+ public void endElement(String nameSpace, String localName, String qName) {
+ if (localName.equals("process")) {
+ processFactory.createProcess();
}
-
- public void endDocument() {} // NOTHING TODO
+ }
+
+ public void endDocument() {
+ } // NOTHING TODO
}
* @since SimGrid 3.3
* @since JDK1.5011
*/
-public final class Channel
-{
- /**
+public final class Channel {
+ /**
* The channel identifier (as a port number in the TCP protocol.
*/
- private int id;
-
- private Channel() {} /* disable the default constructor */
-
- /**
+ private int id;
+
+ private Channel() {
+ } /* disable the default constructor */
+ /**
* Construct the channel with the specified identifier.
*
* @param id The channel identifier.
- */
- public Channel(int id){
- this.id = id;
- }
-
- /**
+ */ public Channel(int id) {
+ this.id = id;
+ }
+
+ /**
* This static method sets the number of channels for all the hosts
* of the simulation.
*
* param channelNumber The channel number to set.
- */
- public static void setNumber(int channelNumber) {
- Msg.channelSetNumber(channelNumber);
- }
-
- /**
+ */
+ public static void setNumber(int channelNumber) {
+ Msg.channelSetNumber(channelNumber);
+ }
+
+ /**
* This static method gets the number of channel of the simulation.
*
* @return The channel numbers used in the simulation.
*/
- public static int getNumber() {
- return Msg.channelGetNumber();
- }
-
- /** Returns the identifier of the channel */
- public int getId() {
- return this.id;
- }
+ public static int getNumber() {
+ return Msg.channelGetNumber();
+ }
- /**
+ /** Returns the identifier of the channel */
+ public int getId() {
+ return this.id;
+ }
+
+ /**
* Listen on the channel and wait for receiving a task.
*
* @return The task readed from the channel.
*
*/
- public Task get() throws JniException,NativeException {
- return Msg.channelGet(this);
- }
-
- /**
+ public Task get() throws JniException, NativeException {
+ return Msg.channelGet(this);
+ }
+ /**
* Listen on the channel and wait for receiving a task with a timeout.
*
* @param timeout The timeout of the listening.
*
* @exception NativeException if the listening operation failed.
*/
- public Task getWithTimeout(double timeout) throws JniException, NativeException{
- return Msg.channelGetWithTimeout(this,timeout);
- }
-
- /**
+ public Task getWithTimeout(double timeout) throws JniException,
+ NativeException {
+ return Msg.channelGetWithTimeout(this, timeout);
+ }
+ /**
* Listen on the channel and wait for receiving a task from a host.
*
* @param host The host.
*
* @see Host
*/
- public Task getFromHost(Host host) throws NativeException, JniException{
- return Msg.channelGetFromHost(this,host);
- }
-
- /**
+ public Task getFromHost(Host host) throws NativeException, JniException {
+ return Msg.channelGetFromHost(this, host);
+ }
+ /**
* This method tests whether there is a pending communication on the channel.
*
* @return This method returns true if there is a pending communication
* on the channel. Otherwise the method returns false.
*/
- public boolean hasPendingCommunication() throws NativeException, JniException{
- return Msg.channelHasPendingCommunication(this);
- }
-
- /**
+ public boolean hasPendingCommunication() throws NativeException,
+ JniException {
+ return Msg.channelHasPendingCommunication(this);
+ }
+ /**
* This method tests whether there is a pending communication on a
* channel, and who sent it.
*
* @return The method returns -1 if there is no pending
* communication and the PID of the process who sent it otherwise
- */
- public int getCommunicatingProcess() throws JniException{
- return Msg.channelGetCommunicatingProcess(this) ;
- }
-
- /**
+ */ public int getCommunicatingProcess() throws JniException {
+ return Msg.channelGetCommunicatingProcess(this);
+ }
+ /**
* Wait for at most timeout seconds for a task reception
* on channel. The PID is updated with the PID of the first process.
*
* @return The PID of the first process to send a task.
*
* @exception MsgException if the reception failed.
- */
- public int wait(double timeout) throws NativeException, JniException{
- return Msg.channelWait(this,timeout);
- }
-
- /**
+ */
+ public int wait(double timeout) throws NativeException, JniException {
+ return Msg.channelWait(this, timeout);
+ }
+ /**
* This method returns the number of tasks waiting to be received on a
* channel and sent by a host.
*
* and sent by a host.
*
* @exception InvalidHostException if the specified host is not valid.
- */
- public int getHostWaitingTasks(Host host) throws JniException{
- return Msg.channelGetHostWaitingTasks(this,host);
- }
-
- /**
+ */ public int getHostWaitingTasks(Host host) throws JniException {
+ return Msg.channelGetHostWaitingTasks(this, host);
+ }
+ /**
* This method puts a task on a channel of an host and waits for the end of the
* transmission.
*
* @exception InvalidTaskException if the task is not valid.
* InvalidHostException if the host is not valid.
* MsgException if the operation failed.
- */
- public void put(Task task,Host host) throws NativeException, JniException {
- Msg.channelPut(this,task,host);
- }
-
- /**
+ */
+ public void put(Task task, Host host) throws NativeException,
+ JniException {
+ Msg.channelPut(this, task, host);
+ }
+ /**
* This method puts a task on a channel of an host (with a timeout on the waiting
* of the destination host) and waits for the end of the transmission.
*
* InvalidHostException if the host is not valid.
* MsgException if the operation failed.
*/
- public void putWithTimeout(Task task,Host host,double timeout) throws NativeException, JniException {
- Msg.channelPutWithTimeout(this,task,host,timeout);
- }
-
- /**
+ public void putWithTimeout(Task task, Host host,
+ double timeout) throws
+ NativeException, JniException {
+ Msg.channelPutWithTimeout(this, task, host, timeout);
+ }
+ /**
* This method does exactly the same as put() but with a bounded transmition
* rate.
*
* InvalidHostException if the host is not valid.
* MsgException if the operation failed.
*/
- public void putBounded(Task task,Host host,double maxRate) throws NativeException, JniException {
- Msg.channelPutBounded(this,task,host,maxRate);
- }
-}
+ public void putBounded(Task task, Host host,
+ double maxRate) throws NativeException,
+ JniException {
+ Msg.channelPutBounded(this, task, host, maxRate);
+}}
* This program is free software; you can redistribute \r
* it and/or modify it under the terms of the license \r
*(GNU LGPL) which comes with this package. \r
- */\r
+ */ \r
+ \r\r\rpackage simgrid.msg;
+\r\rimport java.io.InputStream;
+\rimport org.xml.sax.EntityResolver;
+\rimport org.xml.sax.InputSource;
+\rimport org.xml.sax.SAXException;
+\r\rpublic class DTDResolver implements EntityResolver {
+ \r\rpublic InputSource resolveEntity(String publicID, String systemID) \r
+ throws SAXException {
+ \r\r\rif (!systemID.endsWith("surfxml.dtd")) {
+ \rSystem.out.
+ println("\n MSG - Warning - the platform used seams invalid\n");
+ \rreturn null;
+ \r}
+ \r\r
+ /* try to get the DTD from the classpath */ \r
+ InputStream in = getClass().getResourceAsStream("/surfxml.dtd");
+ \r\rif (null == in)
+ \r
+ /* try to get the DTD from the surf dir in the jar */ \r
+ in = getClass().getResourceAsStream("/surf/surfxml.dtd");
+ \rif (null == in)
+ \r
+ /* try to get the DTD from the directory Simgrid */ \r
+ in = getClass().getResourceAsStream("/Simgrid/surfxml.dtd");
+ \r\rif (null == in)
+ \r
+ /* try to get the DTD from the directory Simgrid/msg */ \r
+ in = getClass().getResourceAsStream("/Simgrid/msg/surfxml.dtd");
+ \r\rif (null == in) {
+ \rSystem.err.println("\nMSG - XML DTD not found (" +
+ systemID.toString() +
+ ").\n\nPlease put this file in one of the following destinations :\n\n"
+ + \r" - classpath;\n" +
+ \r" - the directory Simgrid;\n" +
+ \r" - the directory Simgrid/msg;\n" +
+ \r" - the directory of you simulation.\n\n" +
+ \r"Once the DTD puted in one of the previouse destinations, retry you simulation.\n");
+ \r\r
+ /* \r
+ * If not founded, returning null makes process continue normally (try to get \r
+ * the DTD from the current directory \r
+ */ \r
+ return null;
+ \r}
+ \r\rreturn new InputSource(in);
+ \r}
+\r}
+
\r
- \r
-\r
-package simgrid.msg;\r
-\r
-import java.io.InputStream;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-\r
-public class DTDResolver implements EntityResolver {\r
- \r
- public InputSource resolveEntity(String publicID, String systemID)\r
- throws SAXException {\r
- \r
- \r
- if(!systemID.endsWith("surfxml.dtd")){\r
- System.out.println("\n MSG - Warning - the platform used seams invalid\n");\r
- return null;\r
- }\r
- \r
- /* try to get the DTD from the classpath */\r
- InputStream in = getClass().getResourceAsStream("/surfxml.dtd"); \r
- \r
- if(null == in) \r
- /* try to get the DTD from the surf dir in the jar */\r
- in = getClass().getResourceAsStream("/surf/surfxml.dtd");\r
- if(null == in)\r
- /* try to get the DTD from the directory Simgrid */\r
- in = getClass().getResourceAsStream("/Simgrid/surfxml.dtd"); \r
- \r
- if(null == in)\r
- /* try to get the DTD from the directory Simgrid/msg */\r
- in = getClass().getResourceAsStream("/Simgrid/msg/surfxml.dtd"); \r
- \r
- if(null == in) {\r
- System.err.println("\nMSG - XML DTD not found (" + systemID.toString() + ").\n\nPlease put this file in one of the following destinations :\n\n"+\r
- " - classpath;\n"+\r
- " - the directory Simgrid;\n"+\r
- " - the directory Simgrid/msg;\n"+\r
- " - the directory of you simulation.\n\n"+\r
- "Once the DTD puted in one of the previouse destinations, retry you simulation.\n");\r
- \r
- /* \r
- * If not founded, returning null makes process continue normally (try to get \r
- * the DTD from the current directory \r
- */\r
- return null;\r
- }\r
- \r
- return new InputSource(in); \r
- }\r
-}\r
* @since JDK1.5011
*/
public class Host {
- /**
+ /**
* This attribute represents a bind between a java host object and
* a native host. Even if this attribute is public you must never
* access to it. It is set automaticatly during the call of the
*
* @see Host.getByName().
*/
- public long bind;
-
- /**
+ public long bind;
+
+ /**
* User data.
*/
- private Object data;
-
- protected Host() {
- this.bind = 0;
- this.data = null;
- };
-
- /**
+ private Object data;
+
+ protected Host() {
+ this.bind = 0;
+ this.data = null;
+ };
+
+ /**
* This static method gets an host instance associated with a native
* host of your platform. This is the best way to get a java host object.
*
*
* @exception HostNotFoundException if the name of the host is not valid.
* MsgException if the native version of this method failed.
- */
- public static Host getByName(String name)
- throws HostNotFoundException, NativeException, JniException {
+ */
+ public static Host getByName(String name)
+ throws HostNotFoundException, NativeException, JniException {
- return Msg.hostGetByName(name);
- }
-
- /**
+ return Msg.hostGetByName(name);
+ }
+ /**
* This static method returns the number of the installed hosts.
*
* @return The number of the installed hosts.
*
- */
- public static int getNumber() throws NativeException, JniException {
- return Msg.hostGetNumber();
- }
-
- /**
+ */ public static int getNumber() throws NativeException, JniException {
+ return Msg.hostGetNumber();
+ }
+ /**
* This static method return an instance to the host of the current process.
*
* @return The host on which the current process is executed.
*
* @exception MsgException if the native version of this method failed.
- */
- public static Host currentHost() throws JniException{
- return Msg.hostSelf();
- }
-
- /**
+ */ public static Host currentHost() throws JniException {
+ return Msg.hostSelf();
+ }
+ /**
* This static method returns all of the hosts of the installed platform.
*
* @return An array containing all the hosts installed.
*
* @exception MsgException if the native version of this method failed.
- */
- public static Host[] all() throws JniException, NativeException{
- return Msg.allHosts();
- }
-
- /**
+ */ public static Host[] all() throws JniException, NativeException {
+ return Msg.allHosts();
+ }
+ /**
* This method returns the name of a host.
*
* @return The name of the host.
*
* @exception InvalidHostException if the host is not valid.
- */
- public String getName() throws NativeException, JniException{
- return Msg.hostGetName(this);
- }
-
- /**
+ */ public String getName() throws NativeException, JniException {
+ return Msg.hostGetName(this);
+ }
+ /**
* This method sets the data of the host.
*
- */
- public void setData(Object data) {
- this.data = data;
- }
-
- /**
+ */ public void setData(Object data) {
+ this.data = data;
+ }
+
+ /**
* This method gets the data of the host.
*/
- public Object getData() {
- return this.data;
- }
-
- /**
+ public Object getData() {
+ return this.data;
+ }
+
+ /**
* This function tests if a host has data.
*/
- public boolean hasData() {
- return null != this.data;
- }
-
- /**
+ public boolean hasData() {
+ return null != this.data;
+ }
+
+ /**
* This method returns the number of tasks currently running on a host.
* The external load is not taken in account.
*
* @exception InvalidHostException if the host is invalid.
*
*/
- public int getLoad() throws JniException{
- return Msg.hostGetLoad(this);
- }
-
- /**
+ public int getLoad() throws JniException {
+ return Msg.hostGetLoad(this);
+ }
+ /**
* This method returns the speed of the processor of a host,
* regardless of the current load of the machine.
*
*
* @exception InvalidHostException if the host is not valid.
*
- */
-
- public double getSpeed() throws JniException {
- return Msg.hostGetSpeed(this);
- }
-
- /**
+ */ public double getSpeed() throws JniException {
+ return Msg.hostGetSpeed(this);
+ }
+ /**
* This method tests if a host is avail.
*
* @return If the host is avail the method returns true.
* @exception JniException if the host is not valid.
*
*
- */
- public boolean isAvail()throws JniException {
- return Msg.hostIsAvail(this);
- }
-
-}
+ */ public boolean isAvail() throws JniException {
+ return Msg.hostIsAvail(this);
+}}
* it and/or modify it under the terms of the license
* (GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
public class HostNotFoundException extends MsgException {
-
- private static final long serialVersionUID = 1L;
+
+ private static final long serialVersionUID = 1L;
/**
* Constructs an <code>HostNotFoundException</code> without a
* detail message.
*/
- public HostNotFoundException() {
- super();
- }
-
+ public HostNotFoundException() {
+ super();
+ }
/**
* Constructs an <code>HostNotFoundException</code> with a detail message.
*
* @param s the detail message.
- */
- public HostNotFoundException(String s) {
- super(s);
- }
-}
\ No newline at end of file
+ */ public HostNotFoundException(String s) {
+ super(s);
+ }
+}
* it and/or modify it under the terms of the license
* (GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
public class JniException extends MsgException {
-
- private static final long serialVersionUID = 1L;
+
+ private static final long serialVersionUID = 1L;
/**
* Constructs an <code>JniException</code> without a
* detail message.
*/
- public JniException() {
- super();
- }
-
+ public JniException() {
+ super();
+ }
/**
* Constructs an <code>JniException</code> with a detail message.
*
* @param s the detail message.
- */
- public JniException(String s) {
- super(s);
- }
-}
\ No newline at end of file
+ */ public JniException(String s) {
+ super(s);
+ }
+}
* it and/or modify it under the terms of the license
*(GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
import org.xml.sax.*;
*
* @return The last error code of the simulation.
*/
- final static native int getErrCode();
-
+ final static native int getErrCode();
+
/**
* Errors returned by the method Msg.getErrCode().
*/
-
- /* Everything is right. Keep on goin the way !
- *
- */
- public static final int SUCCESS = 0;
-
- /* Something must be not perfectly clean. But I
- * may be paranoid freak... !
- */
- public static final int WARNING = 1;
-
- /* There has been a problem during you task treansfer.
- * Either the network is down or the remote host has
- * been shutdown.
- */
- public static final int TRANSFERT_FAILURE = 2;
-
+
+ /* Everything is right. Keep on goin the way !
+ *
+ */
+ public static final int SUCCESS = 0;
+
+ /* Something must be not perfectly clean. But I
+ * may be paranoid freak... !
+ */
+ public static final int WARNING = 1;
+
+ /* There has been a problem during you task treansfer.
+ * Either the network is down or the remote host has
+ * been shutdown.
+ */
+ public static final int TRANSFERT_FAILURE = 2;
+
/**
* System shutdown. The host on which you are running
* has just been rebooted. Free your datastructures and
* return now !
*/
- public static final int HOST_FAILURE = 3;
-
+ public static final int HOST_FAILURE = 3;
+
/**
* Cancelled task. This task has been cancelled by somebody !
*/
- public static final int TASK_CANCELLLED = 4;
-
+ public static final int TASK_CANCELLLED = 4;
+
/**
* You've done something wrong. You'd better look at it...
*/
- public static final int FATAL_ERROR = 5;
-
+ public static final int FATAL_ERROR = 5;
+
/**
* Staticaly load the SIMGRID4JAVA library
* which contains all native functions used in here
*/
- static {
- try {
- System.loadLibrary("simgrid");
- Msg.selectContextFactory("jcontext_factory");
- } catch(NativeException e)
- {
- System.err.println(e.toString());
- e.printStackTrace();
- System.exit(1);
- } catch(UnsatisfiedLinkError e){
- System.err.println("Cannot load simgrid library : ");
- e.printStackTrace();
- System.err.println("Please check your LD_LIBRARY_PATH, "+
- "or copy the library to the current directory");
- System.exit(1);
- }
+ static {
+ try {
+ System.loadLibrary("simgrid");
+ Msg.selectContextFactory("jcontext_factory");
+ } catch(NativeException e) {
+ System.err.println(e.toString());
+ e.printStackTrace();
+ System.exit(1);
+ } catch(UnsatisfiedLinkError e) {
+ System.err.println("Cannot load simgrid library : ");
+ e.printStackTrace();
+ System.err.println("Please check your LD_LIBRARY_PATH, " +
+ "or copy the library to the current directory");
+ System.exit(1);
}
-
- final static native
+ }
+
+ final static native
void selectContextFactory(String name) throws NativeException;
-
+
/******************************************************************
* The natively implemented methods connected to the MSG Process *
******************************************************************/
-
+
/**
* The natively implemented method to create an MSG process.
*
*
* @see Process constructors.
*/
- final static native
- void processCreate(Process process, Host host) throws JniException;
-
+ final static native
+ void processCreate(Process process, Host host) throws JniException;
+
/**
* The natively implemented method to kill all the process of the simulation.
*
*
* @return The function returns the PID of the next created process.
*/
- final static native int processKillAll(int resetPID);
-
+ final static native int processKillAll(int resetPID);
+
/**
* The natively implemented method to suspend an MSG process.
*
*
* @see Process.pause()
*/
- final static native void processSuspend(Process process)
- throws JniException, NativeException;
-
+ final static native void processSuspend(Process process)
+ throws JniException, NativeException;
+
/**
* The natively implemented method to kill a MSG process.
*
*
* @see Process.kill()
*/
- final static native void processKill(Process process)
- throws JniException;
-
+ final static native void processKill(Process process)
+ throws JniException;
+
/**
* The natively implemented method to resume a suspended MSG process.
*
*
* @see Process.restart()
*/
- final static native void processResume(Process process)
- throws JniException, NativeException;
-
+ final static native void processResume(Process process)
+ throws JniException, NativeException;
+
/**
* The natively implemented method to test if MSG process is suspended.
*
*
* @see Process.isSuspended()
*/
- final static native boolean processIsSuspended(Process process) throws JniException;
-
+ final static native boolean processIsSuspended(Process process) throws
+ JniException;
+
/**
* The natively implemented method to get the host of a MSG process.
*
*
* @see Process.getHost()
*/
- final static native Host processGetHost(Process process)
- throws JniException, NativeException;
-
+ final static native Host processGetHost(Process process)
+ throws JniException, NativeException;
+
/**
* The natively implemented method to get a MSG process from his PID.
*
*
* @see Process.getFromPID()
*/
- final static native Process processFromPID(int PID) throws NativeException;
-
+ final static native Process processFromPID(int PID) throws NativeException;
+
/**
* The natively implemented method to get the PID of a MSG process.
*
*
* @see Process.getPID()
*/
- final static native int processGetPID(Process process) throws NativeException;
-
+ final static native int processGetPID(Process process) throws
+ NativeException;
+
/**
* The natively implemented method to get the PPID of a MSG process.
*
*
* @see Process.getPPID()
*/
- final static native int processGetPPID(Process process) throws NativeException;
-
+ final static native int processGetPPID(Process process) throws
+ NativeException;
+
/**
* The natively implemented method to get the current running process.
*
* @see Process.currentProcess()
*/
- final static native Process processSelf() throws NativeException;
-
+ final static native Process processSelf() throws NativeException;
+
/**
* The natively implemented method to get the current running process PID.
*
*
* @see Process.currentProcessPID()
*/
- final static native int processSelfPID();
-
+ final static native int processSelfPID();
+
/**
* The natively implemented method to get the current running process PPID.
*
*
* @see Process.currentProcessPPID()
*/
- final static native int processSelfPPID();
-
+ final static native int processSelfPPID();
+
/**
* The natively implemented method to migrate a process from his currnet host to a new host.
*
* @see Process.migrate()
* @see Host.getByName()
*/
- final static native void processChangeHost(Process process,Host host)
- throws JniException, NativeException;
-
+ final static native void processChangeHost(Process process, Host host)
+ throws JniException, NativeException;
+
/**
* Process synchronization. The process wait the signal of the simulator to start.
*
* @exception JniException if something goes wrong with JNI
*/
- final static native void waitSignal(Process process) throws JniException;
-
+ final static native void waitSignal(Process process) throws JniException;
+
/**
* The natively implemented native to request the current process to sleep
* until time seconds have elapsed.
*
* @see Process.waitFor()
*/
- final static native void processWaitFor(double seconds) throws NativeException;
-
+ final static native void processWaitFor(double seconds) throws
+ NativeException;
+
/**
* The natively implemented native method to exit a process.
*
*
* @see Process.exit()
*/
- final static native void processExit(Process process) throws JniException;
-
-
+ final static native void processExit(Process process) throws JniException;
+
+
/******************************************************************
* The natively implemented methods connected to the MSG host *
******************************************************************/
-
+
/**
* The natively implemented method to get an host from his name.
*
*
* @see Host.getByName()
*/
- final static native Host hostGetByName(String name)
- throws JniException, HostNotFoundException, NativeException;
-
+ final static native Host hostGetByName(String name)
+ throws JniException, HostNotFoundException, NativeException;
+
/**
* The natively implemented method to get the name of an MSG host.
*
*
* @see Host.getName()
*/
- final static native String hostGetName(Host host) throws JniException;
-
+ final static native String hostGetName(Host host) throws JniException;
+
/**
* The natively implemented method to get the number of hosts of the simulation.
*
*
* @see Host.getNumber()
*/
- final static native int hostGetNumber();
-
+ final static native int hostGetNumber();
+
/**
* The natively implemented method to get the host of the current runing process.
*
*
* @see Host.currentHost()
*/
- final static native Host hostSelf() throws JniException;
-
+ final static native Host hostSelf() throws JniException;
+
/**
* The natively implemented method to get the speed of a MSG host.
*
*
* @see Host.getSpeed()
*/
-
- final static native double hostGetSpeed(Host host) throws JniException;
-
+
+ final static native double hostGetSpeed(Host host) throws JniException;
+
/**
* The natively implemented native method to test if an host is avail.
*
*
* @see Host.isAvail()
*/
- final static native boolean hostIsAvail(Host host) throws JniException;
-
+ final static native boolean hostIsAvail(Host host) throws JniException;
+
/**
* The natively implemented native method to get all the hosts of the simulation.
*
*
* @return A array which contains all the hosts of simulation.
*/
-
- final static native Host[] allHosts() throws JniException;
-
+
+ final static native Host[] allHosts() throws JniException;
+
/**
* The natively implemented native method to get the number of running tasks on a host.
*
* @exception JniException if something goes wrong with JNI
*
*/
- final static native int hostGetLoad(Host host) throws JniException;
-
+ final static native int hostGetLoad(Host host) throws JniException;
+
/******************************************************************
* The natively implemented methods connected to the MSG task *
******************************************************************/
-
+
/**
* The natively implemented method to create a MSG task.
*
*
* @see Task.create()
*/
- final static native void taskCreate(Task task,String name,double computeDuration, double messageSize)
- throws JniException, NullPointerException, IllegalArgumentException;
-
+ final static native void taskCreate(Task task, String name,
+ double computeDuration,
+ double messageSize)
+ throws JniException, NullPointerException, IllegalArgumentException;
+
/**
* The natively implemented method to get the sender of a task.
*
*
* @see Task.getSender()
*/
- final static native Process taskGetSender(Task task) throws JniException;
-
+ final static native Process taskGetSender(Task task) throws JniException;
+
/**
* The natively implementd method to get the source of a task.
*
*
* @see Task.getSource()
*/
- final static native Host taskGetSource(Task task) throws JniException, NativeException;
-
+ final static native Host taskGetSource(Task task) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to get the name of the task.
*
*
* @see Task.getName()
*/
- final static native String taskGetName(Task task) throws JniException;
-
+ final static native String taskGetName(Task task) throws JniException;
+
/**
* The natively implemented method to cancel a task.
*
*
* @see Task.cancel().
*/
- final static native void taskCancel(Task task) throws JniException, NativeException;
-
+ final static native void taskCancel(Task task) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to get the computing amount of the task.
*
*
* @see Task.getComputeDuration()
*/
- final static native double taskGetComputeDuration(Task task) throws JniException;
-
+ final static native double taskGetComputeDuration(Task task) throws
+ JniException;
+
/**
* The natively implemented method to get the remaining computation
*
*
* @see Task.getRemainingDuration()
*/
- final static native double taskGetRemainingDuration(Task task) throws JniException;
-
+ final static native double taskGetRemainingDuration(Task task) throws
+ JniException;
+
/**
* The natively implemented method to set the priority of a task.
*
*
* @see Task.setPriority()
*/
- final static native void taskSetPriority(Task task,double priority) throws JniException;
-
+ final static native void taskSetPriority(Task task,
+ double priority) throws
+ JniException;
+
/**
* The natively implemented method to destroy a MSG task.
*
*
* @see Task.destroy()
*/
- final static native void taskDestroy(Task task) throws JniException, NativeException;
-
+ final static native void taskDestroy(Task task) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to execute a MSG task.
*
*
* @see Task.execute()
*/
- final static native void taskExecute(Task task) throws JniException, NativeException;
-
-
-
+ final static native void taskExecute(Task task) throws JniException,
+ NativeException;
+
+
+
/**************************************************************************
* The natively implemented methods connected to the MSG parallel task *
***************************************************************************/
-
+
/**
* The natively implemented method to create a MSG parallel task.
*
*
* @see ParallelTask.create()
*/
- final static native void parallelTaskCreate(ParallelTask parallelTask, String name,
- Host[] hosts, double[] computeDurations, double[] messageSizes)
- throws JniException, NullPointerException, IllegalArgumentException;
-
+ final static native void parallelTaskCreate(ParallelTask parallelTask,
+ String name, Host[]hosts,
+ double[]computeDurations,
+ double[]messageSizes)
+ throws JniException, NullPointerException, IllegalArgumentException;
+
/**
* The natively implemented method to get the sender of a parallel task.
*
*
* @see ParallelTask.getSender()
*/
- final static native Process parallelTaskGetSender(ParallelTask parallelTask) throws JniException;
-
+ final static native Process parallelTaskGetSender(ParallelTask parallelTask)
+ throws JniException;
+
/**
* The natively implementd method to get the source of a parallel task.
*
*
* @see ParallelTask.getSource()
*/
- final static native Host parallelTaskGetSource(ParallelTask parallelTask) throws JniException;
-
+ final static native Host parallelTaskGetSource(ParallelTask parallelTask)
+ throws JniException;
+
/**
* The natively implemented method to get the name of the parallel task.
*
*
* @see ParallelTask.getName()
*/
- final static native String parallelTaskGetName(ParallelTask parallelTask) throws JniException;
-
+ final static native String parallelTaskGetName(ParallelTask parallelTask)
+ throws JniException;
+
/**
* The natively implemented method to cancel a parallel task.
*
*
* @see ParallelTask.cancel().
*/
- final static native void parallelTaskCancel(ParallelTask parallelTask) throws JniException,NativeException;
-
+ final static native void parallelTaskCancel(ParallelTask parallelTask)
+ throws JniException, NativeException;
+
/**
* The natively implemented method to get the computing amount of the task.
*
*
* @see ParallelTask.getComputeDuration()
*/
- final static native double parallelTaskGetComputeDuration(ParallelTask parallelTask) throws JniException;
-
+ final static native double parallelTaskGetComputeDuration(ParallelTask
+ parallelTask)
+ throws JniException;
+
/**
* The natively implemented method to get the remaining computation
*
*
* @see ParallelTask.getRemainingDuration()
*/
- final static native double parallelTaskGetRemainingDuration(ParallelTask parallelTask) throws JniException;
-
+ final static native double parallelTaskGetRemainingDuration(ParallelTask
+ parallelTask)
+ throws JniException;
+
/**
* The natively implemented method to set the priority of a parallel task.
*
*
* @see ParallelTask.setPriority()
*/
- final static native void parallelTaskSetPriority(ParallelTask parallelTask,double priority) throws JniException;
-
+ final static native void parallelTaskSetPriority(ParallelTask parallelTask,
+ double priority) throws
+ JniException;
+
/**
* The natively implemented method to destroy a MSG parallel task.
*
*
* @see ParallelTask.destroy()
*/
- final static native void parallelTaskDestroy(ParallelTask parallelTask) throws JniException,NativeException;
-
+ final static native void parallelTaskDestroy(ParallelTask parallelTask)
+ throws JniException, NativeException;
+
/**
* The natively implemented method to execute a MSG parallel task.
*
*
* @see ParallelTask.execute()
*/
- final static native void parallelTaskExecute(ParallelTask parallelTask) throws JniException, NativeException;
-
+ final static native void parallelTaskExecute(ParallelTask parallelTask)
+ throws JniException, NativeException;
+
/******************************************************************
* The natively implemented methods connected to the MSG channel *
******************************************************************/
-
+
/**
* The natively implemented method to listen on the channel and wait for receiving a task.
*
*
* @see Channel.get()
*/
- final static native Task channelGet(Channel channel) throws JniException,NativeException;
-
+ final static native Task channelGet(Channel channel) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to listen on the channel and wait for receiving a task with a timeout.
*
*
* @see Channel.getWithTimeout()
*
- */
- final static native Task channelGetWithTimeout(Channel channel,double timeout) throws JniException,NativeException;
-
-
+ */
+ final static native Task channelGetWithTimeout(Channel channel,
+ double timeout) throws
+ JniException, NativeException;
+
+
/**
* The natively implemented method to listen on the channel of a specific host.
*
* MsgException if the listening operation failed.
*
* @see Channel.getFromHost()
- */
- final static native Task channelGetFromHost(Channel channel,Host host) throws JniException,NativeException;
-
+ */
+ final static native Task channelGetFromHost(Channel channel,
+ Host host) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to test whether there is a pending communication on the channel.
*
* channel. Otherwise the method returns false.
*
* @see Channel.hasPendingCommunication()
- */
- final static native boolean channelHasPendingCommunication(Channel channel) throws JniException;
-
+ */
+ final static native boolean channelHasPendingCommunication(Channel channel)
+ throws JniException;
+
/**
* The natively implemented method to test whether there is a pending communication on a
* channel, and who sent it.
*
* @see Channel.getCummunicatingProcess()
*/
- final static native int channelGetCommunicatingProcess(Channel channel) throws JniException;
-
+ final static native int channelGetCommunicatingProcess(Channel channel)
+ throws JniException;
+
/**
* The natively implemented method to get the number of tasks waiting to be received on a
* channel and sent by a host.
*
* @see Channel.getHostWaiting()
*/
- final static native int channelGetHostWaitingTasks(Channel channel,Host host) throws JniException;
-
+ final static native int channelGetHostWaitingTasks(Channel channel,
+ Host host) throws
+ JniException;
+
/**
* The natively implemented method to put a task on the channel of an host.
*
* MsgException if the operation failed.
*
* @see Channel.put()
- */
- final static native void channelPut(Channel channel,Task task,Host host) throws JniException,NativeException;
-
+ */
+ final static native void channelPut(Channel channel, Task task,
+ Host host) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to put a task on a channel of an host (with a timeout
* on the waiting of the destination host) and waits for the end of the transmission.
*
* @see Channel.putWithTimeout()
*/
- final static native void channelPutWithTimeout(Channel channel,Task task,Host host,double timeout) throws JniException,NativeException;
-
+ final static native void channelPutWithTimeout(Channel channel, Task task,
+ Host host,
+ double timeout) throws
+ JniException, NativeException;
+
/**
* The natively implemented method to put a task on channel with a bounded transmition
* rate.
*
* @see Channel.putBounded()
*/
- final static native void channelPutBounded(Channel channel,Task task,Host host,double max_rate) throws JniException,NativeException;
-
+ final static native void channelPutBounded(Channel channel, Task task,
+ Host host,
+ double max_rate) throws
+ JniException, NativeException;
+
/**
* The natively implemented method to wait for at most timeout seconds for a task reception
* on channel. The PID is updated with the PID of the first process.
*
* @see Channel.wait()
*/
- final static native int channelWait(Channel channel, double timeout) throws JniException,NativeException;
-
+ final static native int channelWait(Channel channel,
+ double timeout) throws JniException,
+ NativeException;
+
/**
* The natively implemented method to set the number of channel used by all the process
* of the simulation.
*
* @see Channel.setNumber()
*/
- final static native void channelSetNumber(int channelNumber);
-
+ final static native void channelSetNumber(int channelNumber);
+
/**
* The natively implemented method to get the number of channel of the process of the simulation.
*
*
* @see Channel.getNumber()
*/
- final static native int channelGetNumber();
-
+ final static native int channelGetNumber();
+
/*********************************************************************************
* Additional native methods *
**********************************************************************************/
-
+
/**
* The natively implemented method to get the simulation time.
*
* @param The simulation time.
*/
- public final static native double getClock();
-
- public final static native void pajeOutput(String pajeFile);
-
-
- public final static native void info(String s);
-
+ public final static native double getClock();
+
+ public final static native void pajeOutput(String pajeFile);
+
+
+ public final static native void info(String s);
+
/*********************************************************************
* The natively implemented methods connected to the MSG simulation *
*********************************************************************/
-
+
/**
* The natively implemented method to initialize a MSG simulation.
*
*
* @see Msg.init()
*/
- public final static native void init(String[] args);
-
+ public final static native void init(String[]args);
+
/**
* Run the MSG simulation, and cleanup everything afterward.
*
*
* @see MSG_run, MSG_clean
*/
- public final static native void run() throws NativeException;
-
+ public final static native void run() throws NativeException;
+
/**
* The native implemented method to create the environment of the simulation.
*
* @param platformFile The XML file which contains the description of the environment of the simulation
*
*/
- public final static native void createEnvironment(String platformFile) throws NativeException;
-
-
+ public final static native void createEnvironment(String platformFile)
+ throws NativeException;
+
+
/**
* The method to deploy the simulation.
*
* @param appFile The XML file which contains the description of the application to deploy.
*/
-
-
- public static void deployApplication(String platformFile) {
- try {
- Class c = Class.forName("com.sun.org.apache.xerces.internal.parsers.SAXParser");
- XMLReader reader = (XMLReader)c.newInstance();
- reader.setEntityResolver(new DTDResolver());
- ApplicationHandler handler = new ApplicationHandler();
- reader.setContentHandler(handler);
- reader.setFeature("http://xml.org/sax/features/validation", false);
- reader.parse(platformFile);
-
- } catch(Exception e) {
- /* FIXME: do not swallow exception ! */
- System.out.println("Exception in Msg.launchApplication()");
- System.out.println(e);
- e.printStackTrace();
- }
- }
-
- /* The launcher */
- static public void main(String[]args) throws MsgException {
- /* initialize the MSG simulation. Must be done before anything else (even logging). */
- Msg.init(args);
-
- if(args.length < 2) {
-
- Msg.info("Usage: Msg platform_file deployment_file");
- System.exit(1);
- }
-
- /* specify the number of channel for the process of the simulation. */
- Channel.setNumber(1);
-
- /* Load the platform and deploy the application */
- Msg.createEnvironment(args[0]);
- Msg.deployApplication(args[1]);
-
- /* Execute the simulation */
- Msg.run();
+
+
+ public static void deployApplication(String platformFile) {
+ try {
+ Class c =
+ Class.forName("com.sun.org.apache.xerces.internal.parsers.SAXParser");
+ XMLReader reader = (XMLReader) c.newInstance();
+
+ reader.setEntityResolver(new DTDResolver());
+ ApplicationHandler handler = new ApplicationHandler();
+
+ reader.setContentHandler(handler);
+ reader.setFeature("http://xml.org/sax/features/validation", false);
+ reader.parse(platformFile);
+
+ } catch(Exception e) {
+ /* FIXME: do not swallow exception ! */
+ System.out.println("Exception in Msg.launchApplication()");
+ System.out.println(e);
+ e.printStackTrace();
}
+ }
+
+ /* The launcher */
+ static public void main(String[]args) throws MsgException {
+ /* initialize the MSG simulation. Must be done before anything else (even logging). */
+ Msg.init(args);
+
+ if (args.length < 2) {
+
+ Msg.info("Usage: Msg platform_file deployment_file");
+ System.exit(1);
+ }
+
+ /* specify the number of channel for the process of the simulation. */
+ Channel.setNumber(1);
+
+ /* Load the platform and deploy the application */
+ Msg.createEnvironment(args[0]);
+ Msg.deployApplication(args[1]);
+
+ /* Execute the simulation */
+ Msg.run();
+ }
}
* it and/or modify it under the terms of the license
*(GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
import java.lang.Exception;
public class MsgException extends Exception {
-
- private static final long serialVersionUID = 1L;
+
+ private static final long serialVersionUID = 1L;
/**
* Constructs an <code>MsgException</code> without a
* detail message.
*/
- public MsgException() {
- super();
- }
-
+ public MsgException() {
+ super();
+ }
/**
* Constructs an <code>MsgException</code> with a detail message.
*
* @param s the detail message.
- */
- public MsgException(String s) {
- super(s);
- }
-}
\ No newline at end of file
+ */ public MsgException(String s) {
+ super(s);
+ }
+}
* it and/or modify it under the terms of the license
* (GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
public class NativeException extends MsgException {
-
- private static final long serialVersionUID = 1L;
+
+ private static final long serialVersionUID = 1L;
/**
* Constructs an <code>NativeException</code> without a
* detail message.
*/
- public NativeException() {
- super();
- }
-
+ public NativeException() {
+ super();
+ }
/**
* Constructs an <code>NativeException</code> with a detail message.
*
* @param s the detail message.
- */
- public NativeException(String s) {
- super(s);
- }
-}
\ No newline at end of file
+ */ public NativeException(String s) {
+ super(s);
+ }
+}
* it and/or modify it under the terms of the license
*(GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
class ParallelTask {
-
+
/**
* This attribute represents a bind between a java task object and
* a native task. Even if this attribute is public you must never
* access to it. It is set automaticatly during the build of the object.
*/
- public long bind = 0;
-
-
- /* Default constructor (disabled) */
- protected ParallelTask() {};
-
+ public long bind = 0;
+
+
+ /* Default constructor (disabled) */
+ protected ParallelTask() {
+ };
+
/**
* Construct an new parallel task with the specified processing amount and amount for each host
* implied.
* InvalidComputeDuration if the parameter computeDurations is null.
* InvalidMessageSize if the parameter messageSizes is null.
*/
- public ParallelTask(String name, Host[] hosts,double[] computeDurations, double[] messageSizes)
- throws JniException {
- create(name,hosts,computeDurations,messageSizes);
- }
-
+ public ParallelTask(String name, Host[]hosts, double[]computeDurations,
+ double[]messageSizes)
+ throws JniException {
+ create(name, hosts, computeDurations, messageSizes);
+ }
/**
* This method creates a parallel task (if not already created).
*
* InvalidComputeDuration if the parameter computeDurations is null.
* InvalidMessageSize if the parameter messageSizes is null.
*/
- public void create(String name, Host[] hosts,double[] computeDurations, double[] messageSizes)
- throws JniException {
-
- if(bind != 0)
- Msg.parallelTaskCreate(this,name,hosts,computeDurations,messageSizes);
- }
-
+ public void create(String name, Host[]hosts, double[]computeDurations,
+ double[]messageSizes)
+ throws JniException {
+
+ if (bind != 0)
+ Msg.parallelTaskCreate(this, name, hosts, computeDurations,
+ messageSizes);
+ }
/**
* This method gets the sender of the parallel task.
*
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
*
- */
- Process getSender() throws JniException {
- return Msg.parallelTaskGetSender(this);
- }
-
+ */ Process getSender() throws JniException {
+ return Msg.parallelTaskGetSender(this);
+ }
/**
* This method gets the source of the parallel task.
*
*
* @exception InvalidTaskException is the specified parallel task is not valid. A task
* is invalid if it is not binded with a native parallel task.
- */
- public Host getSource() throws JniException {
- return Msg.parallelTaskGetSource(this);
- }
-
+ */ public Host getSource() throws JniException {
+ return Msg.parallelTaskGetSource(this);
+ }
/**
* This method gets the name of a parallel task.
*
*
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
- */
- public String getName() throws JniException {
- return Msg.parallelTaskGetName(this);
- }
-
+ */ public String getName() throws JniException {
+ return Msg.parallelTaskGetName(this);
+ }
/**
* This method cancels a task.
*
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
* MsgException if the cancelation failed.
- */
- public void cancel() throws JniException, NativeException {
- Msg.parallelTaskCancel(this);
- }
-
+ */ public void cancel() throws JniException, NativeException {
+ Msg.parallelTaskCancel(this);
+ }
/**
* This method gets the computing amount of the parallel task.
*
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public double getComputeDuration() throws JniException {
- return Msg.parallelTaskGetComputeDuration(this);
- }
-
+ */ public double getComputeDuration() throws JniException {
+ return Msg.parallelTaskGetComputeDuration(this);
+ }
/**
* This method gets the remaining computation.
*
*
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
- */
- public double getRemainingDuration() throws JniException {
- return Msg.parallelTaskGetRemainingDuration(this);
- }
-
+ */ public double getRemainingDuration() throws JniException {
+ return Msg.parallelTaskGetRemainingDuration(this);
+ }
/**
* This method sets the priority of the computation of the parallel task.
* The priority doesn't affect the transfert rate. For example a
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public void setPrirority(double priority) throws JniException {
- Msg.parallelTaskSetPriority(this,priority);
- }
-
+ */ public void setPrirority(double priority) throws JniException {
+ Msg.parallelTaskSetPriority(this, priority);
+ }
/**
* This method destroies a parallel task.
*
* @exception InvalidTaskException is the specified task is not valid. A parallel task
* is invalid if it is not binded with a native task.
* MsgException if the destruction failed.
- */
- public void destroy() throws JniException, NativeException {
- Msg.parallelTaskDestroy(this);
- }
-
+ */ public void destroy() throws JniException, NativeException {
+ Msg.parallelTaskDestroy(this);
+ }
/**
* This method deletes a parallel task.
*
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
* MsgException if the destruction failed.
- */
- protected void finalize() throws JniException, NativeException {
- if(this.bind != 0)
- Msg.parallelTaskDestroy(this);
- }
-
+ */ protected void finalize() throws JniException, NativeException {
+ if (this.bind != 0)
+ Msg.parallelTaskDestroy(this);
+ }
/**
* This method execute a task on the location on which the
* process is running.
* @exception InvalidTaskException is the specified parallel task is not valid. A parallel task
* is invalid if it is not binded with a native parallel task.
* MsgException if the destruction failed.
- */
- public void execute() throws JniException, NativeException {
- Msg.parallelTaskExecute(this);
- }
-}
+ */ public void execute() throws JniException, NativeException {
+ Msg.parallelTaskExecute(this);
+}}
import java.lang.Thread;
import java.util.*;
+
/*
* A process may be defined as a code, with some private data, executing
* in a location (host). All the process used by your simulation must be
* @since SimGrid 3.3
* @since JDK1.5011
*/
-
-public abstract class Process extends Thread
-{
+
+public abstract class Process extends Thread {
/**
* This attribute represents a bind between a java process object and
* a native process. Even if this attribute is public you must never
* access to it. It is set automaticatly during the build of the object.
*/
- public long bind;
-
+ public long bind;
+
/**
* Even if this attribute is public you must never access to it.
* It is used to compute the id of an MSG process.
*/
- public static long nextProcessId = 0;
-
+ public static long nextProcessId = 0;
+
/**
* Even if this attribute is public you must never access to it.
* It is compute automaticaly during the creation of the object.
* The native functions use this identifier to synchronize the process.
*/
- public long id;
-
+ public long id;
+
/**
* The name of the process.
*/
- protected String name;
- public String msgName() {
- return this.name;
- }
-
- /*
- * The arguments of the method function of the process.
- */
- public Vector args;
-
- /* process synchronisation tools */
- protected Sem schedBegin, schedEnd;
-
+ protected String name;
+ public String msgName() {
+ return this.name;
+ }
+ /*
+ * The arguments of the method function of the process.
+ */ public Vector args;
+
+ /* process synchronisation tools */
+ protected Sem schedBegin, schedEnd;
+
/**
* Default constructor. (used in ApplicationHandler to initialize it)
*/
- protected Process() {
- super();
- this.id = 0;
- this.name = null;
- this.bind = 0;
- this.args = new Vector();
- schedBegin = new Sem(0);
- schedEnd = new Sem(0);
- }
+ protected Process() {
+ super();
+ this.id = 0;
+ this.name = null;
+ this.bind = 0;
+ this.args = new Vector();
+ schedBegin = new Sem(0);
+ schedEnd = new Sem(0);
+ }
+
-
/**
* Constructs a new process from the name of a host and his name. The method
* function of the process doesn't have argument.
* JniException on JNI madness
*
*/
- public Process(String hostname,String name)
- throws NullPointerException, HostNotFoundException, JniException, NativeException {
- this(Host.getByName(hostname),name,null);
- }
-
+ public Process(String hostname, String name)
+ throws NullPointerException, HostNotFoundException, JniException,
+ NativeException {
+ this(Host.getByName(hostname), name, null);
+ }
/**
* Constructs a new process from the name of a host and his name. The arguments
* of the method function of the process are specified by the parameter args.
* NullPointerException if the provided name is null
* JniException on JNI madness
*
- */
- public Process(String hostname,String name,String args[])
- throws NullPointerException, HostNotFoundException, JniException, NativeException {
- this(Host.getByName(hostname),name,args);
- }
-
+ */ public Process(String hostname, String name, String args[])
+ throws NullPointerException, HostNotFoundException, JniException,
+ NativeException {
+ this(Host.getByName(hostname), name, args);
+ }
/**
* Constructs a new process from a host and his name. The method function of the
* process doesn't have argument.
* JniException on JNI madness
*
*/
- public Process(Host host,String name) throws NullPointerException, JniException {
- this(host,name,null);
- }
-
+ public Process(Host host, String name) throws NullPointerException,
+ JniException {
+ this(host, name, null);
+ }
/**
* Constructs a new process from a host and his name, the arguments of here method function are
* specified by the parameter args.
* JniException on JNI madness
*
*/
- public Process(Host host,String name,String[] args) throws NullPointerException, JniException {
- /* This is the constructor called by all others */
-
- if (name==null)
- throw new NullPointerException("Process name cannot be NULL");
-
-
- this.args = new Vector();
-
- if(null != args)
- this.args.addAll(Arrays.asList(args));
-
- this.name = name;
- this.id = nextProcessId++;
-
- schedBegin = new Sem(0);
- schedEnd = new Sem(0);
-
- Msg.processCreate(this,host);
- }
-
+ public Process(Host host, String name,
+ String[]args) throws NullPointerException, JniException {
+ /* This is the constructor called by all others */
+
+ if (name == null)
+ throw new NullPointerException("Process name cannot be NULL");
+
+
+ this.args = new Vector();
+
+ if (null != args)
+ this.args.addAll(Arrays.asList(args));
+
+ this.name = name;
+ this.id = nextProcessId++;
+
+ schedBegin = new Sem(0);
+ schedEnd = new Sem(0);
+
+ Msg.processCreate(this, host);
+ }
/**
* This method kills all running process of the simulation.
*
*
* @return The function returns the PID of the next created process.
*
- */
- public static int killAll(int resetPID){
- return Msg.processKillAll(resetPID);
- }
-
+ */ public static int killAll(int resetPID) {
+ return Msg.processKillAll(resetPID);
+ }
+
/**
* This method adds an argument in the list of the arguments of the main function
* of the process.
*
* @param arg The argument to add.
*/
- protected void addArg(String arg) {
- args.add(arg);
- }
-
+ protected void addArg(String arg) {
+ args.add(arg);
+ }
+
/**
* This method suspends the process by suspending the task on which it was
* waiting for the completion.
* @exception JniException on JNI madness
* NativeException on error in the native SimGrid code
*/
- public void pause() throws JniException,NativeException {
- Msg.processSuspend(this);
- }
-
+ public void pause() throws JniException, NativeException {
+ Msg.processSuspend(this);
+ }
/**
* This method resumes a suspended process by resuming the task on which it was
* waiting for the completion.
* @exception JniException on JNI madness
* NativeException on error in the native SimGrid code
*
- */
- public void restart() throws JniException,NativeException {
- Msg.processResume(this);
- }
-
+ */ public void restart() throws JniException, NativeException {
+ Msg.processResume(this);
+ }
/**
* This method tests if a process is suspended.
*
* Otherwise the method returns false.
*
* @exception JniException on JNI madness
- */
- public boolean isSuspended() throws JniException {
- return Msg.processIsSuspended(this);
- }
-
+ */ public boolean isSuspended() throws JniException {
+ return Msg.processIsSuspended(this);
+ }
/**
* This method returns the host of a process.
*
* @exception JniException on JNI madness
* NativeException on error in the native SimGrid code
*
- */
- public Host getHost() throws JniException,NativeException{
- return Msg.processGetHost(this);
- }
-
+ */ public Host getHost() throws JniException, NativeException {
+ return Msg.processGetHost(this);
+ }
/**
* This static method get a process from a PID.
*
* @return The process with the specified PID.
*
* @exception NativeException on error in the native SimGrid code
- */
- public static Process fromPID(int PID) throws NativeException {
- return Msg.processFromPID(PID);
- }
-
+ */ public static Process fromPID(int PID) throws NativeException {
+ return Msg.processFromPID(PID);
+ }
/**
* This method returns the PID of the process.
*
*
* @exception JniException on JNI madness
* NativeException on error in the native SimGrid code
- */
- public int getPID() throws JniException,NativeException{
- return Msg.processGetPID(this);
- }
-
+ */ public int getPID() throws JniException, NativeException {
+ return Msg.processGetPID(this);
+ }
/**
* This method returns the PID of the parent of a process.
*
* @return The PID of the parent of the process.
*
* @exception NativeException on error in the native SimGrid code
- */
- public int getPPID() throws NativeException{
- return Msg.processGetPPID(this);
- }
-
+ */ public int getPPID() throws NativeException {
+ return Msg.processGetPPID(this);
+ }
/**
* This static method returns the currently running process.
*
* @exception NativeException on error in the native SimGrid code
*
*
- */
- public static Process currentProcess() throws NativeException{
- return Msg.processSelf();
- }
-
+ */ public static Process currentProcess() throws NativeException {
+ return Msg.processSelf();
+ }
/**
* This static method returns the PID of the currently running process.
*
* @return The PID of the current process.
- */
- public static int currentProcessPID(){
- return Msg.processSelfPID();
- }
-
+ */ public static int currentProcessPID() {
+ return Msg.processSelfPID();
+ }
+
/**
* This static method returns the PID of the parent of the currently running process.
*
* @return The PID of the parent of current process.
*/
- public static int currentProcessPPID(){
- return Msg.processSelfPPID();
- }
-
+ public static int currentProcessPPID() {
+ return Msg.processSelfPPID();
+ }
+
/**
* This function migrates a process to another host.
*
*
* @exception JniException on JNI madness
* NativeException on error in the native SimGrid code
- */
- public void migrate(Host host) throws JniException, NativeException{
- Msg.processChangeHost(this,host);
- }
-
+ */
+ public void migrate(Host host) throws JniException, NativeException {
+ Msg.processChangeHost(this, host);
+ }
/**
* This method makes the current process sleep until time seconds have elapsed.
*
* @param seconds The time the current process must sleep.
*
* @exception NativeException on error in the native SimGrid code
- */
- public static void waitFor(double seconds) throws NativeException {
- Msg.processWaitFor(seconds);
- }
-
-
- public void showArgs(){
- try {
- Msg.info("["+this.name+"/"+this.getHost().getName()+"] argc="+this.args.size() );
- for(int i = 0; i < this.args.size(); i++)
- Msg.info("["+this.msgName()+"/"+this.getHost().getName()+
- "] args["+i+"]="+(String)(this.args.get(i)));
- } catch (MsgException e) {
- Msg.info("Damn JNI stuff");
- e.printStackTrace();
- System.exit(1);
- }
+ */ public static void waitFor(double seconds) throws NativeException {
+ Msg.processWaitFor(seconds);
+ } public void showArgs() {
+ try {
+ Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" +
+ this.args.size());
+ for (int i = 0; i < this.args.size(); i++)
+ Msg.info("[" + this.msgName() + "/" + this.getHost().getName() +
+ "] args[" + i + "]=" + (String) (this.args.get(i)));
+ } catch(MsgException e) {
+ Msg.info("Damn JNI stuff");
+ e.printStackTrace();
+ System.exit(1);
}
+ }
/**
* This method runs the process. Il calls the method function that you must overwrite.
*/
- public synchronized void run() {
-
- try {
- String[] args = null; /* do not fill it before the signal or this.args will be empty */
-
- //waitSignal(); /* wait for other people to fill the process in */
-
-
- try {
- schedBegin.acquire();
- } catch(InterruptedException e) {
- }
-
-
-
- if(this.args.size() > 0)
- {
-
- args = new String[this.args.size()];
- this.args.toArray(args);
- }
-
- this.main(args);
- Msg.processExit(this);
- schedEnd.release();
- } catch (MsgException e) {
- e.printStackTrace();
- Msg.info("Unexpected behavior. Stopping now");
- System.exit(1);
- }
+ public synchronized void run() {
+
+ try {
+ String[]args = null; /* do not fill it before the signal or this.args will be empty */
+
+ //waitSignal(); /* wait for other people to fill the process in */
+
+
+ try {
+ schedBegin.acquire();
+ } catch(InterruptedException e) {
+ }
+
+
+
+ if (this.args.size() > 0) {
+
+ args = new String[this.args.size()];
+ this.args.toArray(args);
+ }
+
+ this.main(args);
+ Msg.processExit(this);
+ schedEnd.release();
+ }
+ catch(MsgException e) {
+ e.printStackTrace();
+ Msg.info("Unexpected behavior. Stopping now");
+ System.exit(1);
}
-
+ }
+
/**
* Process synchronization. The process wait the signal of the simulator to start.
*
* @exception JniException on JNI madness
*/
- private void waitSignal() throws JniException{
- Msg.waitSignal(this);
- unschedule();
- }
-
+ private void waitSignal() throws JniException {
+ Msg.waitSignal(this);
+ unschedule();
+ }
/**
* The main function of the process (to implement).
- */
- public abstract void main(String[] args)
- throws JniException, NativeException;
-
-
- public void unschedule() {
-
- try {
- schedEnd.release();
- schedBegin.acquire();
- } catch(InterruptedException e){
-
- }
- }
-
- public void schedule() {
-
- try {
- schedBegin.release();
- schedEnd.acquire();
- } catch(InterruptedException e) {
-
- }
- }
-
- public void taskSend(Channel channel,Task task, Host host) throws NativeException, JniException {
- Msg.channelPut(channel,task,host);
- }
-
- public Task taskReceive(Channel channel) throws NativeException, JniException {
- return Msg.channelGet(channel);
- }
-}
+ */ public abstract void main(String[]args)
+ throws JniException, NativeException;
+ public void unschedule() {
+
+ try {
+ schedEnd.release();
+ schedBegin.acquire();
+ } catch(InterruptedException e) {
+
+ }
+ }
+
+ public void schedule() {
+
+ try {
+ schedBegin.release();
+ schedEnd.acquire();
+ } catch(InterruptedException e) {
+
+ }
+ }
+
+ public void taskSend(Channel channel, Task task,
+ Host host) throws NativeException, JniException {
+ Msg.channelPut(channel, task, host);
+ } public Task taskReceive(Channel channel) throws NativeException,
+ JniException {
+ return Msg.channelGet(channel);
+}}
* it and/or modify it under the terms of the license
* (GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
public class ProcessNotFoundException extends MsgException {
-
- private static final long serialVersionUID = 1L;
+
+ private static final long serialVersionUID = 1L;
/**
* Constructs an <code>ProcessNotFoundException</code> without a
* detail message.
*/
- public ProcessNotFoundException() {
- super();
- }
-
+ public ProcessNotFoundException() {
+ super();
+ }
/**
* Constructs an <code>ProcessNotFoundException</code> with a detail message.
*
* @param s the detail message.
- */
- public ProcessNotFoundException(String s) {
- super(s);
- }
-}
\ No newline at end of file
+ */ public ProcessNotFoundException(String s) {
+ super(s);
+ }
+}
* This program is free software; you can redistribute \r
* it and/or modify it under the terms of the license \r
*(GNU LGPL) which comes with this package. \r
- */\r
- \r
-package simgrid.msg;\r
-\r
-public class Sem { \r
- \r
- /******************************************************************/\r
- /* Simple semaphore implementation, from Doug Lea (public domain) */\r
- /******************************************************************/\r
- private int permits_;\r
- \r
- public Sem(int i) {\r
- permits_ = i;\r
- }\r
- \r
- public void acquire() throws InterruptedException {\r
- \r
- if (Thread.interrupted()) \r
- throw new InterruptedException();\r
- \r
- synchronized(this) {\r
- \r
- try {\r
- while (permits_ <= 0) \r
- wait();\r
- \r
- --permits_;\r
- }\r
- catch (InterruptedException ex) {\r
- notify();\r
- throw ex;\r
- }\r
- }\r
- }\r
-\r
- public synchronized void release() {\r
- ++(this.permits_);\r
- notify();\r
- }\r
-}\r
+ */ \r
+ \rpackage simgrid.msg;
+\r\rpublic class Sem {
+ \r\r
+ /******************************************************************/ \r
+ /* Simple semaphore implementation, from Doug Lea (public domain) */ \r
+ /******************************************************************/ \r
+ private int permits_;
+ \r\rpublic Sem(int i) {
+ \rpermits_ = i;
+ \r} \r\rpublic void acquire() throws InterruptedException {
+ \r \r if (Thread.interrupted())
+ \rthrow new InterruptedException();
+ \r\rsynchronized(this) {
+ \r\rtry {
+ \rwhile (permits_ <= 0)
+ \rwait();
+ \r\r--permits_;
+ \r}
+ \rcatch(InterruptedException ex) {
+ \rnotify();
+ \rthrow ex;
+ \r}
+ \r}
+ \r}
+ \r\rpublic synchronized void release() {
+ \r++(this.permits_);
+ \rnotify();
+\r} \r} \r
* it and/or modify it under the terms of the license
*(GNU LGPL) which comes with this package.
*/
-
+
package simgrid.msg;
/**
* @since SimGrid 3.3
* @since JDK1.5011
*/
-public class Task
-{
- /**
+public class Task {
+ /**
* This attribute represents a bind between a java task object and
* a native task. Even if this attribute is public you must never
* access to it. It is set automaticatly during the build of the object.
*/
- public long bind = 0;
-
- /**
+ public long bind = 0;
+
+ /**
* Default constructor (disabled)
*/
- protected Task() {}
-
- /**
+ protected Task() {
+ }
+ /**
* Construct an new task with the specified processing amount and amount
* of data needed.
*
* InvalidComputeDuration if the specified compute duration is less than 0.
* InvalidMessageSizeException if the specified message size is less than 0.
*/
- public Task(String name, double computeDuration, double messageSize) throws JniException {
-
- create(name,computeDuration,messageSize);
- }
-
- /**
+ public Task(String name, double computeDuration,
+ double messageSize) throws JniException {
+
+ create(name, computeDuration, messageSize);
+ }
+ /**
* This method creates a new task with the specified features. The task
* creation means that the native task is created and binded with the
* java task instance. If the task is already created you must destroy it
* InvalidComputeDuration if the specified compute duration is less than 0.
* InvalidMessageSizeException if the specified message size is less than 0.
*/
- public void create(String name, double computeDuration, double messageSize) throws JniException {
-
- if(this.bind == 0)
- Msg.taskCreate(this,name,computeDuration,messageSize);
- }
-
- /**
+ public void create(String name, double computeDuration,
+ double messageSize) throws JniException {
+
+ if (this.bind == 0)
+ Msg.taskCreate(this, name, computeDuration, messageSize);
+ }
+ /**
* This method gets the sender of the task.
*
* @return The sender of the task.
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
*
- */
- Process getSender() throws JniException{
- return Msg.taskGetSender(this);
- }
-
- /**
+ */ Process getSender() throws JniException {
+ return Msg.taskGetSender(this);
+ }
+ /**
* This method gets the source of the task.
*
* @return The source of the task.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public Host getSource()throws JniException, NativeException{
- return Msg.taskGetSource(this);
- }
-
- /**
+ */ public Host getSource() throws JniException, NativeException {
+ return Msg.taskGetSource(this);
+ }
+ /**
* This method gets the name of a task.
*
* @return The name of the task.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public String getName()throws JniException{
- return Msg.taskGetName(this);
- }
-
- /**
+ */ public String getName() throws JniException {
+ return Msg.taskGetName(this);
+ }
+ /**
* This method cancels a task.
*
* @exception InvalidTaskException if the specified task is not valid. A task
* is invalid if it is not binded with a native task.
* MsgException if the cancelation failed.
- */
- public void cancel() throws JniException, NativeException{
- Msg.taskCancel(this);
- }
-
- /**
+ */ public void cancel() throws JniException, NativeException {
+ Msg.taskCancel(this);
+ }
+ /**
* This method gets the computing amount of the task.
*
* @return The computing amount of the task.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public double getComputeDuration()throws JniException{
- return Msg.taskGetComputeDuration(this);
- }
-
- /**
+ */ public double getComputeDuration() throws JniException {
+ return Msg.taskGetComputeDuration(this);
+ }
+ /**
* This method gets the remaining computation.
*
* @return The remaining duration.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public double getRemainingDuration() throws JniException {
- return Msg.taskGetRemainingDuration(this);
- }
-
- /**
+ */ public double getRemainingDuration() throws JniException {
+ return Msg.taskGetRemainingDuration(this);
+ }
+ /**
* This method sets the priority of the computation of the task.
* The priority doesn't affect the transfert rate. For example a
* priority of 2 will make the task receive two times more cpu than
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
- */
- public void setPrirority(double priority) throws JniException {
- Msg.taskSetPriority(this,priority);
- }
-
- /**
+ */ public void setPrirority(double priority) throws JniException {
+ Msg.taskSetPriority(this, priority);
+ }
+ /**
* This method destroys a task.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
* MsgException if the destruction failed.
- */
- public void destroy() throws JniException, NativeException {
- if(this.bind != 0) {
- Msg.taskDestroy(this);
- this.bind = 0;
- }
- }
-
- /**
+ */ public void destroy() throws JniException, NativeException {
+ if (this.bind != 0) {
+ Msg.taskDestroy(this);
+ this.bind = 0;
+ }
+ }
+ /**
* This method deletes a task.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
* MsgException if the destruction failed.
- */
- protected void finalize() throws JniException, NativeException {
- if(this.bind != 0)
- Msg.taskDestroy(this);
- }
-
- /**
+ */ protected void finalize() throws JniException, NativeException {
+ if (this.bind != 0)
+ Msg.taskDestroy(this);
+ }
+ /**
* This method execute a task on the location on which the
* process is running.
*
* @exception InvalidTaskException is the specified task is not valid. A task
* is invalid if it is not binded with a native task.
* MsgException if the destruction failed.
- */
- public void execute() throws JniException, NativeException {
- Msg.taskExecute(this);
- }
-}
+ */ public void execute() throws JniException, NativeException {
+ Msg.taskExecute(this);
+}}