2 * simgrid.msg.Task.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
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.
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.
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.
28 /* Default constructor (disabled) */
34 * Construct an new task with the specified processing amount and amount
37 * @param name Task's name
39 * @param computeDuration A value of the processing amount (in flop) needed to process the task.
40 * If 0, then it cannot be executed with the execute() method.
41 * This value has to be >= 0.
43 * @param messageSize A value of amount of data (in bytes) needed to transfert this task.
44 * If 0, then it cannot be transfered with the get() and put() methods.
45 * This value has to be >= 0.
47 * @exception JniException if the binding mechanism fails.
49 public Task(String name, double computeDuration, double messageSize) throws JniException {
50 MsgNative.taskCreate(this, name, computeDuration, messageSize);
53 * Construct an new parallel task with the specified processing amount and amount for each host
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.
61 * @exception JniException if the binding mecanism fails.
63 public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) throws JniException {
64 MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
67 * * Getters / Setters * *
69 /** gets the name of a task.
70 * @exception JniException if the binding mechanism fails.
72 public String getName() throws JniException {
73 return MsgNative.taskGetName(this);
75 /** gets the sender of the task.
76 * @exception JniException if the binding mechanism fails.
79 Process getSender() throws JniException {
80 return MsgNative.taskGetSender(this);
82 /** Gets the source of the task.
83 * @exception JniException if the binding mechanism fails.
85 public Host getSource() throws JniException, NativeException {
86 return MsgNative.taskGetSource(this);
88 /** gets the computing amount of the task.
89 * @exception JniException if the binding mechanism fails.
91 public double getComputeDuration() throws JniException {
92 return MsgNative.taskGetComputeDuration(this);
94 /** gets the remaining computation of the task.
95 * @exception JniException if the binding mechanism fails.
97 public double getRemainingDuration() throws JniException {
98 return MsgNative.taskGetRemainingDuration(this);
101 * This method sets the priority of the computation of the task.
102 * The priority doesn't affect the transfert rate. For example a
103 * priority of 2 will make the task receive two times more cpu than
106 * @param priority The new priority of the task.
108 * @exception JniException is the specified task is not valid (ie, not binded to a native task)
110 public void setPriority(double priority) throws JniException {
111 MsgNative.taskSetPriority(this, priority);
114 * * Communication-related * *
119 * * Computation-related * *
122 * This method execute a task on the location on which the
123 * process is running.
125 * @exception JniException if the binding mechanism fails.
126 * @exception NativeException if the execution failed.
128 public void execute() throws JniException, NativeException {
129 MsgNative.taskExecute(this);
132 * This method cancels a task.
134 * @exception JniException if the binding mechanism fails.
135 * @exception NativeException if the cancellation failed.
137 public void cancel() throws JniException, NativeException {
138 MsgNative.taskCancel(this);
142 * @exception JniException if the binding mechanism fails
143 * NativeException if the destruction failed.
145 protected void finalize() throws JniException, NativeException {
147 MsgNative.taskDestroy(this);
151 * Send the task on the mailbox identified by the specified name
153 * @exception JniException if the binding mechanism fails.
154 * @exception NativeException if the retrieval fails.
156 public void send(String mailbox) throws JniException,NativeException {
157 MsgNative.taskSend(mailbox, this, -1);
161 * Send the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
163 * @exception JniException if the binding mechanism fails.
164 * @exception NativeException if the retrieval fails.
166 public void send(String mailbox, double timeout) throws JniException,NativeException {
167 MsgNative.taskSend(mailbox, this, timeout);
171 * Send the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
173 * @exception JniException if the binding mechanism fails.
174 * @exception NativeException if the retrieval fails.
176 public void sendBounded(String alias, double maxrate) throws JniException,NativeException {
177 MsgNative.taskSendBounded(alias, this, maxrate);
181 * Retrieves next task from the mailbox identified by the specified name
183 * @exception JniException if the binding mechanism fails.
184 * @exception NativeException if the retrieval fails.
187 public static Task receive(String mailbox) throws JniException, NativeException {
188 return MsgNative.taskReceive(mailbox, -1.0, null);
192 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
194 * @exception JniException if the binding mechanism fails.
195 * @exception NativeException if the retrieval fails.
197 public static Task receive(String mailbox, double timeout) throws JniException, NativeException {
198 return MsgNative.taskReceive(mailbox, timeout, null);
202 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
204 * @exception JniException if the binding mechanism fails.
205 * @exception NativeException if the retrieval fails.
208 public static Task receive(String mailbox, Host host) throws JniException, NativeException {
209 return MsgNative.taskReceive(mailbox, -1.0, host);
213 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
215 * @exception JniException if the binding mechanism fails.
216 * @exception NativeException if the retrieval fails.
218 public static Task receive(String mailbox, double timeout, Host host) throws JniException, NativeException {
219 return MsgNative.taskReceive(mailbox, timeout, host);
223 * Test whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
225 * @exception JniException if the binding mechanism fails.
226 * @exception NativeException if the retrieval fails.
228 public static int listenFrom(String mailbox) throws JniException, NativeException {
229 return MsgNative.taskListenFrom(mailbox);
232 * Listen whether there is a waiting task on the mailbox identified by the specified alias
234 * @exception JniException if the binding mechanism fails.
235 * @exception NativeException if the retrieval fails.
237 public static boolean listen(String mailbox) throws JniException, NativeException {
238 return MsgNative.taskListen(mailbox);
242 * 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.
244 * @exception JniException if the binding mechanism fails.
245 * @exception NativeException if the retrieval fails.
247 public static int listenFromHost(String alias, Host host) throws JniException, NativeException {
248 return MsgNative.taskListenFromHost(alias, host);