Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reindent, no change at all
[simgrid.git] / src / java / simgrid / msg / Task.java
1 /*
2  * simgrid.msg.Task.java        1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
5  * All right reserved. 
6  *
7  * This program is free software; you can redistribute 
8  * it and/or modify it under the terms of the license 
9  *(GNU LGPL) which comes with this package. 
10  */
11
12 package simgrid.msg;
13
14 /**
15  * Since most scheduling algorithms rely on a concept of 
16  * task that can be either computed locally or transferred 
17  * on another processor, it seems to be the right level of 
18  * abstraction for our purposes. A task may then be defined 
19  * by a computing amount, a message size and some private
20  * data. To transfer a task you use an instance of the class
21  * Channel identified by an number.
22  *
23  * @author  Abdelmalek Cherier
24  * @author  Martin Quinson
25  * @version 1.00, 07/05/01
26  * @see Process
27  * @see Channel
28  * @since SimGrid 3.3
29  * @since JDK1.5011 
30  */
31 public class Task {
32         /**
33          * This attribute represents a bind between a java task object and
34          * a native task. Even if this attribute is public you must never
35          * access to it. It is set automaticatly during the build of the object.
36          */
37   public long bind = 0;
38
39         /**
40          * Default constructor (disabled)
41          */
42   protected Task() {
43   }
44         /**
45          * Construct an new task with the specified processing amount and amount
46          * of data needed.
47          *
48          * @param name                          The name of th task.
49          *
50          * @param computeDuration       A value of the processing amount (in flop) needed 
51          *                                                      to process the task. If 0, then it cannot be executed
52          *                                                      with the execute() method. This value has to be >= 0.
53          *
54          * @param messageSize           A value of amount of data (in bytes) needed to transfert 
55          *                                                      this task. If 0, then it cannot be transfered this task. 
56          *                                                      If 0, then it cannot be transfered with the get() and put() 
57          *                                                      methods. This value has to be >= 0.
58          *
59          * @exception                           InvalidTaskNameException if the specified name is null.
60          *                                                      InvalidComputeDuration if the specified compute duration is less than 0.
61          *                                                      InvalidMessageSizeException if the specified message size is less than 0.
62          */
63     public Task(String name, double computeDuration,
64                   double messageSize) throws JniException {
65
66     create(name, computeDuration, messageSize);
67   }
68         /**
69          * This method creates a new task with the specified features. The task
70          * creation means that the native task is created and binded with the
71          * java task instance. If the task is already created you must destroy it
72          * before to use this method, otherwise the method throws the exception
73          * TaskAlreadyCreatedException.
74          *
75          * @param name                          The name of the task.
76          * @param computeDuration       A value of the processing amount (in flop) needed 
77          *                                                      to process the task. If 0, then it cannot be executed
78          *                                                      with the execute() method. This value has to be >= 0.
79          * @param messageSize           A value of amount of data (in bytes) needed to transfert 
80          *                                                      this task. If 0, then it cannot be transfered this task. 
81          *                                                      If 0, then it cannot be transfered with the get() and put() 
82          *                                                      methods. This value has to be >= 0.
83          *
84          * @exception                           InvalidTaskNameException if the specified name is null.
85          *                                                      InvalidComputeDuration if the specified compute duration is less than 0.
86          *                                                      InvalidMessageSizeException if the specified message size is less than 0.
87          */
88     public void create(String name, double computeDuration,
89                          double messageSize) throws JniException {
90
91     if (this.bind == 0)
92       Msg.taskCreate(this, name, computeDuration, messageSize);
93   }
94         /**
95          * This method gets the sender of the task.
96          *
97          * @return                              The sender of the task.
98          *
99          * @exception                   InvalidTaskException is the specified task is not valid. A task
100          *                                              is invalid if it is not binded with a native task.
101          *
102          */ Process getSender() throws JniException {
103     return Msg.taskGetSender(this);
104   }
105          /**
106           * This method gets the source of the task.
107           *
108           * @return                             The source of the task. 
109           *
110           * @exception                  InvalidTaskException is the specified task is not valid. A task
111           *                                             is invalid if it is not binded with a native task.
112           */ public Host getSource() throws JniException, NativeException {
113     return Msg.taskGetSource(this);
114   }
115         /**
116          * This method gets the name of a task.
117          *
118          * @return                              The name of the task.
119          *
120          * @exception                   InvalidTaskException is the specified task is not valid. A task
121          *                                              is invalid if it is not binded with a native task.
122          */ public String getName() throws JniException {
123     return Msg.taskGetName(this);
124   }
125         /**
126          * This method cancels a task.
127          *
128          * @exception                   InvalidTaskException if the specified task is not valid. A task
129          *                                              is invalid if it is not binded with a native task.
130          *                                              MsgException if the cancelation failed.
131          */ public void cancel() throws JniException, NativeException {
132     Msg.taskCancel(this);
133   }
134         /**
135          * This method gets the computing amount of the task.
136          *
137          * @return                              The computing amount of the task.
138          *
139          * @exception                   InvalidTaskException is the specified task is not valid. A task
140          *                                              is invalid if it is not binded with a native task.
141          */ public double getComputeDuration() throws JniException {
142     return Msg.taskGetComputeDuration(this);
143   }
144         /**
145          * This method gets the remaining computation.
146          *
147          * @return                              The remaining duration. 
148          *
149          * @exception                   InvalidTaskException is the specified task is not valid. A task
150          *                                              is invalid if it is not binded with a native task.
151          */ public double getRemainingDuration() throws JniException {
152     return Msg.taskGetRemainingDuration(this);
153   }
154         /**
155          * This method sets the priority of the computation of the task.
156          * The priority doesn't affect the transfert rate. For example a
157          * priority of 2 will make the task receive two times more cpu than
158          * the other ones.
159          *
160          * @param                               The new priority of the task.
161          *
162          * @exception                   InvalidTaskException is the specified task is not valid. A task
163          *                                              is invalid if it is not binded with a native task.
164          */ public void setPrirority(double priority) throws JniException {
165     Msg.taskSetPriority(this, priority);
166   }
167         /**
168          * This method destroys a task.
169          *
170          * @exception                   InvalidTaskException is the specified task is not valid. A task
171          *                                              is invalid if it is not binded with a native task.
172          *                                              MsgException if the destruction failed.
173          */ public void destroy() throws JniException, NativeException {
174     if (this.bind != 0) {
175       Msg.taskDestroy(this);
176       this.bind = 0;
177     }
178   }
179         /**
180          * This method deletes a task.
181          *
182          * @exception                   InvalidTaskException is the specified task is not valid. A task
183          *                                              is invalid if it is not binded with a native task.
184          *                                              MsgException if the destruction failed.
185          */ protected void finalize() throws JniException, NativeException {
186     if (this.bind != 0)
187       Msg.taskDestroy(this);
188   }
189         /**
190          * This method execute a task on the location on which the
191          * process is running.
192          *
193          * @exception                   InvalidTaskException is the specified task is not valid. A task
194          *                                              is invalid if it is not binded with a native task.
195          *                                              MsgException if the destruction failed.
196          */ public void execute() throws JniException, NativeException {
197     Msg.taskExecute(this);
198 }}