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 * @exception NativeException if the SimGrid native code failed.
111 * @see Process.getFromPID()
113 final static native Process processFromPID(int PID) throws NativeException;
116 * The natively implemented method to get the PID of a MSG process.
118 * @param process The valid (binded with a native process) java process to get the PID.
120 * @return The PID of the specified process.
122 * @see Process.getPID()
124 final static native int processGetPID(Process process);
127 * The natively implemented method to get the PPID of a MSG process.
129 * @param process The valid (binded with a native process) java process to get the PID.
131 * @return The PPID of the specified process.
133 * @see Process.getPPID()
135 final static native int processGetPPID(Process process);
138 * The natively implemented method to get the current running process.
140 * @return The current process.
142 * @see Process.currentProcess()
144 final static native Process processSelf();
147 * The natively implemented method to migrate a process from his currnet host to a new host.
149 * @param process The (valid) process to migrate.
150 * @param host A (valid) host where move the process.
153 * @see Process.migrate()
154 * @see Host.getByName()
156 final static native void processChangeHost(Process process, Host host) ;
159 * The natively implemented native to request the current process to sleep
160 * until time seconds have elapsed.
162 * @param seconds The time the current process must sleep.
164 * @exception HostFailureException if the SimGrid native code failed.
166 * @see Process.waitFor()
168 final static native void processWaitFor(double seconds) throws HostFailureException;
171 * The natively implemented native method to exit a process.
173 * @see Process.exit()
175 final static native void processExit(Process process);
178 /******************************************************************
179 * The natively implemented methods connected to the MSG host *
180 ******************************************************************/
183 * The natively implemented method to get an host from his name.
185 * @param name The name of the host to get.
187 * @return The host having the specified name.
189 * @exception HostNotFoundException if there is no such host
192 * @see Host.getByName()
194 final static native Host hostGetByName(String name) throws HostNotFoundException;
197 * The natively implemented method to get the name of an MSG host.
199 * @param host The host (valid) to get the name.
201 * @return The name of the specified host.
203 * @see Host.getName()
205 final static native String hostGetName(Host host);
208 * The natively implemented method to get the number of hosts of the simulation.
210 * @return The number of hosts of the simulation.
212 * @see Host.getNumber()
214 final static native int hostGetCount();
217 * The natively implemented method to get the host of the current runing process.
219 * @return The host of the current running process.
221 * @see Host.currentHost()
223 final static native Host hostSelf();
226 * The natively implemented method to get the speed of a MSG host.
228 * @param host The host to get the host.
230 * @return The speed of the specified host.
232 * @see Host.getSpeed()
235 final static native double hostGetSpeed(Host host);
238 * The natively implemented native method to test if an host is avail.
240 * @param host The host to test.
242 * @return If the host is avail the method returns true.
243 * Otherwise the method returns false.
245 * @see Host.isAvail()
247 final static native boolean hostIsAvail(Host host);
250 * The natively implemented native method to get all the hosts of the simulation.
252 * @return A array which contains all the hosts of simulation.
255 final static native Host[] allHosts();
258 * The natively implemented native method to get the number of running tasks on a host.
260 * @param The host concerned by the operation.
262 * @return The number of running tasks.
264 final static native int hostGetLoad(Host host);
266 /******************************************************************
267 * The natively implemented methods connected to the MSG task *
268 ******************************************************************/
271 * The natively implemented method to create a MSG task.
273 * @param name The name of th task.
274 * @param computeDuration A value of the processing amount (in flop) needed
275 * to process the task. If 0, then it cannot be executed
276 * with the execute() method. This value has to be >= 0.
277 * @param messageSize A value of amount of data (in bytes) needed to transfert
278 * this task. If 0, then it cannot be transfered this task.
279 * If 0, then it cannot be transfered with the get() and put()
280 * methods. This value has to be >= 0.
281 * @param task The java task object to bind with the native task to create.
283 * @exception IllegalArgumentException if compute duration <0 or message size <0
287 final static native void taskCreate(Task task, String name,
288 double computeDuration,
290 throws IllegalArgumentException;
293 * The natively implemented method to get the sender of a task.
295 * @param task The task (valid) to get the sender.
297 * @return The sender of the task.
299 * @see Task.getSender()
301 final static native Process taskGetSender(Task task);
304 * The natively implementd method to get the source of a task.
306 * @param task The task to get the source.
308 * @return The source of the task.
311 * @see Task.getSource()
313 final static native Host taskGetSource(Task task);
316 * The natively implemented method to get the name of the task.
318 * @param task The task to get the name.
320 * @return The name of the specified task.
322 * @see Task.getName()
324 final static native String taskGetName(Task task);
327 * The natively implemented method to cancel a task.
329 * @param task The task to cancel.
332 * @see Task.cancel().
334 final static native void taskCancel(Task task);
337 * The natively implemented method to create a MSG parallel task.
339 * @param name The name of the parallel task.
340 * @param hosts The list of hosts implied by the parallel task.
341 * @param computeDurations The total number of operations that have to be performed
343 * @param messageSizes An array of doubles
345 * @see ParallelTask.create()
347 final static native void parallelTaskCreate(Task pTask, String name,
349 double[]computeDurations,
350 double[]messageSizes)
351 throws NullPointerException, IllegalArgumentException;
354 * The natively implemented method to get the computing amount of the task.
356 * @param task The task to get the computing amount.
358 * @return The computing amount of the specified task.
360 * @see Task.getComputeDuration()
362 final static native double taskGetComputeDuration(Task task);
365 * The natively implemented method to get the remaining computation
367 * @param task The task to get the remaining computation.
369 * @return The remaining computation of the specified task.
371 * @see Task.getRemainingDuration()
373 final static native double taskGetRemainingDuration(Task task);
376 * The natively implemented method to set the priority of a task.
378 * @param task The task to set the priority
380 * @param priority The new priority of the specified task.
382 * @see Task.setPriority()
384 final static native void taskSetPriority(Task task, double priority);
387 * The natively implemented method to destroy a MSG task.
389 * @param The task to destroy.
392 * @see Task.destroy()
394 final static native void taskDestroy(Task task) ;
397 * The natively implemented method to execute a MSG task.
399 * @param task The task to execute.
401 * @exception HostFailureException,TaskCancelledException on error in the C world
403 * @see Task.execute()
405 final static native void taskExecute(Task task) throws HostFailureException,TaskCancelledException;
407 /* ****************************************************************
408 * Communication methods thru mailboxes *
409 **************************************************************** */
411 final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,TimeoutException;
412 final static native Task taskReceive(String alias, double timeout, Host host) throws TransferFailureException,HostFailureException,TimeoutException;
413 final static native int taskListenFrom(String alias);
414 final static native boolean taskListen(String alias);
415 final static native int taskListenFromHost(String alias, Host host);
417 /* ***************************************************************
418 * Task sending methods *
419 *************************************************************** */
422 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
425 * @param alias The alias of the mailbox.
426 * @param task The task to put.
427 * @param max_rate The bounded transmition rate.
429 * @exception NativeException on error in the C world
431 final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;