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.
72 * @exception NativeException if the SimGrid native code failed.
74 * @see Process.restart()
76 final static native void processResume(Process process) throws NativeException;
79 * The natively implemented method to test if MSG process is suspended.
81 * @param process The valid (binded with a native process) java process to test.
83 * @return If the process is suspended the method retuns true. Otherwise the
84 * method returns false.
86 * @see Process.isSuspended()
88 final static native boolean processIsSuspended(Process process);
91 * The natively implemented method to get the host of a MSG process.
93 * @param process The valid (binded with a native process) java process to get the host.
95 * @return The method returns the host where the process is running.
97 * @exception HostNotFoundException if the SimGrid native code failed (initialization error?).
99 * @see Process.getHost()
101 final static native Host processGetHost(Process process);
104 * The natively implemented method to get a MSG process from his PID.
106 * @param PID The PID of the process to get.
108 * @return The process with the specified PID.
110 * @exception NativeException if the SimGrid native code failed.
112 * @see Process.getFromPID()
114 final static native Process processFromPID(int PID) throws NativeException;
117 * The natively implemented method to get the PID of a MSG process.
119 * @param process The valid (binded with a native process) java process to get the PID.
121 * @return The PID of the specified process.
123 * @see Process.getPID()
125 final static native int processGetPID(Process process);
128 * The natively implemented method to get the PPID of a MSG process.
130 * @param process The valid (binded with a native process) java process to get the PID.
132 * @return The PPID of the specified process.
134 * @see Process.getPPID()
136 final static native int processGetPPID(Process process);
139 * The natively implemented method to get the current running process.
141 * @return The current process.
143 * @see Process.currentProcess()
145 final static native Process processSelf();
148 * The natively implemented method to migrate a process from his currnet host to a new host.
150 * @param process The (valid) process to migrate.
151 * @param host A (valid) host where move the process.
153 * @exception NativeException if the SimGrid native code failed.
155 * @see Process.migrate()
156 * @see Host.getByName()
158 final static native void processChangeHost(Process process, Host host) throws NativeException;
161 * The natively implemented native to request the current process to sleep
162 * until time seconds have elapsed.
164 * @param seconds The time the current process must sleep.
166 * @exception NativeException if the SimGrid native code failed.
168 * @see Process.waitFor()
170 final static native void processWaitFor(double seconds) throws NativeException;
173 * The natively implemented native method to exit a process.
175 * @see Process.exit()
177 final static native void processExit(Process process);
180 /******************************************************************
181 * The natively implemented methods connected to the MSG host *
182 ******************************************************************/
185 * The natively implemented method to get an host from his name.
187 * @param name The name of the host to get.
189 * @return The host having the specified name.
191 * @exception HostNotFoundException if there is no such host
192 * NativeException if the SimGrid native code failed.
194 * @see Host.getByName()
196 final static native Host hostGetByName(String name) throws HostNotFoundException, NativeException;
199 * The natively implemented method to get the name of an MSG host.
201 * @param host The host (valid) to get the name.
203 * @return The name of the specified host.
205 * @see Host.getName()
207 final static native String hostGetName(Host host);
210 * The natively implemented method to get the number of hosts of the simulation.
212 * @return The number of hosts of the simulation.
214 * @see Host.getNumber()
216 final static native int hostGetCount();
219 * The natively implemented method to get the host of the current runing process.
221 * @return The host of the current running process.
223 * @see Host.currentHost()
225 final static native Host hostSelf();
228 * The natively implemented method to get the speed of a MSG host.
230 * @param host The host to get the host.
232 * @return The speed of the specified host.
234 * @see Host.getSpeed()
237 final static native double hostGetSpeed(Host host);
240 * The natively implemented native method to test if an host is avail.
242 * @param host The host to test.
244 * @return If the host is avail the method returns true.
245 * Otherwise the method returns false.
247 * @see Host.isAvail()
249 final static native boolean hostIsAvail(Host host);
252 * The natively implemented native method to get all the hosts of the simulation.
254 * @return A array which contains all the hosts of simulation.
257 final static native Host[] allHosts();
260 * The natively implemented native method to get the number of running tasks on a host.
262 * @param The host concerned by the operation.
264 * @return The number of running tasks.
266 final static native int hostGetLoad(Host host);
268 /******************************************************************
269 * The natively implemented methods connected to the MSG task *
270 ******************************************************************/
273 * The natively implemented method to create a MSG task.
275 * @param name The name of th task.
276 * @param computeDuration A value of the processing amount (in flop) needed
277 * to process the task. If 0, then it cannot be executed
278 * with the execute() method. This value has to be >= 0.
279 * @param messageSize A value of amount of data (in bytes) needed to transfert
280 * this task. If 0, then it cannot be transfered this task.
281 * If 0, then it cannot be transfered with the get() and put()
282 * methods. This value has to be >= 0.
283 * @param task The java task object to bind with the native task to create.
285 * @exception IllegalArgumentException if compute duration <0 or message size <0
289 final static native void taskCreate(Task task, String name,
290 double computeDuration,
292 throws IllegalArgumentException;
295 * The natively implemented method to get the sender of a task.
297 * @param task The task (valid) to get the sender.
299 * @return The sender of the task.
301 * @see Task.getSender()
303 final static native Process taskGetSender(Task task);
306 * The natively implementd method to get the source of a task.
308 * @param task The task to get the source.
310 * @return The source of the task.
312 * @exception NativeException if the SimGrid native code failed.
314 * @see Task.getSource()
316 final static native Host taskGetSource(Task task) throws NativeException;
319 * The natively implemented method to get the name of the task.
321 * @param task The task to get the name.
323 * @return The name of the specified task.
325 * @see Task.getName()
327 final static native String taskGetName(Task task);
330 * The natively implemented method to cancel a task.
332 * @param task The task to cancel.
334 * @exception NativeException if the cancellation failed.
336 * @see Task.cancel().
338 final static native void taskCancel(Task task) throws NativeException;
341 * The natively implemented method to create a MSG parallel task.
343 * @param name The name of the parallel task.
344 * @param hosts The list of hosts implied by the parallel task.
345 * @param computeDurations The total number of operations that have to be performed
347 * @param messageSizes An array of doubles
349 * @see ParallelTask.create()
351 final static native void parallelTaskCreate(Task pTask, String name,
353 double[]computeDurations,
354 double[]messageSizes)
355 throws NullPointerException, IllegalArgumentException;
358 * The natively implemented method to get the computing amount of the task.
360 * @param task The task to get the computing amount.
362 * @return The computing amount of the specified task.
364 * @see Task.getComputeDuration()
366 final static native double taskGetComputeDuration(Task task);
369 * The natively implemented method to get the remaining computation
371 * @param task The task to get the remaining computation.
373 * @return The remaining computation of the specified task.
375 * @see Task.getRemainingDuration()
377 final static native double taskGetRemainingDuration(Task task);
380 * The natively implemented method to set the priority of a task.
382 * @param task The task to set the priority
384 * @param priority The new priority of the specified task.
386 * @see Task.setPriority()
388 final static native void taskSetPriority(Task task, double priority);
391 * The natively implemented method to destroy a MSG task.
393 * @param The task to destroy.
395 * @exception NativeException on error in the C world
397 * @see Task.destroy()
399 final static native void taskDestroy(Task task) throws NativeException;
402 * The natively implemented method to execute a MSG task.
404 * @param task The task to execute.
406 * @exception NativeException on error in the C world
408 * @see Task.execute()
410 final static native void taskExecute(Task task) throws NativeException;
412 /* ****************************************************************
413 * Communication methods thru mailboxes *
414 **************************************************************** */
416 final static native void taskSend(String alias, Task task, double timeout) throws NativeException,TransferFailureException,HostFailureException,TimeoutException;
417 final static native Task taskReceive(String alias, double timeout, Host host) throws NativeException;
418 final static native int taskListenFrom(String alias) throws NativeException;
419 final static native boolean taskListen(String alias);
420 final static native int taskListenFromHost(String alias, Host host);
422 /* ***************************************************************
423 * Task sending methods *
424 *************************************************************** */
427 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
430 * @param alias The alias of the mailbox.
431 * @param task The task to put.
432 * @param max_rate The bounded transmition rate.
434 * @exception NativeException on error in the C world
436 final static native void taskSendBounded(String alias, Task task, double maxrate) throws NativeException;