Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
missing exceptions
[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  * A task is either something to compute somewhere, or something to exchange between two hosts (or both).
16  * It is defined by a computing amount and a message size.
17  *
18  */
19 public class Task {
20         /**
21          * This attribute represents a bind between a java task object and
22          * a native task. Even if this attribute is public you must never
23          * access to it. It is set automatically during the build of the object.
24          */
25         public long bind = 0;
26
27
28         /** Default constructor (all fields to 0 or null) */
29         public Task() {
30                 MsgNative.taskCreate(this, null, 0, 0);
31         }
32         /* *              * *
33          * * Constructors * *
34          * *              * */
35         /**
36          * Construct an new task with the specified processing amount and amount
37          * of data needed.
38          *
39          * @param name  Task's name
40          *
41          * @param computeDuration       A value of the processing amount (in flop) needed to process the task. 
42          *                              If 0, then it cannot be executed with the execute() method.
43          *                              This value has to be >= 0.
44          *
45          * @param messageSize           A value of amount of data (in bytes) needed to transfert this task.
46          *                              If 0, then it cannot be transfered with the get() and put() methods.
47          *                              This value has to be >= 0.
48          */ 
49         public Task(String name, double computeDuration, double messageSize) {
50                 MsgNative.taskCreate(this, name, computeDuration, messageSize);
51         }
52         /**
53          * Construct an new parallel task with the specified processing amount and amount for each host
54          * implied.
55          *
56          * @param name          The name of the parallel task.
57          * @param hosts         The list of hosts implied by the parallel task.
58          * @param computeDurations      The amount of operations to be performed by each host of \a hosts.
59          * @param messageSizes  A matrix describing the amount of data to exchange between hosts.
60          */ 
61         public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
62                 MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
63         }
64         /* *                   * *
65          * * Getters / Setters * *
66          * *                   * */
67         /** Gets the name of a task */ 
68         public String getName() {
69                 return MsgNative.taskGetName(this);
70         }
71         /** Gets the sender of the task */ 
72         Process getSender() {
73                 return MsgNative.taskGetSender(this);
74         }
75         /** Gets the source of the task */ 
76         public Host getSource() throws NativeException {
77                 return MsgNative.taskGetSource(this);
78         }
79         /** Gets the computing amount of the task */ 
80         public double getComputeDuration() {
81                 return MsgNative.taskGetComputeDuration(this);
82         }
83         /** Gets the remaining computation of the task */ 
84         public double getRemainingDuration() {
85                 return MsgNative.taskGetRemainingDuration(this);
86         }
87         /**
88          * This method sets the priority of the computation of the task.
89          * The priority doesn't affect the transfert rate. For example a
90          * priority of 2 will make the task receive two times more cpu than
91          * the other ones.
92          *
93          * @param priority      The new priority of the task.
94          */ 
95         public void setPriority(double priority) {
96                 MsgNative.taskSetPriority(this, priority);
97         }
98         /* *                       * *
99          * * Communication-related * *
100          * *                       * */
101
102
103         /* *                     * *
104          * * Computation-related * *
105          * *                     * */
106         /**
107          * Executes a task on the location on which the process is running.
108          *
109          * @exception NativeException if the execution failed.
110          */ 
111         public void execute() throws NativeException {
112                 MsgNative.taskExecute(this);
113         }
114         /**
115          * Cancels a task.
116          *
117          * @exception NativeException if the cancellation failed.
118          */ 
119         public void cancel() throws NativeException {
120                 MsgNative.taskCancel(this);
121         }
122         /** Deletes a task.
123          *
124          * @exception                   NativeException if the destruction failed.
125          */ 
126         protected void finalize() throws NativeException {
127                 if (this.bind != 0)
128                         MsgNative.taskDestroy(this);
129         }
130
131         /**
132          * Sends the task on the mailbox identified by the specified name 
133          *
134          * @exception  NativeException if the retrieval fails.
135          */
136         public void send(String mailbox) throws NativeException {
137                 MsgNative.taskSend(mailbox, this, -1);
138         } 
139
140         /**
141          * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
142          *
143          * @exception  NativeException if the retrieval fails.
144          */
145         public void send(String mailbox, double timeout) throws NativeException {
146                 MsgNative.taskSend(mailbox, this, timeout);
147         } 
148
149         /**
150          * Sends the task on the mailbox identified by the specified alias  (capping the sending rate to \a maxrate) 
151          *
152          * @exception  NativeException if the retrieval fails.
153          */
154         public void sendBounded(String alias, double maxrate) throws NativeException {
155                 MsgNative.taskSendBounded(alias, this, maxrate);
156         } 
157
158         /**
159          * Retrieves next task from the mailbox identified by the specified name
160          *
161          * @exception  NativeException if the retrieval fails.
162          */
163
164         public static Task receive(String mailbox) throws NativeException {
165                 return MsgNative.taskReceive(mailbox, -1.0, null);
166         }
167
168         /**
169          * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
170          *
171          * @exception  NativeException if the retrieval fails.
172          */
173         public static Task receive(String mailbox, double timeout) throws  NativeException {
174                 return MsgNative.taskReceive(mailbox, timeout, null);
175         }
176
177         /**
178          * Retrieves next task sent by a given host on the mailbox identified by the specified alias 
179          *
180          * @exception  NativeException if the retrieval fails.
181          */
182
183         public static Task receive(String mailbox, Host host) throws NativeException {
184                 return MsgNative.taskReceive(mailbox, -1.0, host);
185         }
186
187         /**
188          * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
189          *
190          * @exception  NativeException if the retrieval fails.
191          */
192         public static Task receive(String mailbox, double timeout, Host host) throws NativeException {
193                 return MsgNative.taskReceive(mailbox, timeout, host);
194         }
195
196         /**
197          * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
198          *
199          * @exception  NativeException if the retrieval fails.
200          */ 
201         public static int listenFrom(String mailbox) throws NativeException  {
202                 return MsgNative.taskListenFrom(mailbox);
203         }
204         /**
205          * Listen whether there is a waiting task on the mailbox identified by the specified alias
206          *
207          * @exception  NativeException if the retrieval fails.
208          */ 
209         public static boolean listen(String mailbox) throws NativeException  {
210                 return MsgNative.taskListen(mailbox);
211         }
212
213         /**
214          * 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.
215          *
216          * @exception  NativeException if the retrieval fails.
217          */ 
218         public static int listenFromHost(String alias, Host host) throws NativeException  {
219                 return MsgNative.taskListenFromHost(alias, host);
220         }
221 }