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.
12 package org.simgrid.msg;
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 (all fields to 0 or null) */
30 MsgNative.taskCreate(this, null, 0, 0);
36 * Construct an new task with the specified processing amount and amount
39 * @param name Task's name
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.
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.
49 public Task(String name, double computeDuration, double messageSize) {
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 public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
62 MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
65 * * Getters / Setters * *
67 /** Gets the name of a task
70 public String getName() {
71 Process.ifInterruptedStop();
72 return MsgNative.taskGetName(this);
74 /** Gets the sender of the task */
76 Process.ifInterruptedStop();
77 return MsgNative.taskGetSender(this);
79 /** Gets the source of the task
82 public Host getSource() {
83 Process.ifInterruptedStop();
84 return MsgNative.taskGetSource(this);
86 /** Gets the computing amount of the task
89 public double getComputeDuration() {
90 Process.ifInterruptedStop();
91 return MsgNative.taskGetComputeDuration(this);
93 /** Gets the remaining computation of the task
96 public double getRemainingDuration() {
97 Process.ifInterruptedStop();
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 public void setPriority(double priority) {
109 Process.ifInterruptedStop();
110 MsgNative.taskSetPriority(this, priority);
113 * * Communication-related * *
118 * * Computation-related * *
121 * Executes a task on the location on which the process is running.
124 * @throws HostFailureException
125 * @throws TaskCancelledException
127 public void execute() throws HostFailureException,TaskCancelledException {
128 Process.ifInterruptedStop();
129 MsgNative.taskExecute(this);
135 public void cancel() {
136 Process.ifInterruptedStop();
137 MsgNative.taskCancel(this);
141 * @exception NativeException if the destruction failed.
143 protected void finalize() throws NativeException {
144 Process.ifInterruptedStop();
146 MsgNative.taskDestroy(this);
150 * Sends the task on the mailbox identified by the specified name
153 * @throws TimeoutException
154 * @throws HostFailureException
155 * @throws TransferFailureException
157 public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
158 Process.ifInterruptedStop();
159 MsgNative.taskSend(mailbox, this, -1);
163 * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds)
167 * @exception NativeException if the retrieval fails.
168 * @throws TimeoutException
169 * @throws HostFailureException
170 * @throws TransferFailureException
172 public void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
173 Process.ifInterruptedStop();
174 MsgNative.taskSend(mailbox, this, timeout);
178 * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
182 * @throws TransferFailureException
183 * @throws HostFailureException
184 * @throws TimeoutException
186 public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException {
187 Process.ifInterruptedStop();
188 MsgNative.taskSendBounded(alias, this, maxrate);
192 * Retrieves next task from the mailbox identified by the specified name
196 * @throws TransferFailureException
197 * @throws HostFailureException
198 * @throws TimeoutException
201 public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
202 Process.ifInterruptedStop();
203 return MsgNative.taskReceive(mailbox, -1.0, null);
207 * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds)
212 * @throws TransferFailureException
213 * @throws HostFailureException
214 * @throws TimeoutException
216 public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException {
217 Process.ifInterruptedStop();
218 return MsgNative.taskReceive(mailbox, timeout, null);
222 * Retrieves next task sent by a given host on the mailbox identified by the specified alias
227 * @throws TransferFailureException
228 * @throws TimeoutException
229 * @throws HostFailureException
232 public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
233 Process.ifInterruptedStop();
234 return MsgNative.taskReceive(mailbox, -1.0, host);
238 * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds)
244 * @throws TransferFailureException
245 * @throws HostFailureException
246 * @throws TimeoutException
248 public static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException {
249 Process.ifInterruptedStop();
250 return MsgNative.taskReceive(mailbox, timeout, host);
254 * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it
260 public static int listenFrom(String mailbox) {
261 Process.ifInterruptedStop();
262 return MsgNative.taskListenFrom(mailbox);
265 * Listen whether there is a waiting task on the mailbox identified by the specified alias
271 public static boolean listen(String mailbox) {
272 Process.ifInterruptedStop();
273 return MsgNative.taskListen(mailbox);
277 * 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.
284 public static int listenFromHost(String alias, Host host) {
285 Process.ifInterruptedStop();
286 return MsgNative.taskListenFromHost(alias, host);