import java.util.Hashtable;
import java.util.Vector;
+/**
+ *
+ * @author lbobelin
+ */
public final class ApplicationHandler {
*/
public static Vector<String> args;
- public static Hashtable<String,String> properties;
+ /**
+ *
+ */
+ public static Hashtable<String,String> properties;
/**
* The name of the host of the process.
* and clear the vector containing the arguments of the
* previouse process function if needed.
*
- * @host The host of the process to create.
+ * @param hostName_
+ * @param function_
+ * @host The host of the process to create.
* @function The function of the process to create.
*
*/
* It stores the argument of the function of the next
* process to create in the vector of arguments.
*
- * @arg The argument to add.
+ * @param arg
+ * @arg The argument to add.
*
*/ public static void registerProcessArg(String arg) {
args.add(arg);
}
- public static void setProperty(String id, String value)
+ /**
+ *
+ * @param id
+ * @param value
+ */
+ public static void setProperty(String id, String value)
{
properties.put(id,value);
}
- public static String getHostName()
+ /**
+ *
+ * @return
+ */
+ public static String getHostName()
{
return hostName;
}
- @SuppressWarnings("unchecked")
+ /**
+ *
+ */
+ @SuppressWarnings("unchecked")
public static void createProcess() {
try {
Class<Process> cls = (Class<Process>) Class.forName(function);
}
- public static void onStartDocument() {
+ /**
+ *
+ */
+ public static void onStartDocument() {
args = new Vector<String>();
properties = new Hashtable<String,String>();
hostName = null;
function = null;
}
- public static void onBeginProcess(String hostName, String function) {
+ /**
+ *
+ * @param hostName
+ * @param function
+ */
+ public static void onBeginProcess(String hostName, String function) {
setProcessIdentity(hostName, function);
}
- public static void onProperty(String id, String value) {
+ /**
+ *
+ * @param id
+ * @param value
+ */
+ public static void onProperty(String id, String value) {
setProperty(id, value);
}
- public static void onProcessArg(String arg) {
+ /**
+ *
+ * @param arg
+ */
+ public static void onProcessArg(String arg) {
registerProcessArg(arg);
}
- public static void onEndProcess() {
+ /**
+ *
+ */
+ public static void onEndProcess() {
createProcess();
}
- public static void onEndDocument() {
+ /**
+ *
+ */
+ public static void onEndDocument() {
}
}
* User data.
*/
private Object data;
- protected Host() {
+ /**
+ *
+ */
+ protected Host() {
this.bind = 0;
this.data = null;
};
*
* @param name The name of the host to get.
*
- * @exception HostNotFoundException if the name of the host is not valid.
+ * @return
+ * @exception HostNotFoundException if the name of the host is not valid.
* NativeException if the native version of this method failed.
*/
public static Host getByName(String name)
/**
* Sets the data of the host.
*
- */
+ *
+ * @param data
+ */
public void setData(Object data) {
this.data = data;
}
/**
* Gets the data of the host.
- */
+ *
+ * @return
+ */
public Object getData() {
return this.data;
}
/**
* Checks whether a host has data.
- */
+ *
+ * @return
+ */
public boolean hasData() {
return null != this.data;
}
return MsgNative.hostGetSpeed(this);
}
- /** This method tests if a host is avail. */
+ /** This method tests if a host is avail.
+ * @return
+ */
public boolean isAvail() {
return MsgNative.hostIsAvail(this);
}
package org.simgrid.msg;
+/**
+ *
+ * @author lbobelin
+ */
public final class Msg {
/* Statically load the library which contains all native functions used in here */
static {
}
/* FIXME: kill these C crufts */
- /** Returns the last error code of the simulation */
+ /** Returns the last error code of the simulation
+ * @return
+ */
public final static native int getErrCode();
/** Everything is right. Keep on going the way ! */
/** You've done something wrong. You'd better look at it... */
public static final int FATAL_ERROR = 5;
- /** Retrieve the simulation time */
+ /** Retrieve the simulation time
+ * @return
+ */
public final static native double getClock();
- /** Issue an information logging message */
+ /** Issue an information logging message
+ * @param s
+ */
public final static native void info(String s);
/*********************************************************************************
/**
* The method to deploy the simulation.
*
- * @param platformFile The XML file which contains the description of the application to deploy.
- */
+ *
+ * @param deploymentFile
+ */
public final static native void deployApplication(String deploymentFile);
- /** Example launcher. You can use it or provide your own launcher, as you wish */
+ /** Example launcher. You can use it or provide your own launcher, as you wish
+ * @param args
+ * @throws MsgException
+ */
static public void main(String[]args) throws MsgException {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
Msg.init(args);
*/
public long id;
- public Hashtable<String,String> properties;
+ /**
+ *
+ */
+ public Hashtable<String,String> properties;
/**
* The name of the process.
*/
protected String name;
- public String msgName() {
+ /**
+ *
+ * @return
+ */
+ public String msgName() {
return this.name;
}
/** The arguments of the method function of the process. */
public Vector<String> args;
/* process synchronization tools */
- protected Sem schedBegin, schedEnd;
+ /**
+ *
+ */
+ /**
+ *
+ */
+ protected Sem schedBegin, schedEnd;
/**
* Default constructor (used in ApplicationHandler to initialize it)
* @param args The arguments of the main function of the process.
*
* @exception HostNotFoundException if no host with this name exists.
- * NativeException
+ * NativeException
+ * @throws NativeException
*
*/
public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException {
return MsgNative.processKillAll(resetPID);
}
+
+ /**
+ * This method kill the current process.
+ * @param process the process to be killed.
+ *
+ */
+ public static void kill(Process process) {
+ MsgNative.processKill(process);
+ }
/**
* This method adds an argument in the list of the arguments of the main function
* of the process.
*
* @param arg The argument to add.
- */
+ *
+ * @deprecated
+ */
@Deprecated
protected void addArg(String arg) {
args.add(arg);
*
* @return The host instance of the process.
*
- * @exception NativeException on error in the native SimGrid code
*
*/
public Host getHost() {
public static void waitFor(double seconds) throws HostFailureException {
MsgNative.processWaitFor(seconds);
}
- public void showArgs() {
+ /**
+ *
+ */
+ public void showArgs() {
Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" +
this.args.size());
for (int i = 0; i < this.args.size(); i++)
/**
* The main function of the process (to implement).
- */
+ *
+ * @param args
+ * @throws MsgException
+ */
public abstract void main(String[]args) throws MsgException;
- public void unschedule() {
+ /**
+ *
+ */
+ public void unschedule() {
try {
schedEnd.release();
schedBegin.acquire();
}
}
- public void schedule() {
+ /**
+ *
+ */
+ public void schedule() {
//System.err.println("Scheduling process in Java");
try {
schedBegin.release();
}
/** Send the given task in the mailbox associated with the specified alias (waiting at most given time)
- * @throws TimeoutException
+ * @param mailbox
+ * @param task
+ * @param timeout
+ * @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException */
public void taskSend(String mailbox, Task task, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
}
/** Send the given task in the mailbox associated with the specified alias
- * @throws TimeoutException
+ * @param mailbox
+ * @param task
+ * @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException */
public void taskSend(String mailbox, Task task) throws TransferFailureException, HostFailureException, TimeoutException {
MsgNative.taskSend(mailbox, task, -1);
}
- /** Receive a task on mailbox associated with the specified mailbox */
+ /** Receive a task on mailbox associated with the specified mailbox
+ * @param mailbox
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
+ */
public Task taskReceive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, -1.0, null);
}
- /** Receive a task on mailbox associated with the specified alias (waiting at most given time) */
+ /** Receive a task on mailbox associated with the specified alias (waiting at most given time)
+ * @param mailbox
+ * @param timeout
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
+ */
public Task taskReceive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, timeout, null);
}
- /** Receive a task on mailbox associated with the specified alias from given sender */
+ /** Receive a task on mailbox associated with the specified alias from given sender
+ * @param mailbox
+ * @param host
+ * @param timeout
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
+ */
public Task taskReceive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, timeout, host);
}
- /** Receive a task on mailbox associated with the specified alias from given sender*/
+ /** Receive a task on mailbox associated with the specified alias from given sender
+ * @param mailbox
+ * @param host
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
+ */
public Task taskReceive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, -1.0, host);
}
* it and/or modify it under the terms of the license \r
*(GNU LGPL) which comes with this package. \r
*/ \r
-\rpackage org.simgrid.msg;
-\r\rpublic class Sem {\r
+\r
+package org.simgrid.msg;\r
+\r
+\r
+/**\r
+ *\r
+ * @author lbobelin\r
+ */\r
+public class Sem {\r
/******************************************************************/ \r
/* Simple semaphore implementation, from Doug Lea (public domain) */ \r
/******************************************************************/ \r
- private int permits_;
-\r public Sem(int i) {\r permits_ = i;\r } \r\r public void acquire() throws InterruptedException {
- if (Thread.interrupted())
- throw new InterruptedException();
-\r synchronized(this) {
- try {
- while (permits_ <= 0)
- wait();
- --permits_;
- }
- catch(InterruptedException ex) {
- notify();
- throw ex;
- }
- }
- }
-\r public synchronized void release() {
- ++(this.permits_);
- notify();
- } \r} \r
+ private int permits_;\r
+\r
+ /**\r
+ *\r
+ * @param i\r
+ */\r
+ public Sem(int i) {\r
+ permits_ = i;\r
+ } \r
+\r
+ /**\r
+ *\r
+ * @throws java.lang.InterruptedException\r
+ */\r
+ public void acquire() throws InterruptedException {\r
+ if (Thread.interrupted())\r
+ throw new InterruptedException();\r
+\r
+ synchronized(this) {\r
+ try {\r
+ while (permits_ <= 0)\r
+ wait();\r
+ --permits_;\r
+ }\r
+ catch(InterruptedException ex) {\r
+ notify();\r
+ throw ex;\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ public synchronized void release() {\r
+ ++(this.permits_);\r
+ notify();\r
+ } \r
+} \r
/* * * *
* * Getters / Setters * *
* * * */
- /** Gets the name of a task */
+ /** Gets the name of a task
+ * @return
+ */
public String getName() {
return MsgNative.taskGetName(this);
}
Process getSender() {
return MsgNative.taskGetSender(this);
}
- /** Gets the source of the task */
+ /** Gets the source of the task
+ * @return
+ */
public Host getSource() {
return MsgNative.taskGetSource(this);
}
- /** Gets the computing amount of the task */
+ /** Gets the computing amount of the task
+ * @return
+ */
public double getComputeDuration() {
return MsgNative.taskGetComputeDuration(this);
}
- /** Gets the remaining computation of the task */
+ /** Gets the remaining computation of the task
+ * @return
+ */
public double getRemainingDuration() {
return MsgNative.taskGetRemainingDuration(this);
}
/**
* Executes a task on the location on which the process is running.
*
- * @exception HostFailureException,TaskCancelledException
- */
+ *
+ * @throws HostFailureException
+ * @throws TaskCancelledException
+ */
public void execute() throws HostFailureException,TaskCancelledException {
MsgNative.taskExecute(this);
}
/**
* Cancels a task.
*
- * @exception NativeException if the cancellation failed.
*/
public void cancel() {
MsgNative.taskCancel(this);
/**
* Sends the task on the mailbox identified by the specified name
*
- * @throws TimeoutException
+ * @param mailbox
+ * @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException
*/
/**
* Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
*
- * @exception NativeException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
+ * @exception NativeException if the retrieval fails.
* @throws TimeoutException
* @throws HostFailureException
* @throws TransferFailureException
/**
* Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException.
+ * @param alias
+ * @param maxrate
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
*/
public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
MsgNative.taskSendBounded(alias, this, maxrate);
/**
* Retrieves next task from the mailbox identified by the specified name
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
*/
public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
/**
* Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
*/
public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, timeout, null);
/**
* Retrieves next task sent by a given host on the mailbox identified by the specified alias
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param host
+ * @return
+ * @throws TransferFailureException
+ * @throws TimeoutException
+ * @throws HostFailureException
*/
public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
/**
* Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
*
- * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ * @param mailbox
+ * @param timeout
+ * @param host
+ * @return
+ * @throws TransferFailureException
+ * @throws HostFailureException
+ * @throws TimeoutException
*/
public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
return MsgNative.taskReceive(mailbox, timeout, host);
/**
* Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
*
- */
+ *
+ * @param mailbox
+ * @return
+ */
public static int listenFrom(String mailbox) {
return MsgNative.taskListenFrom(mailbox);
}
/**
* Listen whether there is a waiting task on the mailbox identified by the specified alias
*
- */
+ *
+ * @param mailbox
+ * @return
+ */
public static boolean listen(String mailbox) {
return MsgNative.taskListen(mailbox);
}
/**
* Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host.
*
- */
+ *
+ * @param alias
+ * @param host
+ * @return
+ */
public static int listenFromHost(String alias, Host host) {
return MsgNative.taskListenFromHost(alias, host);
}