package simgrid.msg;
/**
- * Since most scheduling algorithms rely on a concept of
- * task that can be either computed locally or transferred
- * on another processor, it seems to be the right level of
- * abstraction for our purposes. A task may then be defined
- * by a computing amount, a message size and some private
- * data. To transfer a task you use an instance of the class
- * Channel identified by an number.
+ * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
+ * It is defined by a computing amount and a message size.
*
- * @author Abdelmalek Cherier
- * @author Martin Quinson
- * @since SimGrid 3.3
*/
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.
+ * access to it. It is set automatically during the build of the object.
*/
- public long bind = 0;
+ public long bind = 0;
- /* Default constructor (disabled) */
- protected Task() {
- }
- /* * * *
- * * Constructors * *
- * * * *//**
+ /** Default constructor (all fields to 0 or null) */
+ public Task() {
+ MsgNative.taskCreate(this, null, 0, 0);
+ }
+ /* * * *
+ * * Constructors * *
+ * * * */
+ /**
* Construct an new task with the specified processing amount and amount
* of data needed.
*
* @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.
+ */
+ public Task(String name, double computeDuration, double messageSize) {
+ MsgNative.taskCreate(this, name, computeDuration, messageSize);
+ }
+ /**
+ * Construct an new parallel task with the specified processing amount and amount for each host
+ * implied.
*
- * @exception JniException if the binding mecanism fails.
- */ public Task(String name, double computeDuration,
- double messageSize) throws JniException {
- MsgNative.taskCreate(this, name, computeDuration, messageSize);
- }
- /**
- * 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 \e 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.
- *
- * @return The name of the task.
- *
- * @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 JniException if the binding mecanism fails.
- *
- */ Process getSender() throws JniException {
- return MsgNative.taskGetSender(this);
- }
- /**
- * This method gets the source of the task.
- *
- * @return The source of the task.
- *
- * @exception JniException if the binding mecanism fails.
- */ public Host getSource() throws JniException, NativeException {
- return MsgNative.taskGetSource(this);
- }
- /**
- * This method gets the computing amount of the task.
+ * @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 \a hosts.
+ * @param messageSizes A matrix describing the amount of data to exchange between hosts.
+ */
+ public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
+ MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
+ }
+ /* * * *
+ * * Getters / Setters * *
+ * * * */
+ /** Gets the name of a task */
+ public String getName() {
+ return MsgNative.taskGetName(this);
+ }
+ /** Gets the sender of the task */
+ Process getSender() {
+ return MsgNative.taskGetSender(this);
+ }
+ /** Gets the source of the task */
+ public Host getSource() {
+ return MsgNative.taskGetSource(this);
+ }
+ /** Gets the computing amount of the task */
+ public double getComputeDuration() {
+ return MsgNative.taskGetComputeDuration(this);
+ }
+ /** Gets the remaining computation of the task */
+ public double getRemainingDuration() {
+ return MsgNative.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
+ * the other ones.
*
- * @return The computing amount of the task.
+ * @param priority The new priority of the task.
+ */
+ public void setPriority(double priority) {
+ MsgNative.taskSetPriority(this, priority);
+ }
+ /* * * *
+ * * Communication-related * *
+ * * * */
+
+
+ /* * * *
+ * * Computation-related * *
+ * * * */
+ /**
+ * Executes a task on the location on which the process is running.
*
- * @exception JniException if the binding mecanism fails.
- */ public double getComputeDuration() throws JniException {
- return MsgNative.taskGetComputeDuration(this);
- }
- /**
- * This method gets the remaining computation.
- *
- * @return The remaining duration.
- *
- * @exception JniException if the binding mecanism fails.
- */ public double getRemainingDuration() throws JniException {
- return MsgNative.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
- * the other ones.
- *
- * @param priority The new priority of the task.
- *
- * @exception JniException is the specified task is not valid (ie, not binded to a native task)
- */
- public void setPriority(double priority) throws JniException {
- 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 \e 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 \e 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 \e channel of local host and sent by given \e 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 cancels a task.
+ * @exception HostFailureException,TaskCancelledException
+ */
+ public void execute() throws HostFailureException,TaskCancelledException {
+ MsgNative.taskExecute(this);
+ }
+ /**
+ * Cancels a task.
*
- * @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.
+ * @exception NativeException if the cancellation failed.
+ */
+ public void cancel() {
+ MsgNative.taskCancel(this);
+ }
+ /** 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)
- MsgNative.taskDestroy(this);
+ * @exception NativeException if the destruction failed.
+ */
+ protected void finalize() throws NativeException {
+ if (this.bind != 0)
+ MsgNative.taskDestroy(this);
}
-
- /**
- * Send the task on the mailbox identified by the default alias (defaultAlias = "currentHostName:CurrentProcessName")
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void send() throws JniException,NativeException {
-
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
-
- MsgNative.taskSend(alias, this, -1);
- }
-
- /**
- * Send the task on the mailbox identified by the specified alias
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void send(String alias) throws JniException,NativeException {
- MsgNative.taskSend(alias, this, -1);
- }
-
- /**
- * Send the task on the mailbox identified by the default alias (wait at most \e timeout seconds)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void send(double timeout) throws JniException,NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
- MsgNative.taskSend(alias, this, timeout);
- }
-
+
/**
- * Send the task on the mailbox identified by the specified alias (wait at most \e timeout seconds)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void send(String alias, double timeout) throws JniException,NativeException {
- MsgNative.taskSend(alias, this, timeout);
+ * Sends the task on the mailbox identified by the specified name
+ *
+ * @throws TimeoutException
+ * @throws HostFailureException
+ * @throws TransferFailureException
+ */
+ public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
+ MsgNative.taskSend(mailbox, this, -1);
}
-
-
+
/**
- * Send the task on the mailbox identified by the default alias (capping the emision rate to \e maxrate)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void sendBounded(double maxrate) throws JniException,NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
- MsgNative.taskSendBounded(alias, this, maxrate);
+ * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
+ *
+ * @exception NativeException if the retrieval fails.
+ * @throws TimeoutException
+ * @throws HostFailureException
+ * @throws TransferFailureException
+ */
+ public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+ MsgNative.taskSend(mailbox, this, timeout);
}
-
+
/**
- * Send the task on the mailbox identified by the specified alias (capping the emision rate to \e maxrate)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public void sendBounded(String alias, double maxrate) throws JniException,NativeException {
+ * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
+ *
+ * @exception TransferFailureException, HostFailureException, 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 default alias (defaultAlias = "currentHostName:CurrentProcessName")
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static Task receive() throws JniException, NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
- return MsgNative.taskReceive(alias, -1.0, null);
- }
-
+
/**
- * Retrieves next task from the mailbox identified by the specified alias
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
-
- public static Task receive(String alias) throws JniException, NativeException {
- return MsgNative.taskReceive(alias, -1.0, null);
+ * Retrieves next task from the mailbox identified by the specified name
+ *
+ * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ */
+
+ public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
+ return MsgNative.taskReceive(mailbox, -1.0, null);
}
-
+
/**
- * Retrieves next task on the mailbox identified by the specified alias (wait at most \e timeout seconds)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static Task receive(String alias, double timeout) throws JniException, NativeException {
- return MsgNative.taskReceive(alias, timeout, null);
+ * 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.
+ */
+ public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
+ return MsgNative.taskReceive(mailbox, timeout, null);
}
-
+
/**
- * Retrieves next task sended by a given host on the mailbox identified by the specified alias
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
-
- public static Task receive(String alias, Host host) throws JniException, NativeException {
- return MsgNative.taskReceive(alias, -1.0, host);
+ * Retrieves next task sent by a given host on the mailbox identified by the specified alias
+ *
+ * @exception TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
+ */
+
+ public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
+ return MsgNative.taskReceive(mailbox, -1.0, host);
}
-
+
/**
- * Retrieves next task sended by a given host on the mailbox identified by the specified alias (wait at most \e timeout seconds)
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static Task receive(String alias, double timeout, Host host) throws JniException, NativeException {
- return MsgNative.taskReceive(alias, timeout, host);
+ * 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.
+ */
+ public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
+ return MsgNative.taskReceive(mailbox, timeout, host);
}
-
+
/**
- * Listen whether there is a waiting task on the mailbox identified by the default alias of local host
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static boolean listen() throws JniException, NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
-
- return MsgNative.taskListen(alias);
+ * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
+ *
+ */
+ public static int listenFrom(String mailbox) {
+ return MsgNative.taskListenFrom(mailbox);
}
-
/**
- * Test whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static int listenFrom(String alias) throws JniException, NativeException {
- return MsgNative.taskListenFrom(alias);
+ * Listen whether there is a waiting task on the mailbox identified by the specified alias
+ *
+ */
+ public static boolean listen(String mailbox) {
+ return MsgNative.taskListen(mailbox);
}
-
+
/**
- * Test whether there is a pending communication on the mailbox identified by the default alias, of the current host, and who sent it
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static int listenFrom() throws JniException, NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
-
- return MsgNative.taskListenFrom(alias);
- }
-
- /**
- * Listen whether there is a waiting task on the mailbox identified by the specified alias
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static boolean listen(String alias) throws JniException, NativeException {
- return MsgNative.taskListen(alias);
- }
-
- /**
- * Counts the number of tasks waiting to be received on the \e mailbox identified by the specified alias and sended by the current host.
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static int listenFromHost(Host host) throws JniException, NativeException {
- String alias = Host.currentHost().getName() + ":" + Process.currentProcess().msgName();
- return MsgNative.taskListenFromHost(alias,host);
- }
-
- /**
- * Counts the number of tasks waiting to be received on the \e mailbox identified by the specified alia and sended by the specified \e host.
- *
- * @exception JniException if the binding mecanism fails.
- * @exception NativeException if the retrival fails.
- */
- public static int listenFromHost(String alias, Host host) throws JniException, NativeException {
+ * 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.
+ *
+ */
+ public static int listenFromHost(String alias, Host host) {
return MsgNative.taskListenFromHost(alias, host);
}
}