2 * Contains all the native methods related to Process, Host and Task.
4 * Copyright 2006,2007,2010 The SimGrid Team
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.
14 /* FIXME: split into internal classes of Msg, Task, Host etc. */
17 * Contains all the native methods related to Process, Host and Task.
19 final class MsgNative {
22 void selectContextFactory(String name) throws NativeException;
24 /******************************************************************
25 * The natively implemented methods connected to the MSG Process *
26 ******************************************************************/
28 * The natively implemented method to create an MSG process.
30 * @param process The java process object to bind with the MSG native process.
31 * @param host A valid (binded) host where create the process.
33 * @see Process constructors.
36 void processCreate(Process process, Host host);
39 * The natively implemented method to kill all the process of the simulation.
41 * @param resetPID Should we reset the PID numbers. A negative number means no reset
42 * and a positive number will be used to set the PID of the next newly
45 * @return The function returns the PID of the next created process.
47 final static native int processKillAll(int resetPID);
50 * The natively implemented method to suspend an MSG process.
52 * @param process The valid (binded with a native process) java process to suspend.
54 * @see Process.pause()
56 final static native void processSuspend(Process process);
59 * The natively implemented method to kill a MSG process.
61 * @param process The valid (binded with a native process) java process to kill.
65 final static native void processKill(Process process);
68 * The natively implemented method to resume a suspended MSG process.
70 * @param process The valid (binded with a native process) java process to resume.
73 * @see Process.restart()
75 final static native void processResume(Process process);
78 * The natively implemented method to test if MSG process is suspended.
80 * @param process The valid (binded with a native process) java process to test.
82 * @return If the process is suspended the method retuns true. Otherwise the
83 * method returns false.
85 * @see Process.isSuspended()
87 final static native boolean processIsSuspended(Process process);
90 * The natively implemented method to get the host of a MSG process.
92 * @param process The valid (binded with a native process) java process to get the host.
94 * @return The method returns the host where the process is running.
96 * @exception HostNotFoundException if the SimGrid native code failed (initialization error?).
98 * @see Process.getHost()
100 final static native Host processGetHost(Process process);
103 * The natively implemented method to get a MSG process from his PID.
105 * @param PID The PID of the process to get.
107 * @return The process with the specified PID.
109 * @see Process.getFromPID()
111 final static native Process processFromPID(int PID) ;
114 * The natively implemented method to get the PID of a MSG process.
116 * @param process The valid (binded with a native process) java process to get the PID.
118 * @return The PID of the specified process.
120 * @see Process.getPID()
122 final static native int processGetPID(Process process);
125 * The natively implemented method to get the PPID of a MSG process.
127 * @param process The valid (binded with a native process) java process to get the PID.
129 * @return The PPID of the specified process.
131 * @see Process.getPPID()
133 final static native int processGetPPID(Process process);
136 * The natively implemented method to get the current running process.
138 * @return The current process.
140 * @see Process.currentProcess()
142 final static native Process processSelf();
145 * The natively implemented method to migrate a process from his currnet host to a new host.
147 * @param process The (valid) process to migrate.
148 * @param host A (valid) host where move the process.
151 * @see Process.migrate()
152 * @see Host.getByName()
154 final static native void processChangeHost(Process process, Host host) ;
157 * The natively implemented native to request the current process to sleep
158 * until time seconds have elapsed.
160 * @param seconds The time the current process must sleep.
162 * @exception HostFailureException if the SimGrid native code failed.
164 * @see Process.waitFor()
166 final static native void processWaitFor(double seconds) throws HostFailureException;
169 * The natively implemented native method to exit a process.
171 * @see Process.exit()
173 final static native void processExit(Process process);
176 /******************************************************************
177 * The natively implemented methods connected to the MSG host *
178 ******************************************************************/
181 * The natively implemented method to get an host from his name.
183 * @param name The name of the host to get.
185 * @return The host having the specified name.
187 * @exception HostNotFoundException if there is no such host
190 * @see Host.getByName()
192 final static native Host hostGetByName(String name) throws HostNotFoundException;
195 * The natively implemented method to get the name of an MSG host.
197 * @param host The host (valid) to get the name.
199 * @return The name of the specified host.
201 * @see Host.getName()
203 final static native String hostGetName(Host host);
206 * The natively implemented method to get the number of hosts of the simulation.
208 * @return The number of hosts of the simulation.
210 * @see Host.getNumber()
212 final static native int hostGetCount();
215 * The natively implemented method to get the host of the current runing process.
217 * @return The host of the current running process.
219 * @see Host.currentHost()
221 final static native Host hostSelf();
224 * The natively implemented method to get the speed of a MSG host.
226 * @param host The host to get the host.
228 * @return The speed of the specified host.
230 * @see Host.getSpeed()
233 final static native double hostGetSpeed(Host host);
236 * The natively implemented native method to test if an host is avail.
238 * @param host The host to test.
240 * @return If the host is avail the method returns true.
241 * Otherwise the method returns false.
243 * @see Host.isAvail()
245 final static native boolean hostIsAvail(Host host);
248 * The natively implemented native method to get all the hosts of the simulation.
250 * @return A array which contains all the hosts of simulation.
253 final static native Host[] allHosts();
256 * The natively implemented native method to get the number of running tasks on a host.
258 * @param The host concerned by the operation.
260 * @return The number of running tasks.
262 final static native int hostGetLoad(Host host);
264 /******************************************************************
265 * The natively implemented methods connected to the MSG task *
266 ******************************************************************/
269 * The natively implemented method to create a MSG task.
271 * @param name The name of th task.
272 * @param computeDuration A value of the processing amount (in flop) needed
273 * to process the task. If 0, then it cannot be executed
274 * with the execute() method. This value has to be >= 0.
275 * @param messageSize A value of amount of data (in bytes) needed to transfert
276 * this task. If 0, then it cannot be transfered this task.
277 * If 0, then it cannot be transfered with the get() and put()
278 * methods. This value has to be >= 0.
279 * @param task The java task object to bind with the native task to create.
281 * @exception IllegalArgumentException if compute duration <0 or message size <0
285 final static native void taskCreate(Task task, String name,
286 double computeDuration,
288 throws IllegalArgumentException;
291 * The natively implemented method to get the sender of a task.
293 * @param task The task (valid) to get the sender.
295 * @return The sender of the task.
297 * @see Task.getSender()
299 final static native Process taskGetSender(Task task);
302 * The natively implementd method to get the source of a task.
304 * @param task The task to get the source.
306 * @return The source of the task.
309 * @see Task.getSource()
311 final static native Host taskGetSource(Task task);
314 * The natively implemented method to get the name of the task.
316 * @param task The task to get the name.
318 * @return The name of the specified task.
320 * @see Task.getName()
322 final static native String taskGetName(Task task);
325 * The natively implemented method to cancel a task.
327 * @param task The task to cancel.
330 * @see Task.cancel().
332 final static native void taskCancel(Task task);
335 * The natively implemented method to create a MSG parallel task.
337 * @param name The name of the parallel task.
338 * @param hosts The list of hosts implied by the parallel task.
339 * @param computeDurations The total number of operations that have to be performed
341 * @param messageSizes An array of doubles
343 * @see ParallelTask.create()
345 final static native void parallelTaskCreate(Task pTask, String name,
347 double[]computeDurations,
348 double[]messageSizes)
349 throws NullPointerException, IllegalArgumentException;
352 * The natively implemented method to get the computing amount of the task.
354 * @param task The task to get the computing amount.
356 * @return The computing amount of the specified task.
358 * @see Task.getComputeDuration()
360 final static native double taskGetComputeDuration(Task task);
363 * The natively implemented method to get the remaining computation
365 * @param task The task to get the remaining computation.
367 * @return The remaining computation of the specified task.
369 * @see Task.getRemainingDuration()
371 final static native double taskGetRemainingDuration(Task task);
374 * The natively implemented method to set the priority of a task.
376 * @param task The task to set the priority
378 * @param priority The new priority of the specified task.
380 * @see Task.setPriority()
382 final static native void taskSetPriority(Task task, double priority);
385 * The natively implemented method to destroy a MSG task.
387 * @param The task to destroy.
390 * @see Task.destroy()
392 final static native void taskDestroy(Task task) ;
395 * The natively implemented method to execute a MSG task.
397 * @param task The task to execute.
399 * @exception HostFailureException,TaskCancelledException on error in the C world
401 * @see Task.execute()
403 final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException;
405 /* ****************************************************************
406 * Communication methods thru mailboxes *
407 **************************************************************** */
409 final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException;
410 final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException;
411 final static native int taskListenFrom(String alias);
412 final static native boolean taskListen(String alias);
413 final static native int taskListenFromHost(String alias, Host host);
415 /* ***************************************************************
416 * Task sending methods *
417 *************************************************************** */
420 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
423 * @param alias The alias of the mailbox.
424 * @param task The task to put.
425 * @param max_rate The bounded transmition rate.
427 * @exception NativeException on error in the C world
429 final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;