*
* @author Abdelmalek Cherier
* @author Martin Quinson
- * @version 1.00, 07/05/01
- * @see Process
- * @see Channel
* @since SimGrid 3.3
- * @since JDK1.5011
*/
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
*/
public long bind = 0;
- /**
- * Default constructor (disabled)
- */
+
+ /* Default constructor (disabled) */
protected Task() {
}
- /**
+ /* * * *
+ * * Constructors * *
+ * * * *//**
* Construct an new task with the specified processing amount and amount
* of data needed.
*
- * @param name The name of th task.
+ * @param name Task's name
*
- * @param computeDuration A value of the processing amount (in flop) needed
- * to process the task. If 0, then it cannot be executed
- * with the execute() method. This value has to be >= 0.
+ * @param computeDuration A value of the processing amount (in flop) needed to process the task.
+ * If 0, then it cannot be executed with the execute() method.
+ * This value has to be >= 0.
*
- * @param messageSize A value of amount of data (in bytes) needed to transfert
- * this task. If 0, then it cannot be transfered this task.
- * If 0, then it cannot be transfered with the get() and put()
- * methods. This value has to be >= 0.
+ * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
+ * If 0, then it cannot be transfered with the get() and put() methods.
+ * This value has to be >= 0.
*
- * @exception InvalidTaskNameException if the specified name is null.
- * 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);
+ * @exception JniException if the binding mecanism fails.
+ */ public Task(String name, double computeDuration,
+ double messageSize) throws JniException {
+ MsgNative.taskCreate(this, 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
- * before to use this method, otherwise the method throws the exception
- * TaskAlreadyCreatedException.
+ /**
+ * Construct an new parallel task with the specified processing amount and amount for each host
+ * implied.
+ *
+ * @param name The name of the parallel task.
+ * @param hosts The list of hosts implied by the parallel task.
+ * @param computeDurations The amount of operations to be performed by each host of @hosts.
+ * @param messageSizes A matrix describing the amount of data to exchange between hosts.
+ *
+ * @exception JniException if the binding mecanism fails.
+ */ public Task(String name, Host[]hosts, double[]computeDurations,
+ double[]messageSizes) throws JniException {
+ MsgNative.parallelTaskCreate(this, name, hosts, computeDurations,
+ messageSizes);
+ }
+ /* * * *
+ * * Getters / Setters * *
+ * * * *//**
+ * This method gets the name of a task.
*
- * @param name The name of the task.
- * @param computeDuration A value of the processing amount (in flop) needed
- * to process the task. If 0, then it cannot be executed
- * with the execute() method. This value has to be >= 0.
- * @param messageSize A value of amount of data (in bytes) needed to transfert
- * this task. If 0, then it cannot be transfered this task.
- * If 0, then it cannot be transfered with the get() and put()
- * methods. This value has to be >= 0.
+ * @return The name of the task.
*
- * @exception InvalidTaskNameException if the specified name is null.
- * 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);
+ * @exception JniException if the binding mecanism fails.
+ * @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 MsgNative.taskGetName(this);
}
/**
* 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.
+ * @exception JniException if the binding mecanism fails.
*
*/ Process getSender() throws JniException {
- return Msg.taskGetSender(this);
+ return MsgNative.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.
+ * @exception JniException if the binding mecanism fails.
*/ 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);
- }
- /**
- * 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);
+ return MsgNative.taskGetSource(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.
+ * @exception JniException if the binding mecanism fails.
*/ public double getComputeDuration() throws JniException {
- return Msg.taskGetComputeDuration(this);
+ return MsgNative.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.
+ * @exception JniException if the binding mecanism fails.
*/ public double getRemainingDuration() throws JniException {
- return Msg.taskGetRemainingDuration(this);
+ return MsgNative.taskGetRemainingDuration(this);
}
/**
* This method sets the priority of the computation 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 void setPrirority(double priority) throws JniException {
- Msg.taskSetPriority(this, priority);
+ MsgNative.taskSetPriority(this, priority);
+ }
+ /* * * *
+ * * Communication-related * *
+ * * * *//**
+ * Retrieves next task on given channel of local host
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the retrival fails.
+ */
+ public static Task get(int channel) throws JniException, NativeException {
+ return MsgNative.taskGet(channel, -1.0, null);
+ }
+ /**
+ * Retrieves next task on given channel of local host (wait at most #timeout seconds)
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the retrival fails.
+ */
+ public static Task get(int channel, double timeout) throws JniException,
+ NativeException {
+ return MsgNative.taskGet(channel, timeout, null);
+ }
+ /**
+ * Retrieves next task from given host on given channel of local host
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the retrival fails.
+ */
+ public static Task get(int channel, Host host) throws JniException,
+ NativeException {
+ return MsgNative.taskGet(channel, -1, host);
+ }
+ /**
+ * Retrieves next task from given host on given channel of local host (wait at most #timeout seconds)
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the retrival fails.
+ */ public static Task get(int channel, double timeout,
+ Host host) throws JniException, NativeException {
+ return MsgNative.taskGet(channel, timeout, host);
+ }
+ /**
+ * Probes whether there is a waiting task on the given channel of local host
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the retrival fails.
+ */ public static boolean probe(int channel) throws JniException {
+ return MsgNative.taskProbe(channel);
+ }
+ /**
+ * Counts tasks waiting on the given #channel of local host and sent by given #host
+ *
+ * @exception JniException if the binding mecanism fails.
+ */ public static int probe(int channel, Host host) throws JniException {
+ return MsgNative.taskProbeHost(channel, host);
+ }
+ /* * * *
+ * * Computation-related * *
+ * * * *//**
+ * This method execute a task on the location on which the
+ * process is running.
+ *
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the cancelation failed.
+ */ public void execute() throws JniException, NativeException {
+ MsgNative.taskExecute(this);
}
/**
- * This method destroys a task.
+ * This method cancels 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;
- }
+ * @exception JniException if the binding mecanism fails.
+ * @exception NativeException if the cancelation failed.
+ */ public void cancel() throws JniException, NativeException {
+ MsgNative.taskCancel(this);
}
/**
* This method deletes a task.
* MsgException if the destruction failed.
*/ 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);
+ MsgNative.taskDestroy(this);
}}