Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make bind atributes private (we don't want users to mess with it)
[simgrid.git] / org / simgrid / msg / Task.java
index 441ccb7..d0b5d03 100644 (file)
@@ -22,8 +22,11 @@ public class Task {
         * a native task. Even if this attribute is public you must never
         * access to it. It is set automatically during the build of the object.
         */
-       public long bind = 0;
-
+       private long bind = 0;
+       /**
+        * Task name
+        */
+       protected String name;
 
        /** Default constructor (all fields to 0 or null) */
        public Task() {
@@ -98,33 +101,33 @@ public class Task {
        /* *                   * *
         * * Getters / Setters * *
         * *                   * */
-    /** Gets the name of a task
-     * FIXME: Cache it.
-     * @return
+    /** 
+     * Gets the name of a task
      */
-       public native String getName();
-       /** Gets the sender of the task */ 
-       Process getSender() {
-               return MsgNative.taskGetSender(this);
+       public String getName() {
+               return name;
        }
-    /** Gets the source of the task
-     * @return
+       /**
+        * Gets the sender of the task 
+        * Returns null if the task hasn't been sent yet
+        */
+       public native Process getSender();
+       /** Gets the source of the task.
+        * Returns null if the task hasn't been sent yet.
      */
-       public Host getSource()  {
-               return MsgNative.taskGetSource(this);
-       }
-    /** Gets the computing amount of the task
-     * @return
+       public native Host getSource();   
+       /** Gets the computing amount of the task
+     * FIXME: Cache it !
      */
-       public double getComputeDuration() {
-               return MsgNative.taskGetComputeDuration(this);
-       }
-    /** Gets the remaining computation of the task
-     * @return
+       public native double getComputeDuration();
+       /** Gets the remaining computation of the task
      */
-       public double getRemainingDuration() {
-               return MsgNative.taskGetRemainingDuration(this);
-       }
+       public native double getRemainingDuration();
+       /**
+        * Sets the name of the task
+        * @param name the new task name.c
+        */
+       public native void setName(String name);
        /**
         * This method sets the priority of the computation of the task.
         * The priority doesn't affect the transfer rate. For example a
@@ -133,14 +136,12 @@ public class Task {
         *
         * @param priority      The new priority of the task.
         */ 
-       public void setPriority(double priority) {
-               MsgNative.taskSetPriority(this, priority);
-       }
-       /* *                       * *
-        * * Communication-related * *
-        * *                       * */
-
-
+       public native void setPriority(double priority);
+       /**
+        * Set the computation amount needed to process the task
+        * @param computationAmount the amount of computation needed to process the task
+        */
+       public native void setComputeDuration(double computationAmount);
        /* *                     * *
         * * Computation-related * *
         * *                     * */
@@ -151,16 +152,12 @@ public class Task {
      * @throws HostFailureException
      * @throws TaskCancelledException
      */
-       public void execute() throws HostFailureException,TaskCancelledException {
-               MsgNative.taskExecute(this);
-       }
+       public native void execute() throws HostFailureException,TaskCancelledException;
        /**
         * Cancels a task.
         *
         */ 
-       public void cancel()  {
-               MsgNative.taskCancel(this);
-       }
+       public native void cancel();
        /** Deletes a task.
         *
         * @exception                   NativeException if the destruction failed.
@@ -172,15 +169,15 @@ public class Task {
         * The natively implemented method to destroy a MSG task.
         */
        protected native void destroy();
+       /* *                       * *
+        * * Communication-related * *
+        * *                       * */
 
        /** Send the task asynchronously on the mailbox identified by the specified name, 
         *  with no way to retrieve whether the communication succeeded or not
         * 
         */
-       public void dsend(String mailbox) {
-               MsgNative.taskDSend(mailbox, this);
-       } 
-       
+       public native void dsend(String mailbox);       
        /**
         * Sends the task on the mailbox identified by the specified name 
         *
@@ -190,7 +187,7 @@ public class Task {
         * @throws TransferFailureException 
         */
        public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, this, -1);
+               send(mailbox, -1);
        } 
 
        /**
@@ -203,10 +200,7 @@ public class Task {
         * @throws HostFailureException 
         * @throws TransferFailureException 
         */
-       public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSend(mailbox, this, timeout);
-       } 
-
+       public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
        /**
         * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) 
         *
@@ -216,9 +210,7 @@ public class Task {
      * @throws HostFailureException
      * @throws TimeoutException
         */
-       public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
-               MsgNative.taskSendBounded(alias, this, maxrate);
-       } 
+       public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
        /**
         * Sends the task on the mailbox asynchronously
         */
@@ -227,21 +219,16 @@ public class Task {
        /**
         * Starts listening for receiving a task from an asynchronous communication
         * @param mailbox
-        * @return
         */
        public static native Comm irecv(String mailbox);
        /**
         * Retrieves next task from the mailbox identified by the specified name
         *
      * @param mailbox
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
         */
 
        public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, null);
+               return receive(mailbox, -1.0, null);
        }
 
        /**
@@ -249,13 +236,9 @@ public class Task {
         *
      * @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);
+               return receive(mailbox, timeout, null);
        }
 
        /**
@@ -263,14 +246,10 @@ public class Task {
         *
      * @param mailbox
      * @param host
-     * @return
-     * @throws TransferFailureException
-     * @throws TimeoutException
-     * @throws HostFailureException
         */
 
        public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
-               return MsgNative.taskReceive(mailbox, -1.0, host);
+               return receive(mailbox, -1.0, host);
        }
 
        /**
@@ -279,47 +258,21 @@ public class Task {
      * @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);
-       }
-
+       public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException;
        /**
         * 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);
-       }
+       public native static int listenFrom(String 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);
-       }
+       public native static boolean listen(String 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);
-       }
+       public native static int listenFromHost(String alias, Host host);
        
        /**
         * Class initializer, to initialize various JNI stuff