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 {
23 void selectContextFactory(String name) throws NativeException;
25 /******************************************************************
26 * The natively implemented methods connected to the MSG Process *
27 ******************************************************************/
30 * The natively implemented method to create an MSG process.
32 * @param process The java process object to bind with the MSG native process.
33 * @param host A valid (binded) host where create the process.
35 * @see Process constructors.
38 void processCreate(Process process, Host host);
41 * The natively implemented method to kill all the process of the simulation.
43 * @param resetPID Should we reset the PID numbers. A negative number means no reset
44 * and a positive number will be used to set the PID of the next newly
47 * @return The function returns the PID of the next created process.
49 final static native int processKillAll(int resetPID);
52 * The natively implemented method to suspend an MSG process.
54 * @param process The valid (binded with a native process) java process to suspend.
56 * @exception NativeException if the SimGrid native code failed.
58 * @see Process.pause()
60 final static native void processSuspend(Process process) throws NativeException;
63 * The natively implemented method to kill a MSG process.
65 * @param process The valid (binded with a native process) java process to kill.
69 final static native void processKill(Process process);
72 * The natively implemented method to resume a suspended MSG process.
74 * @param process The valid (binded with a native process) java process to resume.
76 * @exception NativeException if the SimGrid native code failed.
78 * @see Process.restart()
80 final static native void processResume(Process process) throws NativeException;
83 * The natively implemented method to test if MSG process is suspended.
85 * @param process The valid (binded with a native process) java process to test.
87 * @return If the process is suspended the method retuns true. Otherwise the
88 * method returns false.
90 * @see Process.isSuspended()
92 final static native boolean processIsSuspended(Process process);
95 * The natively implemented method to get the host of a MSG process.
97 * @param process The valid (binded with a native process) java process to get the host.
99 * @return The method returns the host where the process is running.
101 * @exception NativeException if the SimGrid native code failed.
103 * @see Process.getHost()
105 final static native Host processGetHost(Process process) throws NativeException;
108 * The natively implemented method to get a MSG process from his PID.
110 * @param PID The PID of the process to get.
112 * @return The process with the specified PID.
114 * @exception NativeException if the SimGrid native code failed.
116 * @see Process.getFromPID()
118 final static native Process processFromPID(int PID) throws NativeException;
121 * The natively implemented method to get the PID of a MSG process.
123 * @param process The valid (binded with a native process) java process to get the PID.
125 * @return The PID of the specified process.
127 * @exception NativeException if the SimGrid native code failed.
129 * @see Process.getPID()
131 final static native int processGetPID(Process process) throws NativeException;
134 * The natively implemented method to get the PPID of a MSG process.
136 * @param process The valid (binded with a native process) java process to get the PID.
138 * @return The PPID of the specified process.
140 * @exception NativeException if the SimGrid native code failed.
142 * @see Process.getPPID()
144 final static native int processGetPPID(Process process) throws NativeException;
147 * The natively implemented method to get the current running process.
149 * @return The current process.
151 * @exception NativeException if the SimGrid native code failed.
153 * @see Process.currentProcess()
155 final static native Process processSelf() throws NativeException;
158 * The natively implemented method to migrate a process from his currnet host to a new host.
160 * @param process The (valid) process to migrate.
161 * @param host A (valid) host where move the process.
163 * @exception NativeException if the SimGrid native code failed.
165 * @see Process.migrate()
166 * @see Host.getByName()
168 final static native void processChangeHost(Process process, Host host) throws NativeException;
171 * The natively implemented native to request the current process to sleep
172 * until time seconds have elapsed.
174 * @param seconds The time the current process must sleep.
176 * @exception NativeException if the SimGrid native code failed.
178 * @see Process.waitFor()
180 final static native void processWaitFor(double seconds) throws NativeException;
183 * The natively implemented native method to exit a process.
185 * @see Process.exit()
187 final static native void processExit(Process process);
190 /******************************************************************
191 * The natively implemented methods connected to the MSG host *
192 ******************************************************************/
195 * The natively implemented method to get an host from his name.
197 * @param name The name of the host to get.
199 * @return The host having the specified name.
201 * @exception HostNotFoundException if there is no such host
202 * NativeException if the SimGrid native code failed.
204 * @see Host.getByName()
206 final static native Host hostGetByName(String name) throws HostNotFoundException, NativeException;
209 * The natively implemented method to get the name of an MSG host.
211 * @param host The host (valid) to get the name.
213 * @return The name of the specified host.
215 * @see Host.getName()
217 final static native String hostGetName(Host host);
220 * The natively implemented method to get the number of hosts of the simulation.
222 * @return The number of hosts of the simulation.
224 * @see Host.getNumber()
226 final static native int hostGetCount();
229 * The natively implemented method to get the host of the current runing process.
231 * @return The host of the current running process.
233 * @see Host.currentHost()
235 final static native Host hostSelf();
238 * The natively implemented method to get the speed of a MSG host.
240 * @param host The host to get the host.
242 * @return The speed of the specified host.
244 * @see Host.getSpeed()
247 final static native double hostGetSpeed(Host host);
250 * The natively implemented native method to test if an host is avail.
252 * @param host The host to test.
254 * @return If the host is avail the method returns true.
255 * Otherwise the method returns false.
257 * @see Host.isAvail()
259 final static native boolean hostIsAvail(Host host);
262 * The natively implemented native method to get all the hosts of the simulation.
264 * @return A array which contains all the hosts of simulation.
267 final static native Host[] allHosts();
270 * The natively implemented native method to get the number of running tasks on a host.
272 * @param The host concerned by the operation.
274 * @return The number of running tasks.
276 final static native int hostGetLoad(Host host);
278 /******************************************************************
279 * The natively implemented methods connected to the MSG task *
280 ******************************************************************/
283 * The natively implemented method to create a MSG task.
285 * @param name The name of th task.
286 * @param computeDuration A value of the processing amount (in flop) needed
287 * to process the task. If 0, then it cannot be executed
288 * with the execute() method. This value has to be >= 0.
289 * @param messageSize A value of amount of data (in bytes) needed to transfert
290 * this task. If 0, then it cannot be transfered this task.
291 * If 0, then it cannot be transfered with the get() and put()
292 * methods. This value has to be >= 0.
293 * @param task The java task object to bind with the native task to create.
295 * @exception IllegalArgumentException if compute duration <0 or message size <0
299 final static native void taskCreate(Task task, String name,
300 double computeDuration,
302 throws IllegalArgumentException;
305 * The natively implemented method to get the sender of a task.
307 * @param task The task (valid) to get the sender.
309 * @return The sender of the task.
311 * @see Task.getSender()
313 final static native Process taskGetSender(Task task);
316 * The natively implementd method to get the source of a task.
318 * @param task The task to get the source.
320 * @return The source of the task.
322 * @exception NativeException if the SimGrid native code failed.
324 * @see Task.getSource()
326 final static native Host taskGetSource(Task task) throws NativeException;
329 * The natively implemented method to get the name of the task.
331 * @param task The task to get the name.
333 * @return The name of the specified task.
335 * @see Task.getName()
337 final static native String taskGetName(Task task);
340 * The natively implemented method to cancel a task.
342 * @param task The task to cancel.
344 * @exception NativeException if the cancellation failed.
346 * @see Task.cancel().
348 final static native void taskCancel(Task task) throws NativeException;
351 * The natively implemented method to create a MSG parallel task.
353 * @param name The name of the parallel task.
354 * @param hosts The list of hosts implied by the parallel task.
355 * @param computeDurations The total number of operations that have to be performed
357 * @param messageSizes An array of doubles
359 * @see ParallelTask.create()
361 final static native void parallelTaskCreate(Task pTask, String name,
363 double[]computeDurations,
364 double[]messageSizes)
365 throws NullPointerException, IllegalArgumentException;
368 * The natively implemented method to get the computing amount of the task.
370 * @param task The task to get the computing amount.
372 * @return The computing amount of the specified task.
374 * @see Task.getComputeDuration()
376 final static native double taskGetComputeDuration(Task task);
379 * The natively implemented method to get the remaining computation
381 * @param task The task to get the remaining computation.
383 * @return The remaining computation of the specified task.
385 * @see Task.getRemainingDuration()
387 final static native double taskGetRemainingDuration(Task task);
390 * The natively implemented method to set the priority of a task.
392 * @param task The task to set the priority
394 * @param priority The new priority of the specified task.
396 * @see Task.setPriority()
398 final static native void taskSetPriority(Task task, double priority);
401 * The natively implemented method to destroy a MSG task.
403 * @param The task to destroy.
405 * @exception NativeException on error in the C world
407 * @see Task.destroy()
409 final static native void taskDestroy(Task task) throws NativeException;
412 * The natively implemented method to execute a MSG task.
414 * @param task The task to execute.
416 * @exception NativeException on error in the C world
418 * @see Task.execute()
420 final static native void taskExecute(Task task) throws NativeException;
424 /* ****************************************************************
425 * Communication methods thru mailboxes *
426 **************************************************************** */
429 final static native void taskSend(String alias, Task task, double timeout) throws TransferFailureException,HostFailureException,NativeException;
430 final static native Task taskReceive(String alias, double timeout, Host host) throws NativeException;
431 final static native int taskListenFrom(String alias) throws NativeException;
432 final static native boolean taskListen(String alias);
433 final static native int taskListenFromHost(String alias, Host host);
435 /* ***************************************************************
436 * Task sending methods *
437 *************************************************************** */
440 * The natively implemented method to send a task in a mailbox associated with an alias, with a bounded transmition
443 * @param alias The alias of the mailbox.
444 * @param task The task to put.
445 * @param max_rate The bounded transmition rate.
447 * @exception NativeException on error in the C world
449 final static native void taskSendBounded(String alias, Task task, double maxrate) throws NativeException;