Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deleted simulatedSleep, use waitFor instead. Moved everything from MsgNative to their...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 9 May 2012 11:10:32 +0000 (13:10 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 9 May 2012 11:10:32 +0000 (13:10 +0200)
16 files changed:
CMakeLists.txt
examples/async/Forwarder.java
examples/async/Master.java
examples/async/Slave.java
org/simgrid/msg/ApplicationHandler.java
org/simgrid/msg/Host.java
org/simgrid/msg/MsgNative.java [deleted file]
org/simgrid/msg/Process.java
org/simgrid/msg/Task.java
src/jmsg.c
src/jmsg.h
src/jmsg_host.c
src/jmsg_host.h
src/jmsg_process.c
src/jmsg_process.h
src/jmsg_task.c

index 086cdfb..76e99d8 100644 (file)
@@ -100,7 +100,6 @@ set(JMSG_JAVA_SRC
        org/simgrid/msg/JniException.java
        org/simgrid/msg/Msg.java
        org/simgrid/msg/MsgException.java
-       org/simgrid/msg/MsgNative.java
        org/simgrid/msg/NativeException.java
        org/simgrid/msg/Process.java
        org/simgrid/msg/ProcessKilled.java
index d17bb93..3ed84f3 100644 (file)
@@ -37,7 +37,7 @@ public class Forwarder extends Process {
                                        Task tf = new FinalizeTask();
                                        tf.dsend("slave_"+cpt);
                                }
-                               simulatedSleep(20);
+                               waitFor(20);
                                break;
                        }
                        int dest = firstOutput + (taskCount % slavesCount);
index 6c28a36..dd4c313 100644 (file)
@@ -11,6 +11,7 @@ package async;
 import java.util.ArrayList;
 
 import org.simgrid.msg.Comm;
+import org.simgrid.msg.Process;
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.MsgException;
 import org.simgrid.msg.Task;
@@ -30,11 +31,11 @@ public class Master extends Process {
                int slavesCount = Integer.valueOf(args[3]).intValue();
 
                Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
-               
                ArrayList<Comm> comms = new ArrayList<Comm>();
                
                for (int i = 0; i < tasksCount; i++) {
                        Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
+                       Process p = task.getSender();
                        Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
                        //task.send("slave_"+(i%slavesCount));
                        Comm comm = task.isend("slave_"+(i%slavesCount));
@@ -53,7 +54,7 @@ public class Master extends Process {
                                        e.printStackTrace();
                                }
                        }
-                       simulatedSleep(1);
+                       waitFor(1);
                }
                
                Msg.info("All tasks have been dispatched. Let's tell (asynchronously) everybody the computation is over, and sleep 20s so that nobody gets a message from a terminated process.");
@@ -62,7 +63,7 @@ public class Master extends Process {
                        FinalizeTask task = new FinalizeTask();
                        task.dsend("slave_"+(i%slavesCount));
                }
-               simulatedSleep(20);
+               waitFor(20);
 
                Msg.info("Goodbye now!");
        }
index ab07cac..e7e92d6 100644 (file)
@@ -50,7 +50,7 @@ public class Slave extends Process {
                                                comm = null;                                                    
                                        }
                                        else {
-                                               simulatedSleep(1);
+                                               waitFor(1);
                                        }
                                }
                        }
@@ -59,6 +59,6 @@ public class Slave extends Process {
                        }
                }
                Msg.info("Received Finalize. I'm done. See you!");
-               simulatedSleep(20);
+               waitFor(20);
        }
 }
\ No newline at end of file
index ae57e0f..3003ec3 100644 (file)
@@ -103,7 +103,7 @@ public final class ApplicationHandler {
                                 process.name = function;
                                 process.id = org.simgrid.msg.Process.nextProcessId++;
 
-                                MsgNative.processCreate(process, hostName);
+                               process.create(hostName);
                                 Vector<String> args_ = args;
                                 int size = args_.size();
 
index 8e09849..11e6bda 100644 (file)
@@ -80,7 +80,7 @@ public class Host {
         * This static method returns the count of the installed hosts.
         *
         * @return                      The count of the installed hosts.
-        * FIXME: Not implemented... ?
+        * FIXME: Not implemented.
         */ 
        public native static int getCount();
 
@@ -97,28 +97,24 @@ public class Host {
         * @return                      An array containing all the hosts installed.
         *
         */ 
-       public static Host[] all()  {
-               return MsgNative.allHosts();
-       }
+       public native static Host[] all();
 
        /**
         * This method returns the name of a host.
-        *
+        * FIXME: Cache it.
         * @return                      The name of the host.
         *
         */ 
        public native String getName();
        /**
         * Sets the data of the host.
-        *
-     *
      * @param data
      */
        public void setData(Object data) {
                this.data = data;
        } 
        /**
-        * Gets the data of the host.
+        * Gets the d   ata of the host.
      *
      * @return
      */
diff --git a/org/simgrid/msg/MsgNative.java b/org/simgrid/msg/MsgNative.java
deleted file mode 100644 (file)
index f6c28a9..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Contains all the native methods related to Process, Host and Task.
- *
- * Copyright 2006,2007,2010 The SimGrid Team           
- * All right reserved. 
- *
- * This program is free software; you can redistribute 
- * it and/or modify it under the terms of the license 
- *(GNU LGPL) which comes with this package. 
- */
-
-package org.simgrid.msg;
-
-import org.simgrid.msg.Process;
-
-/* FIXME: split into internal classes of Msg, Task, Host etc. */
-
-/**
- *  Contains all the native methods related to Process, Host and Task.
- */
-final class MsgNative {
-
-       /******************************************************************
-        * The natively implemented methods connected to the MSG Process  *
-        ******************************************************************/
-       /**
-        * The natively implemented method to create an MSG process.
-        *
-        * @param process The java process object to bind with the MSG native process.
-        * @param host    A valid (binded) host where create the process.
-        *
-        * @see  Process constructors.
-        */
-       final static native
-       void processCreate(Process process, String hostName) throws HostNotFoundException;
-
-       /**
-        * The natively implemented method to kill all the process of the simulation.
-        *
-        * @param resetPID        Should we reset the PID numbers. A negative number means no reset
-        *                        and a positive number will be used to set the PID of the next newly
-        *                        created process.
-        *
-        * @return                The function returns the PID of the next created process.
-        */
-       final static native int processKillAll(int resetPID);
-
-       /**
-        * The natively implemented method to suspend an MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to suspend.
-        *
-        * @see                 Process.pause()
-        */
-       final static native void processSuspend(Process process);
-
-       /**
-        * The natively implemented method to kill a MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to kill.
-        *
-        * @see                 Process.kill()
-        */
-       final static native void processKill(Process process);
-
-       /**
-        * The natively implemented method to resume a suspended MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to resume.
-        *
-        *
-        * @see                 Process.restart()
-        */
-       final static native void processResume(Process process);
-
-       /**
-        * The natively implemented method to test if MSG process is suspended.
-        *
-        * @param process        The valid (binded with a native process) java process to test.
-        *
-        * @return                If the process is suspended the method retuns true. Otherwise the
-        *                        method returns false.
-        *
-        * @see                 Process.isSuspended()
-        */
-       final static native boolean processIsSuspended(Process process);
-
-       /**
-        * The natively implemented method to get the host of a MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to get the host.
-        *
-        * @return                The method returns the host where the process is running.
-        *
-        * @exception            HostNotFoundException if the SimGrid native code failed (initialization error?).
-        *
-        * @see                 Process.getHost()
-        */
-       final static native Host processGetHost(Process process);
-
-       /**
-        * The natively implemented method to get a MSG process from his PID.
-        *
-        * @param PID            The PID of the process to get.
-        *
-        * @return                The process with the specified PID.
-        *
-        * @see                 Process.getFromPID()
-        */
-       final static native Process processFromPID(int PID) ;
-
-       /**
-        * The natively implemented method to get the PID of a MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to get the PID.
-        *
-        * @return                The PID of the specified process.
-        *
-        * @see                 Process.getPID()
-        */
-       final static native int processGetPID(Process process);
-
-       /**
-        * The natively implemented method to get the PPID of a MSG process.
-        *
-        * @param process        The valid (binded with a native process) java process to get the PID.
-        *
-        * @return                The PPID of the specified process.
-        *
-        * @see                 Process.getPPID()
-        */
-       final static native int processGetPPID(Process process);
-
-       /**
-        * The natively implemented method to get the current running process.
-        *
-        * @return             The current process.
-        *
-        * @see                Process.currentProcess()
-        */
-       final static native Process processSelf();
-
-       /**
-        * The natively implemented method to migrate a process from his currnet host to a new host.
-        *
-        * @param process        The (valid) process to migrate.
-        * @param host            A (valid) host where move the process.
-        *
-        *
-        * @see                Process.migrate()
-        * @see                Host.getByName()
-        */
-       final static native void processMigrate(Process process, Host host) ;
-
-       /**
-        * The natively implemented native to request the current process to sleep 
-        * until time seconds have elapsed.
-        *
-        * @param seconds        The time the current process must sleep.
-        *
-        * @exception            HostFailureException if the SimGrid native code failed.
-        *
-        * @see                 Process.waitFor()
-        */
-       final static native void processWaitFor(double seconds) throws HostFailureException;
-
-       /**
-        * The natively implemented native method to exit a process.
-        *
-        * @see                Process.exit()
-        */
-       final static native void processExit(Process process);
-
-
-       /******************************************************************
-        * The natively implemented methods connected to the MSG host     *
-        ******************************************************************/
-
-       /**
-        * The natively implemented native method to get all the hosts of the simulation.
-        *
-        * @return                A array which contains all the hosts of simulation.
-        */
-
-       final static native Host[] allHosts();
-
-}
index 5d0340d..bd3f943 100644 (file)
@@ -68,9 +68,6 @@ public abstract class Process extends Thread {
         */
        public long id;
 
-    /**
-     *
-     */
     public Hashtable<String,String> properties;
 
        /**
@@ -89,13 +86,7 @@ public abstract class Process extends Thread {
         * The host of the process
         */
        protected Host host = null;
-    /**
-     *
-     * @return
-     */
-    public String msgName() {
-               return this.name;
-       }
+
        /** The arguments of the method function of the process. */     
        public Vector<String> args;
 
@@ -183,14 +174,17 @@ public abstract class Process extends Thread {
                        this.args.addAll(Arrays.asList(args));
 
                try {
-                       MsgNative.processCreate(this, host.getName());
+                       create(host.getName());
                } catch (HostNotFoundException e) {
                        throw new RuntimeException("The impossible happened (yet again): the host that I have were not found",e);
                }
                
        }
-
-
+       /**
+        * The natively implemented method to create an MSG process.
+        * @param host    A valid (binded) host where create the process.
+        */
+       protected native void create(String hostName) throws HostNotFoundException;
        /**
         * This method kills all running process of the simulation.
         *
@@ -201,19 +195,15 @@ public abstract class Process extends Thread {
         * @return                              The function returns the PID of the next created process.
         *                      
         */ 
-       public static int killAll(int resetPID) {
-               return MsgNative.processKillAll(resetPID);
-       }
-
+       public static native int killAll(int resetPID);
        /**
         * This method sets a flag to indicate that this thread must be killed. End user must use static method kill
         *
         * @return                              
         *                      
         */ 
-       public void nativeStop()
-       {
-       nativeStop = true;
+       public void nativeStop() {
+               nativeStop = true;
        }
        /**
         * getter for the flag that indicates that this thread must be killed
@@ -221,8 +211,7 @@ public abstract class Process extends Thread {
         * @return                              
         *                      
         */ 
-       public boolean getNativeStop()
-       {
+       public boolean getNativeStop() {
                return nativeStop;
        }
 
@@ -233,8 +222,7 @@ public abstract class Process extends Thread {
         */
        public void kill() {
                 nativeStop();
-                Msg.info("Process " + msgName() + " will be killed.");                         
-                                
+                Msg.info("Process " + msgName() + " will be killed.");                                                  
        }
 
        /**
@@ -242,38 +230,32 @@ public abstract class Process extends Thread {
         * waiting for the completion.
         *
         */
-       public void pause() {
-               MsgNative.processSuspend(this);
-       }
+       public native void pause();
        /**
         * Resumes a suspended process by resuming the task on which it was
         * waiting for the completion.
         *
         *
         */ 
-       public void restart()  {
-               MsgNative.processResume(this);
-       }
+       public native void restart();
        /**
         * Tests if a process is suspended.
         *
         * @return                              The method returns true if the process is suspended.
         *                                              Otherwise the method returns false.
         */ 
-       public boolean isSuspended() {
-               return MsgNative.processIsSuspended(this);
+       public native boolean isSuspended();
+       /**
+        * Returns the name of the process
+        */
+       public String msgName() {
+               return this.name;
        }
        /**
-        * Returns the host of a process.
-        *
+        * Returns the host of the process.
         * @return                              The host instance of the process.
-        *
-        *
         */ 
        public Host getHost() {
-               if (this.host == null) {
-                       this.host = MsgNative.processGetHost(this);
-               }
                return this.host;
        }
        /**
@@ -285,9 +267,7 @@ public abstract class Process extends Thread {
         *
         * @exception                   NativeException on error in the native SimGrid code
         */ 
-       public static Process fromPID(int PID) throws NativeException {
-               return MsgNative.processFromPID(PID);
-       }
+       public static native Process fromPID(int PID) throws NativeException;
        /**
         * This method returns the PID of the process.
         *
@@ -295,9 +275,6 @@ public abstract class Process extends Thread {
         *
         */ 
        public int getPID()  {
-               if (pid == -1) {
-                       pid = MsgNative.processGetPID(this);
-               }
                return pid;
        }
        /**
@@ -307,9 +284,6 @@ public abstract class Process extends Thread {
         *
         */ 
        public int getPPID()  {
-               if (ppid == -1) {
-                       ppid = MsgNative.processGetPPID(this);
-               }
                return ppid;
        }
        /**
@@ -318,9 +292,12 @@ public abstract class Process extends Thread {
         * @return                              The current process.
         *
         */ 
-       public static Process currentProcess()  {
-               return MsgNative.processSelf();
-       }
+       public static native Process currentProcess();
+       /**
+        * Kills a MSG process
+        * @param process Valid java process to kill
+        */
+       final static native void kill(Process process); 
        /**
         * Migrates a process to another host.
         *
@@ -339,10 +316,7 @@ public abstract class Process extends Thread {
         *
         * @exception                   HostFailureException on error in the native SimGrid code
         */ 
-       public static void waitFor(double seconds) throws HostFailureException {
-               MsgNative.processWaitFor(seconds);
-       } 
-    /**
+       public native void waitFor(double seconds) throws HostFailureException;    /**
      *
      */
     public void showArgs() {
@@ -353,20 +327,16 @@ public abstract class Process extends Thread {
                                        "] args[" + i + "]=" + (String) (this.args.get(i)));
        }
     /**
-     * Let the simulated process sleep for the given amount of millisecond in the simulated world.
-     * 
-     *  You don't want to use sleep instead, because it would freeze your simulation 
-     *  run without any impact on the simulated world.
-     * @param millis
+     * Exit the process
      */
-    public native void simulatedSleep(double seconds);
+    public native void exit();
 
        /**
         * This method runs the process. Il calls the method function that you must overwrite.
         */
        public void run() {
 
-               String[]args = null;      /* do not fill it before the signal or this.args will be empty */
+               String[] args = null;      /* do not fill it before the signal or this.args will be empty */
 
                //waitSignal(); /* wait for other people to fill the process in */
 
@@ -383,7 +353,7 @@ public abstract class Process extends Thread {
                        }
 
                        this.main(args);
-                       MsgNative.processExit(this);
+                       exit();
                        schedEnd.release();
                } catch(MsgException e) {
                        e.printStackTrace();
@@ -393,7 +363,7 @@ public abstract class Process extends Thread {
                 catch(ProcessKilled pk) {
                        if (nativeStop) {
                                try {
-                                       MsgNative.processExit(this);
+                                       exit();
                                } catch (ProcessKilled pk2) {
                                        /* Ignore that other exception that *will* occur all the time. 
                                         * This is because the C mechanic gives the control to the now-killed process 
@@ -405,13 +375,13 @@ public abstract class Process extends Thread {
                                         */
                                        System.err.println(currentThread().getName()+": I ignore that other exception");                                        
                                }
-                       Msg.info(" Process " + ((Process) Thread.currentThread()).msgName() + " has been killed.");                                             
-                       schedEnd.release();                     
+                               Msg.info(" Process " + ((Process) Thread.currentThread()).msgName() + " has been killed.");                                             
+                               schedEnd.release();                     
                        }
                        else {
-                       pk.printStackTrace();
-                       Msg.info("Unexpected behavior. Stopping now");
-                       System.exit(1);
+                               pk.printStackTrace();
+                               Msg.info("Unexpected behavior. Stopping now");
+                               System.exit(1);
                        }
                }       
        }
@@ -508,73 +478,12 @@ public abstract class Process extends Thread {
                        throw new RuntimeException("The impossible did happend once again: I got interrupted in schedEnd.acquire()",e);
                }
        }
-
-       /** Send the given task in the mailbox associated with the specified alias  (waiting at most given time) 
-     * @param mailbox
-     * @param task 
-     * @param timeout
-     * @throws TimeoutException
-        * @throws HostFailureException 
-        * @throws TransferFailureException */
-       public void taskSend(String mailbox, Task task, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
-               task.send(mailbox, timeout);
-       }
-
-       /** Send the given task in the mailbox associated with the specified alias
-     * @param mailbox
-     * @param task
-     * @throws TimeoutException
-        * @throws HostFailureException 
-        * @throws TransferFailureException */
-       public void taskSend(String mailbox, Task task) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
-               task.send(mailbox, -1);
-       }
-
-    /** Receive a task on mailbox associated with the specified mailbox
-     * @param mailbox
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
-     */
-       public Task taskReceive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
-               return Task.receive(mailbox, -1.0, null);
-       }
-
-    /** Receive a task on mailbox associated with the specified alias (waiting at most given time)
-     * @param mailbox
-     * @param timeout
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
-     */
-       public Task taskReceive(String mailbox, double timeout) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return Task.receive(mailbox, timeout, null);
-       }
-
-    /** Receive a task on mailbox associated with the specified alias from given sender
-     * @param mailbox
-     * @param host
-     * @param timeout
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
-     */
-       public Task taskReceive(String mailbox, double timeout, Host host) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return Task.receive(mailbox, timeout, host);
-       }
-
-    /** Receive a task on mailbox associated with the specified alias from given sender
-     * @param mailbox
-     * @param host
-     * @return
-     * @throws TransferFailureException
-     * @throws HostFailureException
-     * @throws TimeoutException
-     */
-       public Task taskReceive(String mailbox, Host host) throws  TransferFailureException, HostFailureException, TimeoutException {
-               return Task.receive(mailbox, -1.0, host);
+    
+       /**
+        * Class initializer, to initialize various JNI stuff
+        */
+       public static native void nativeInit();
+       static {
+               nativeInit();
        }
 }
index 5878ad9..41f064a 100644 (file)
@@ -103,11 +103,12 @@ public class Task {
      * @return
      */
        public native String getName();
-       /** Gets the sender of the task */
-       //FIXME: Don't crash when the task has just been created.
+       /** Gets the sender of the task 
+        * Returns null if the task hasn't been sent yet
+        */
        public native Process getSender();
-       /** Gets the source of the task
-        * FIXME: Not defensive enough, can crash.
+       /** Gets the source of the task.
+        * Returns null if the task hasn't been sent yet.
      */
        public native Host getSource();   
        /** Gets the computing amount of the task
index 95b89eb..5b00966 100644 (file)
@@ -49,317 +49,6 @@ JNIEnv *get_current_thread_env(void)
 
   return env;
 }
-
-/*
- * The MSG process connected functions implementation.                                 
- */
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
-                                         jobject jprocess_arg,
-                                         jobject jhostname)
-{
-     
-   
-  jobject jprocess;             /* the global reference to the java process instance    */
-  jstring jname;                /* the name of the java process instance                */
-  const char *name;             /* the C name of the process                            */
-  const char *hostname;
-  m_process_t process;          /* the native process to create                         */
-  m_host_t host;                /* Where that process lives */
-   
-  hostname = (*env)->GetStringUTFChars(env, jhostname, 0);
-
-  XBT_DEBUG("Java_org_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,host=%s)",
-        env, cls, jprocess_arg, hostname);
-   
-   
-  /* get the name of the java process */
-  jname = jprocess_get_name(jprocess_arg, env);
-  if (!jname) {
-    jxbt_throw_null(env,
-            xbt_strdup("Internal error: Process name cannot be NULL"));
-    return;
-  }
-
-  /* bind/retrieve the msg host */
-  host = MSG_get_host_by_name(hostname);
-
-  if (!(host)) {    /* not binded */
-    jxbt_throw_host_not_found(env, hostname);
-    return;
-  }
-
-  /* create a global java process instance */
-  jprocess = jprocess_new_global_ref(jprocess_arg, env);
-  if (!jprocess) {
-    jxbt_throw_jni(env, "Can't get a global ref to the java process");
-    return;
-  }
-
-  /* build the C name of the process */
-  name = (*env)->GetStringUTFChars(env, jname, 0);
-  name = xbt_strdup(name);
-  
-  /* Actually build the MSG process */
-  process = MSG_process_create_with_environment(name,
-                                               (xbt_main_func_t) jprocess,
-                                               /*data*/ NULL,
-                                               host,
-                                               /* kill_time */-1,
-                                               /*argc, argv, properties*/
-                                               0,NULL,NULL);
-     
-  MSG_process_set_data(process,&process);
-   
-  /* release our reference to the process name (variable name becomes invalid) */
-  //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING
-  //(*env)->ReleaseStringUTFChars(env, jname, name);
-  (*env)->ReleaseStringUTFChars(env, jhostname, hostname);
-   
-  /* bind the java process instance to the native process */
-  jprocess_bind(jprocess, process, env);
-
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
-                                          jobject jprocess)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return;
-  }
-
-  /* try to suspend the process */
-  MSG_error_t rv = MSG_process_suspend(process);
-
-  jxbt_check_res("MSG_process_suspend()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
-
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jobject jprocess,
-                                           jdouble jseconds) {
-         m_process_t process = jprocess_to_native_process(jprocess, env);
-
-         if (!process) {
-           jxbt_throw_notbound(env, "process", jprocess);
-           return;
-         }
-         MSG_error_t rv = MSG_process_sleep((double)jseconds);
-
-         jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
-                        bprintf("unexpected error , please report this bug"));
-}
-
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
-                                         jobject jprocess)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return;
-  }
-
-  /* try to resume the process */
-  MSG_error_t rv = MSG_process_resume(process);
-
-  jxbt_check_res("MSG_process_resume()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
-}
-
-JNIEXPORT jboolean JNICALL
-Java_org_simgrid_msg_MsgNative_processIsSuspended(JNIEnv * env, jclass cls,
-                                              jobject jprocess)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return 0;
-  }
-
-  /* true is the process is suspended, false otherwise */
-  return (jboolean) MSG_process_is_suspended(process);
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processKill(JNIEnv * env, jclass cls,
-                                       jobject jprocess)
-{
-  /* get the native instances from the java ones */
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return;
-  }
-
-  /* kill the native process (this wrapper is call by the destructor of the java 
-   * process instance)
-   */
-  MSG_process_kill(process);
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls,
-                                          jobject jprocess)
-{
-  /* get the native instances from the java ones */
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-  m_host_t host;
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return NULL;
-  }
-
-  host = MSG_process_get_host(process);
-  jobject res = (jobject)MSG_host_get_data(host);
-
-  if (!res) {
-         XBT_INFO("Binding error for host %s ",MSG_host_get_name(host));
-         jxbt_throw_jni(env, bprintf("Binding error for host %s ",MSG_host_get_name(host)));
-         return NULL;
-  }
-
-  /* return the global reference to the java host instance */
-  return res;
-
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls,
-                                          jint PID)
-{
-  m_process_t process = MSG_process_from_PID(PID);
-
-  if (!process) {
-    jxbt_throw_process_not_found(env, bprintf("PID = %d",(int) PID));
-    return NULL;
-  }
-
-  if (!native_to_java_process(process)) {
-    jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
-    return NULL;
-  }
-
-  return (jobject) (native_to_java_process(process));
-}
-
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_processGetPID(JNIEnv * env, jclass cls,
-                                         jobject jprocess)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return 0;
-  }
-
-  return (jint) MSG_process_get_PID(process);
-}
-
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_processGetPPID(JNIEnv * env, jclass cls,
-                                          jobject jprocess)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return 0;
-  }
-
-  return (jint) MSG_process_get_PPID(process);
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_processSelf(JNIEnv * env, jclass cls)
-{
-  m_process_t process = MSG_process_self();
-  jobject jprocess;
-
-  if (!process) {
-    jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed"));
-    return NULL;
-  }
-
-  jprocess = native_to_java_process(process);
-
-  if (!jprocess)
-    jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
-
-  return jprocess;
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processMigrate(JNIEnv * env, jclass cls,
-                                             jobject jprocess, jobject jhost)
-{
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return;
-  }
-
-  m_host_t host = jhost_get_native(env, jhost);
-
-  if (!host) {
-    jxbt_throw_notbound(env, "host", jhost);
-    return;
-  }
-
-  /* try to change the host of the process */
-  MSG_error_t rv = MSG_process_migrate(process, host);
-  jxbt_check_res("MSG_process_migrate()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
-
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls,
-                                          jdouble seconds)
-{
-  MSG_error_t rv = MSG_process_sleep((double) seconds);
-
-  jxbt_check_res("MSG_process_sleep()", rv, MSG_HOST_FAILURE,
-                 bprintf("while process was waiting for %f seconds",
-                         (double) seconds));
-
-}
-
-
-/***************************************************************************************
- * The MSG host connected functions implementation.                                    *
- ***************************************************************************************/
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
-                                       jobject jhost)
-{
-  m_host_t host = jhost_get_native(env, jhost);
-
-  if (!host) {
-    jxbt_throw_notbound(env, "host", jhost);
-    return -1;
-  }
-
-  return (jint) MSG_get_host_msgload(host);
-}
-
-
 /***************************************************************************************
  * Unsortable functions                                                        *
  ***************************************************************************************/
@@ -445,13 +134,6 @@ JNIEXPORT void JNICALL
                  bprintf
                  ("unexpected error : MSG_clean() failed .. please report this bug "));
 }
-   
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_processKillAll(JNIEnv * env, jclass cls,
-                                          jint jresetPID)
-{
-  return (jint) MSG_process_killall((int) jresetPID);
-}
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
@@ -466,21 +148,6 @@ Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
   (*env)->ReleaseStringUTFChars(env, jplatformFile, platformFile);
 }
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processExit(JNIEnv * env, jclass cls,
-                                       jobject jprocess)
-{
-
-  m_process_t process = jprocess_to_native_process(jprocess, env);
-
-  if (!process) {
-    jxbt_throw_notbound(env, "process", jprocess);
-    return;
-  }
-
-  smx_ctx_java_stop(MSG_process_get_smx_ctx(process));
-}
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
 {
@@ -489,49 +156,6 @@ Java_org_simgrid_msg_Msg_info(JNIEnv * env, jclass cls, jstring js)
   (*env)->ReleaseStringUTFChars(env, js, s);
 }
 
-JNIEXPORT jobjectArray JNICALL
-Java_org_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg)
-{
-  int index;
-  jobjectArray jtable;
-  jobject jhost;
-  jstring jname;
-  m_host_t host;
-
-  xbt_dynar_t table =  MSG_hosts_as_dynar();
-  int count = xbt_dynar_length(table);
-
-  jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
-
-  if (!cls) {
-    return NULL;
-  }
-
-  jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
-
-  if (!jtable) {
-    jxbt_throw_jni(env, "Hosts table allocation failed");
-    return NULL;
-  }
-
-  for (index = 0; index < count; index++) {
-    host = xbt_dynar_get_as(table,index,m_host_t);
-    jhost = (jobject) (MSG_host_get_data(host));
-
-    if (!jhost) {
-      jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));
-
-      jhost =
-               Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
-      /* FIXME: leak of jname ? */
-    }
-
-    (*env)->SetObjectArrayElement(env, jtable, index, jhost);
-  }
-  xbt_dynar_free(&table);
-  return jtable;
-}
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
                                        jstring jdeploymentFile)
index 25aaf82..c943fe6 100644 (file)
@@ -16,168 +16,30 @@ JavaVM *get_java_VM(void);
 JNIEnv *get_current_thread_env(void);
 
 /*
- * Class               simgrid_msg_Msg
- * Method              processCreate
- * Signature   (Lsimgrid/msg/Process;Lsimgrid/msg/Host;)V
- */
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
-                                         jobject jprocess, jobject jhost);
-
-
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processSuspend
- * Signature   (Lsimgrid/msg/Process;)V
- */
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jobject obj,
-                                          jobject jprocess);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processResume
- * Signature   (Lsimgrid/msg/Process;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processResume
-    (JNIEnv *, jclass, jobject);
-
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jclass cls,
-                                           jdouble jmillis);
-
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processIsSuspended
- * Signature   (Lsimgrid/msg/Process;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_MsgNative_processIsSuspended
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processKill
- * Signature   (Lsimgrid/msg/Process;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processKill
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processGetHost
- * Signature   (Lsimgrid/msg/Process;)Lsimgrid/msg/Host;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_processGetHost
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processFromPID
- * Signature   (I)Lsimgrid/msg/Process;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_processFromPID
-    (JNIEnv *, jclass, jint);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processGetPID
- * Signature   (Lsimgrid/msg/Process;)I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_processGetPID
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processGetPPID
- * Signature   (Lsimgrid/msg/Process;)I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_processGetPPID
-    (JNIEnv *, jclass, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processSelf
- * Signature   ()Lsimgrid/msg/Process;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_processSelf
-    (JNIEnv *, jclass);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processSelfPID
- * Signature   ()I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_processSelfPID
-    (JNIEnv *, jclass);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processSelfPPID
- * Signature   ()I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_processSelfPPID
-    (JNIEnv *, jclass);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processMigrate
- * Signature   (Lsimgrid/msg/Process;Lsimgrid/msg/Host;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processMigrate
-    (JNIEnv *, jclass, jobject, jobject);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processWaitFor
- * Signature   (D)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processWaitFor
-    (JNIEnv *, jclass, jdouble);
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
-                                       jobject jhost);
-
-/*
- * Class               simgrid_msg_Msg
+ * Class               org_simgrid_msg_Msg
  * Method              getClock
  * Signature   ()D
  */
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv *, jclass);
-
+/**
+ * Class               org_simgrid_msg_Msg
+ * Method              run
+ */
 JNIEXPORT void JNICALL
     JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls);
+/**
+ * Class               org_simgrid_msg_Msg
+ * Method              clean
+ */
 JNIEXPORT void JNICALL
     JNICALL Java_org_simgrid_msg_Msg_clean(JNIEnv * env, jclass cls);
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs);
 
-/*
- * Class               simgrid_msg_Msg
- * Method              processKillAll
- * Signature   (I)I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_processKillAll
-    (JNIEnv *, jclass, jint);
-
-/*
- * Class               simgrid_msg_Msg
- * Method              processExit
- * Signature   (Lsimgrid/msg/Process;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processExit
-    (JNIEnv *, jclass, jobject);
-
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_info(JNIEnv *, jclass,
                                                  jstring);
 
-JNIEXPORT jobjectArray JNICALL
-Java_org_simgrid_msg_MsgNative_allHosts(JNIEnv *, jclass);
-
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
                                        jstring jplatformFile);
index b124580..9707deb 100644 (file)
@@ -218,3 +218,46 @@ Java_org_simgrid_msg_Host_isAvail(JNIEnv * env, jobject jhost) {
 
   return (jboolean) MSG_host_is_avail(host);
 }
+
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg)
+{
+  int index;
+  jobjectArray jtable;
+  jobject jhost;
+  jstring jname;
+  m_host_t host;
+
+  xbt_dynar_t table =  MSG_hosts_as_dynar();
+  int count = xbt_dynar_length(table);
+
+  jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
+
+  if (!cls) {
+    return NULL;
+  }
+
+  jtable = (*env)->NewObjectArray(env, (jsize) count, cls, NULL);
+
+  if (!jtable) {
+    jxbt_throw_jni(env, "Hosts table allocation failed");
+    return NULL;
+  }
+
+  for (index = 0; index < count; index++) {
+    host = xbt_dynar_get_as(table,index,m_host_t);
+    jhost = (jobject) (MSG_host_get_data(host));
+
+    if (!jhost) {
+      jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));
+
+      jhost =
+               Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
+      /* FIXME: leak of jname ? */
+    }
+
+    (*env)->SetObjectArrayElement(env, jtable, index, jhost);
+  }
+  xbt_dynar_free(&table);
+  return jtable;
+}
index d4ddd1d..aa0b5b0 100644 (file)
@@ -98,7 +98,7 @@ const char *jhost_get_name(jobject jhost, JNIEnv * env);
 jboolean jhost_is_valid(jobject jhost, JNIEnv * env);
 
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              getByName
  * Signature   (Ljava/lang/String;)Lsimgrid/msg/Host;
  */
@@ -106,7 +106,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName
     (JNIEnv *, jclass, jstring);
 
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              currentHost
  * Signature   ()Lsimgrid/msg/Host;
  */
@@ -114,14 +114,14 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost
     (JNIEnv *, jclass);
 
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              getName
  * Signature   ()Ljava/lang/String;
  */
 JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Host_getName
     (JNIEnv *, jobject);
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              getCount
  * Signature   ()I
  */
@@ -129,14 +129,14 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount
     (JNIEnv *, jclass);
 
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              getSpeed
  * Signature   ()D
  */
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed
     (JNIEnv *, jobject);
 /*
- * Class               simgrid_msg_Host
+ * Class               org_simgrid_msg_Host
  * Method              getLoad
  * Signature   ()I
  */
@@ -145,11 +145,18 @@ Java_org_simgrid_msg_Host_getLoad(JNIEnv * env,
                                        jobject jhost);
 
 /*
- * Class               simgrid_msg_Msg
+ * Class               org_simgrid_msg_Host
  * Method              isAvail
  * Signature   ()Z
  */
 JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isAvail
     (JNIEnv *, jobject);
 
+/**
+ * Class org_simgrid_msg_Host
+ * Method all
+ */
+JNIEXPORT jobjectArray JNICALL
+Java_org_simgrid_msg_Host_all(JNIEnv *, jclass);
+
 #endif                          /*!MSG_JHOST_H */
index f0c7489..f0fa160 100644 (file)
@@ -5,15 +5,20 @@
 
 /* This program is free software; you can redistribute it and/or modify it
   * under the terms of the license (GNU LGPL) which comes with this package. */
-
 #include "jmsg_process.h"
+
 #include "jmsg.h"
+#include "jmsg_host.h"
 #include "jxbt_utilities.h"
 
 #include "smx_context_java.h"  
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
+static jfieldID jprocess_field_Process_pid;
+static jfieldID jprocess_field_Process_ppid;
+static jfieldID jprocess_field_Process_host;
+
 jobject native_to_java_process(m_process_t process)
 {
   return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
@@ -220,3 +225,256 @@ void jprocess_unschedule(smx_context_t context)
 
   (*env)->CallVoidMethod(env, ((smx_ctx_java_t) context)->jprocess, id);
 }
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) {
+       jclass jprocess_class_Process = (*env)->FindClass(env, "org/simgrid/msg/Process");
+
+       jprocess_field_Process_pid = jxbt_get_sfield(env, "org/simgrid/msg/Process", "pid", "I");
+       jprocess_field_Process_ppid = jxbt_get_sfield(env, "org/simgrid/msg/Process", "ppid", "I");
+       jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;");
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_create(JNIEnv * env,
+                                    jobject jprocess_arg,
+                                    jobject jhostname)
+{
+
+
+  jobject jprocess;             /* the global reference to the java process instance    */
+  jstring jname;                /* the name of the java process instance                */
+  const char *name;             /* the C name of the process                            */
+  const char *hostname;
+  m_process_t process;          /* the native process to create                         */
+  m_host_t host;                /* Where that process lives */
+
+  hostname = (*env)->GetStringUTFChars(env, jhostname, 0);
+
+  XBT_DEBUG("Java_org_simgrid_msg_MsgNative_processCreate(env=%p,jproc=%p,host=%s)",
+        env, jprocess_arg, hostname);
+
+
+  /* get the name of the java process */
+  jname = jprocess_get_name(jprocess_arg, env);
+  if (!jname) {
+    jxbt_throw_null(env,
+            xbt_strdup("Internal error: Process name cannot be NULL"));
+    return;
+  }
+
+  /* bind/retrieve the msg host */
+  host = MSG_get_host_by_name(hostname);
+
+  if (!(host)) {    /* not binded */
+    jxbt_throw_host_not_found(env, hostname);
+    return;
+  }
+
+  /* create a global java process instance */
+  jprocess = jprocess_new_global_ref(jprocess_arg, env);
+  if (!jprocess) {
+    jxbt_throw_jni(env, "Can't get a global ref to the java process");
+    return;
+  }
+
+  /* build the C name of the process */
+  name = (*env)->GetStringUTFChars(env, jname, 0);
+  name = xbt_strdup(name);
+
+  /* Actually build the MSG process */
+  process = MSG_process_create_with_environment(name,
+                                               (xbt_main_func_t) jprocess,
+                                               /*data*/ NULL,
+                                               host,
+                                               /* kill_time */-1,
+                                               /*argc, argv, properties*/
+                                               0,NULL,NULL);
+
+  MSG_process_set_data(process,&process);
+
+  /* release our reference to the process name (variable name becomes invalid) */
+  //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING
+  //(*env)->ReleaseStringUTFChars(env, jname, name);
+  (*env)->ReleaseStringUTFChars(env, jhostname, hostname);
+
+  /* bind the java process instance to the native process */
+  jprocess_bind(jprocess, process, env);
+
+  /* sets the PID and the PPID of the process */
+  (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
+  (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
+  /* sets the Host of the process */
+  jobject jhost = Java_org_simgrid_msg_Host_getByName(env,NULL,jhostname);
+
+  (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
+}
+
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Process_killAll(JNIEnv * env, jclass cls,
+                                     jint jresetPID)
+{
+  return (jint) MSG_process_killall((int) jresetPID);
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls,
+                                     jint PID)
+{
+  m_process_t process = MSG_process_from_PID(PID);
+
+  if (!process) {
+    jxbt_throw_process_not_found(env, bprintf("PID = %d",(int) PID));
+    return NULL;
+  }
+
+  jobject jprocess = native_to_java_process(process);
+
+  if (!jprocess) {
+    jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
+    return NULL;
+  }
+
+  return jprocess;
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Process_currentProcess(JNIEnv * env, jclass cls)
+{
+  m_process_t process = MSG_process_self();
+  jobject jprocess;
+
+  if (!process) {
+    jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed"));
+    return NULL;
+  }
+
+  jprocess = native_to_java_process(process);
+
+  if (!jprocess)
+    jxbt_throw_jni(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
+
+  return jprocess;
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_pause(JNIEnv * env,
+                                   jobject jprocess)
+{
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  /* try to suspend the process */
+  MSG_error_t rv = MSG_process_suspend(process);
+
+  jxbt_check_res("MSG_process_suspend()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_restart(JNIEnv * env,
+                                     jobject jprocess)
+{
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  /* try to resume the process */
+  MSG_error_t rv = MSG_process_resume(process);
+
+  jxbt_check_res("MSG_process_resume()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+}
+JNIEXPORT jboolean JNICALL
+Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env,
+                                         jobject jprocess)
+{
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return 0;
+  }
+
+  /* true is the process is suspended, false otherwise */
+  return (jboolean) MSG_process_is_suspended(process);
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
+                                     jdouble jseconds)
+{
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+  MSG_error_t rv = MSG_process_sleep((double)jseconds);
+
+  jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_exit(JNIEnv * env,
+                                  jobject jprocess)
+{
+
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  smx_ctx_java_stop(MSG_process_get_smx_ctx(process));
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_kill(JNIEnv * env, jclass cls,
+                                  jobject jprocess)
+{
+  /* get the native instances from the java ones */
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  /* kill the native process (this wrapper is call by the destructor of the java
+   * process instance)
+   */
+  MSG_process_kill(process);
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_migrate(JNIEnv * env,
+                                     jobject jprocess, jobject jhost)
+{
+  m_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  m_host_t host = jhost_get_native(env, jhost);
+
+  if (!host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return;
+  }
+
+  /* try to change the host of the process */
+  MSG_error_t rv = MSG_process_migrate(process, host);
+  jxbt_check_res("MSG_process_migrate()", rv, MSG_OK,
+                 bprintf("unexpected error , please report this bug"));
+  /* change the host java side */
+  (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
+}
index 8288346..d4850a4 100644 (file)
@@ -239,6 +239,97 @@ void jprocess_wait_cond(jobject jprocess, JNIEnv * env);
 void jprocess_schedule(smx_context_t context);
 
 void jprocess_unschedule(smx_context_t context);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              nativeInit
+ * Signature   ();
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls);
+
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              create
+ * Signature   (Lsimgrid/msg/Host;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_create(JNIEnv * env,
+                                         jobject jprocess, jobject jhost);
+
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              killAll
+ * Signature   (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll
+    (JNIEnv *, jclass, jint);
+
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              fromPID
+ * Signature   (I)Lsimgrid/msg/Process;
+ */
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID
+    (JNIEnv *, jclass, jint);
+
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              currentProcess
+ * Signature   ()Lsimgrid/msg/Process;
+ */
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_currentProcess
+    (JNIEnv *, jclass);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              pause
+ * Signature   (Lsimgrid/msg/Process;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_pause(JNIEnv * env,
+                                          jobject jprocess);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              restart
+ * Signature   (Lsimgrid/msg/Process;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart
+    (JNIEnv *, jobject);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              isSuspended
+ * Signature   (Lsimgrid/msg/Process;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended
+    (JNIEnv *, jobject);
 
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              waitFor
+ * Signature   (D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor
+    (JNIEnv *, jobject, jdouble);
+/**
+ * Class               org_simgrid_msg_Process
+ * Method              exit
+ * Signature   ()V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_exit
+    (JNIEnv *, jobject);
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              kill
+ * Signature   (Lsimgrid/msg/Process;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill
+    (JNIEnv *, jclass, jobject);
+
+/*
+ * Class               org_simgrid_msg_Process
+ * Method              migrate
+ * Signature   (Lsimgrid/msg/Host;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate
+    (JNIEnv *, jobject, jobject);
 
 #endif                          /* !MSG_JPROCESS_H */
index cf6962f..f91185b 100644 (file)
@@ -248,7 +248,6 @@ Java_org_simgrid_msg_Task_getSender(JNIEnv * env,
 
   process = MSG_task_get_sender(task);
   if (process == NULL) {
-       jxbt_throw_illegal(env,bprintf("Tried to get the sender of a task that hasn't been sent yet."));
        return NULL;
   }
   return (jobject) native_to_java_process(process);
@@ -268,7 +267,6 @@ Java_org_simgrid_msg_Task_getSource(JNIEnv * env,
 
   host = MSG_task_get_source(task);
   if (host == NULL) {
-       jxbt_throw_illegal(env,bprintf("Tried to get the source of a task that hasn't been sent yet."));
        return NULL;
   }
   if (!MSG_host_get_data(host)) {