Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hello you stupid doxygen. Our inline functions are visible to the users, please don...
[simgrid.git] / src / java / simgrid / msg / Task.java
index 3586048..bc2cdaa 100644 (file)
  * it and/or modify it under the terms of the license 
  *(GNU LGPL) which comes with this package. 
  */
+
 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
- * @version 1.00, 07/05/01
- * @see Process
- * @see Channel
- * @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.
+        * access to it. It is set automatically during the build of the object.
         */
        public long bind = 0;
-       
-       /**
-        * Default constructor (disabled)
-        */
-       protected Task() {}
-       
+
+
+       /** 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 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 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.
+        *
+        * @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.
+        *
+        * @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 HostFailureException,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);
+       }
+       /** Deletes a 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.
+        * @exception                   NativeException if the destruction failed.
+        */ 
+       protected void finalize() throws NativeException {
+               if (this.bind != 0)
+                       MsgNative.taskDestroy(this);
+       }
+
+       /**
+        * Sends the task on the mailbox identified by the specified name 
         *
-        * @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.
+        * @throws TimeoutException 
+        * @throws HostFailureException 
+        * @throws TransferFailureException 
+        */
+       public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
+               MsgNative.taskSend(mailbox, this, -1);
+       } 
+
+       /**
+        * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
         *
-        * @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.
+        * @exception  NativeException if the retrieval fails.
+        * @throws TimeoutException 
+        * @throws HostFailureException 
+        * @throws TransferFailureException 
         */
-       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
-        * before to use this method, otherwise the method throws the exception
-        * TaskAlreadyCreatedException.
-        *
-        * @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.
-        *
-        * @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 send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+               MsgNative.taskSend(mailbox, this, timeout);
+       } 
+
+       /**
+        * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) 
+        *
+        * @exception  TransferFailureException, HostFailureException, TimeoutException.
         */
-    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);
-       }
-       
-        /**
-         * 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);
-       }
-       
-       /**
-        * 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 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.
         */
-       public void cancel() throws JniException, NativeException{
-               Msg.taskCancel(this);
+
+       public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
+               return MsgNative.taskReceive(mailbox, -1.0, null);
        }
-       
+
        /**
-        * This method gets the computing amount of the task.
+        * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
         *
-        * @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  TransferFailureException, HostFailureException, TimeoutException if the retrieval fails.
         */
-       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);
-       }
-       
-       /**
-        * 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                               The new priority 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);
-       }
-       
-       /**
-        * 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 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.
         */
-       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.
+
+       public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
+               return MsgNative.taskReceive(mailbox, -1.0, 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.
         */
-       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 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
+        *
+        */ 
+       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
+        *
+        */ 
+       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.
+        *
+        */ 
+       public static int listenFromHost(String alias, Host host)   {
+               return MsgNative.taskListenFromHost(alias, host);
+       }
 }