Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add dsendBounded + sendBounded with timeout
[simgrid.git] / org / simgrid / msg / Task.java
index 5242090..022961d 100644 (file)
@@ -1,12 +1,10 @@
 /*
- * simgrid.msg.Task.java       1.00 07/05/01
- *
- * Copyright 2006,2007 Martin Quinson, Malek Cherier           
+ * Copyright 2006-2012 The SimGrid Team.           
  * All right reserved. 
  *
  * This program is free software; you can redistribute 
  * it and/or modify it under the terms of the license 
- *(GNU LGPL) which comes with this package. 
+ * (GNU LGPL) which comes with this package.
  */
 
 package org.simgrid.msg;
@@ -22,15 +20,24 @@ 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;
 
+       private double messageSize;
+
+       static private Long idCpt = 0L;
+
+       private Long id;
+
        /** Default constructor (all fields to 0 or null) */
        public Task() {
                create(null, 0, 0);
+               this.messageSize = 0;
+               setId(idCpt);
+               idCpt++;
        }
 
        /* *              * *
@@ -52,6 +59,9 @@ public class Task {
         */ 
        public Task(String name, double computeDuration, double messageSize) {
                create(name, computeDuration, messageSize);
+               this.messageSize = messageSize;
+               setId(idCpt);
+               idCpt++;
        }
        /**
         * Construct an new parallel task with the specified processing amount and amount for each host
@@ -79,7 +89,7 @@ public class Task {
         *                        methods. This value has to be >= 0.
         * @exception             IllegalArgumentException if compute duration <0 or message size <0
         */
-       final native void create(String name,
+       private final native void create(String name,
                        double computeDuration,
                        double messageSize)
        throws IllegalArgumentException;                
@@ -93,7 +103,7 @@ public class Task {
         * @param messageSizes        An array of doubles
         *
         */
-       final native void parallelCreate(String name,
+       private final native void parallelCreate(String name,
                        Host[]hosts,
                        double[]computeDurations,
                        double[]messageSizes)
@@ -123,6 +133,11 @@ public class Task {
        /** Gets the remaining computation of the task
      */
        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
@@ -172,7 +187,15 @@ public class Task {
         *  with no way to retrieve whether the communication succeeded or not
         * 
         */
-       public native void dsend(String mailbox);       
+       public native void dsendBounded(String mailbox, double maxrate);
+
+
+       /** Send the task asynchronously on the mailbox identified by the specified name, 
+        *  with no way to retrieve whether the communication succeeded or not
+        * 
+        */
+       public native void dsend(String mailbox);
+       
        /**
         * Sends the task on the mailbox identified by the specified name 
         *
@@ -205,12 +228,37 @@ public class Task {
      * @throws HostFailureException
      * @throws TimeoutException
         */
-       public native void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException;
+       public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
+              sendBounded(alias,-1,maxrate);
+        }
+
+
+/**
+        * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) with a timeout
+        *
+     * @param alias
+     * @param timeout
+     * @param maxrate 
+     * @throws TransferFailureException
+     * @throws HostFailureException
+     * @throws TimeoutException
+        */
+       public void sendBounded(String alias, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
+              sendBounded(alias,timeout,maxrate);
+        }
+
+
        /**
         * Sends the task on the mailbox asynchronously
         */
        public native Comm isend(String mailbox);
+
+       /**
+        * Sends the task on the mailbox asynchronously (capping the sending rate to \a maxrate)
+        */
+       public native Comm isendBounded(String mailbox, double maxrate);
        
+
        /**
         * Starts listening for receiving a task from an asynchronous communication
         * @param mailbox
@@ -274,6 +322,19 @@ public class Task {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }
+
+       public double getMessageSize() {
+               return this.messageSize;
+       }
+
+       public Long getId() {
+               return id;
+       }
+
+       public void setId(Long id) {
+               this.id = id;
+       }
 }