]> AND Public Git Repository - simgrid.git/blobdiff - src/java/simgrid/msg/Process.java
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not pass a NULL argument to processes
[simgrid.git] / src / java / simgrid / msg / Process.java
index c2861eeb5f06b4de54c7ebb06fca7c93e6069204..c690faec123c3a6ef4d44c741550599ca81e5540 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * simgrid.msg.Host.java       1.00 07/05/01
+ * $Id$
  *
  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
  * All right reserved. 
@@ -14,7 +14,7 @@ package simgrid.msg;
 import java.lang.Thread;
 import java.util.*;
 
-/*
+/**
  * A process may be defined as a code, with some private data, executing 
  * in a location (host). All the process used by your simulation must be
  * declared in the deployment file (XML format).
@@ -27,34 +27,25 @@ import java.util.*;
  * 
  * public class Slave extends simgrid.msg.Process {
  *
- *     (2) Write a default constructor and 
- *     call the default constructor of the base class.
- *     
- *     public Slave() {
- *             super();
- *  }
- *
- *  (3) Override the method function 
+ *  (2) Override the method function
+ * 
+ *  \verbatim
  *     public void main(String[] args) {
  *             System.out.println("Hello MSG");
  *     }
+ *  \endverbatim
  * }
  * The name of your process must be declared in the deployment file of your simulation.
  * For the exemple, for the previouse process Slave this file must contains a line :
  * <process host="Maxims" function="Slave"/>, where Maxims is the host of the process
  * Slave. All the process of your simulation are automaticaly launched and managed by Msg.
  * A process use tasks to simulate communications or computations with another process. 
- * For more information see Task and ParallelTask. For more information on host concept 
+ * For more information see Task. For more information on host concept 
  * see Host.
  * 
  * @author  Abdelmalek Cherier
  * @author  Martin Quinson
- * @version 1.00, 07/05/01
- * @see Host
- * @see Task
- * @see ParallelTask
  * @since SimGrid 3.3
- * @since JDK1.5011
  */
 
 public abstract class Process extends Thread {
@@ -77,6 +68,8 @@ public abstract class Process extends Thread {
      * The native functions use this identifier to synchronize the process.
      */
   public long id;
+  
+  public Hashtable properties;
 
     /**
      * The name of the process.                                                        
@@ -101,6 +94,7 @@ public abstract class Process extends Thread {
     this.name = null;
     this.bind = 0;
     this.args = new Vector();
+    this.properties = null;
     schedBegin = new Sem(0);
     schedEnd = new Sem(0);
   }
@@ -174,7 +168,8 @@ public abstract class Process extends Thread {
     if (name == null)
       throw new NullPointerException("Process name cannot be NULL");
 
-
+         this.properties = null;
+         
       this.args = new Vector();
 
     if (null != args)
@@ -186,8 +181,10 @@ public abstract class Process extends Thread {
       schedBegin = new Sem(0);
       schedEnd = new Sem(0);
 
-      Msg.processCreate(this, host);
+      MsgNative.processCreate(this, host);
   }
+  
     /**
      * This method kills all running process of the simulation.
      *
@@ -198,7 +195,7 @@ public abstract class Process extends Thread {
      * @return                         The function returns the PID of the next created process.
      *                 
      */ public static int killAll(int resetPID) {
-    return Msg.processKillAll(resetPID);
+    return MsgNative.processKillAll(resetPID);
   }
 
     /**
@@ -219,7 +216,7 @@ public abstract class Process extends Thread {
      *                              NativeException on error in the native SimGrid code
      */
   public void pause() throws JniException, NativeException {
-    Msg.processSuspend(this);
+    MsgNative.processSuspend(this);
   }
     /**
      * This method resumes a suspended process by resuming the task on which it was
@@ -229,7 +226,7 @@ public abstract class Process extends Thread {
      *                              NativeException on error in the native SimGrid code
      *
      */ public void restart() throws JniException, NativeException {
-    Msg.processResume(this);
+    MsgNative.processResume(this);
   }
     /**
      * This method tests if a process is suspended.
@@ -239,7 +236,7 @@ public abstract class Process extends Thread {
      *
      * @exception                      JniException on JNI madness
      */ public boolean isSuspended() throws JniException {
-    return Msg.processIsSuspended(this);
+    return MsgNative.processIsSuspended(this);
   }
     /**
      * This method returns the host of a process.
@@ -250,7 +247,7 @@ public abstract class Process extends Thread {
      *                              NativeException on error in the native SimGrid code
      *
      */ public Host getHost() throws JniException, NativeException {
-    return Msg.processGetHost(this);
+    return MsgNative.processGetHost(this);
   }
     /**
      * This static method get a process from a PID.
@@ -261,7 +258,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 Msg.processFromPID(PID);
+    return MsgNative.processFromPID(PID);
   }
     /**
      * This method returns the PID of the process.
@@ -271,7 +268,7 @@ public abstract class Process extends Thread {
      * @exception                      JniException on JNI madness
      *                              NativeException on error in the native SimGrid code
      */ public int getPID() throws JniException, NativeException {
-    return Msg.processGetPID(this);
+    return MsgNative.processGetPID(this);
   }
     /**
      * This method returns the PID of the parent of a process.
@@ -280,7 +277,7 @@ public abstract class Process extends Thread {
      *
      * @exception                      NativeException on error in the native SimGrid code
      */ public int getPPID() throws NativeException {
-    return Msg.processGetPPID(this);
+    return MsgNative.processGetPPID(this);
   }
     /**
      * This static method returns the currently running process.
@@ -291,14 +288,14 @@ public abstract class Process extends Thread {
      *
      *
      */ public static Process currentProcess() throws NativeException {
-    return Msg.processSelf();
+    return MsgNative.processSelf();
   }
     /**
      * This static method returns the PID of the currently running process.
      *
      * @return                         The PID of the current process.         
      */ public static int currentProcessPID() {
-    return Msg.processSelfPID();
+    return MsgNative.processSelfPID();
   }
 
     /**
@@ -307,7 +304,7 @@ public abstract class Process extends Thread {
      * @return                         The PID of the parent of current process.               
      */
   public static int currentProcessPPID() {
-    return Msg.processSelfPPID();
+    return MsgNative.processSelfPPID();
   }
 
     /**
@@ -319,7 +316,7 @@ public abstract class Process extends Thread {
      *                              NativeException on error in the native SimGrid code
      */
   public void migrate(Host host) throws JniException, NativeException {
-    Msg.processChangeHost(this, host);
+    MsgNative.processChangeHost(this, host);
   }
     /**
      * This method makes the current process sleep until time seconds have elapsed.
@@ -328,7 +325,7 @@ public abstract class Process extends Thread {
      *
      * @exception                      NativeException on error in the native SimGrid code
      */ public static void waitFor(double seconds) throws NativeException {
-    Msg.processWaitFor(seconds);
+    MsgNative.processWaitFor(seconds);
   } public void showArgs() {
     try {
       Msg.info("[" + this.name + "/" + this.getHost().getName() + "] argc=" +
@@ -347,27 +344,26 @@ public abstract class Process extends Thread {
      */
   public synchronized void run() {
 
-    try {
       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 */
 
 
-      try {
+     try {
         schedBegin.acquire();
-      } catch(InterruptedException e) {
-      }
+     } catch(InterruptedException e) {
+     }
 
 
 
+    try {
+      args = new String[this.args.size()];
       if (this.args.size() > 0) {
-
-        args = new String[this.args.size()];
         this.args.toArray(args);
       }
 
       this.main(args);
-      Msg.processExit(this);
+      MsgNative.processExit(this);
       schedEnd.release();
     }
     catch(MsgException e) {
@@ -378,44 +374,139 @@ public abstract class Process extends Thread {
   }
 
     /**
-     * Process synchronization. The process wait the signal of the simulator to start.
-     *
-     * @exception                      JniException on JNI madness
+     * The main function of the process (to implement).
      */
-  private void waitSignal() throws JniException {
-    Msg.waitSignal(this);
-    unschedule();
-  }
-    /**
-        * The main function of the process (to implement).
-        */ public abstract void main(String[]args)
+  public abstract void main(String[]args)
   throws JniException, NativeException;
 
 
   public void unschedule() {
-
     try {
       schedEnd.release();
       schedBegin.acquire();
     } catch(InterruptedException e) {
-
     }
   }
 
   public void schedule() {
-
     try {
       schedBegin.release();
       schedEnd.acquire();
     } catch(InterruptedException e) {
-
     }
   }
-
-  public void taskSend(Channel channel, Task task,
-                       Host host) throws NativeException, JniException {
-    Msg.channelPut(channel, task, host);
-  } public Task taskReceive(Channel channel) throws NativeException,
+  
+  /** Send the given task to given host on given channel */
+  public void taskPut(Host host, int channel,
+                       Task task) throws NativeException, JniException {
+    MsgNative.hostPut(host, channel, task, -1);
+  }
+  
+   /** Send the given task to given host on given channel (waiting at most given time)*/
+   public void taskPut(Host host, int channel,
+                       Task task, double timeout) throws NativeException, JniException {
+    MsgNative.hostPut(host, channel, task, timeout);
+  }
+   /** Receive a task on given channel */
+    public Task taskGet(int channel) throws NativeException,
+    JniException {
+    return MsgNative.taskGet(channel, -1, null);
+  }
+   /** Receive a task on given channel (waiting at most given time) */
+    public Task taskGet(int channel,
+                            double timeout) throws NativeException,
+    JniException {
+    return MsgNative.taskGet(channel, timeout, null);
+  }
+   /** Receive a task on given channel from given sender */
+    public Task taskGet(int channel, Host host) throws NativeException,
     JniException {
-    return Msg.channelGet(channel);
-}}
+    return MsgNative.taskGet(channel, -1, host);
+  }
+   /** Receive a task on given channel from given sender (waiting at most given time) */
+    public Task taskGet(int channel, double timeout,
+                            Host host) throws NativeException, JniException {
+    return MsgNative.taskGet(channel, timeout, host);
+  }
+  
+  /** Send the given task in the mailbox associated with the specified alias  (waiting at most given time) */
+  public void taskSend(String alias,
+                       Task task, double timeout) throws NativeException, JniException {
+    MsgNative.taskSend(alias, task, timeout);
+  }
+  
+  /** Send the given task in the mailbox associated with the specified alias*/
+  public void taskSend(String alias,
+                       Task task) throws NativeException, JniException {
+    MsgNative.taskSend(alias, task, -1);
+  }
+  
+  /** Send the given task in the mailbox associated with the default alias  (defaultAlias = "hostName:processName") */
+  public void taskSend(Task task) throws NativeException, JniException {
+       
+       String alias = Host.currentHost().getName() + ":" + this.msgName();
+    MsgNative.taskSend(alias, task, -1);
+  }
+  
+  /** Send the given task in the mailbox associated with the default alias (waiting at most given time) */
+  public void taskSend(Task task, double timeout) throws NativeException, JniException {
+       
+       String alias = Host.currentHost().getName() + ":" + this.msgName();
+    MsgNative.taskSend(alias, task, timeout);
+  }
+  
+  
+   /** Receive a task on mailbox associated with the specified alias */
+    public Task taskReceive(String alias) throws NativeException,
+    JniException {
+    return MsgNative.taskReceive(alias, -1.0, null);
+  }
+  
+  /** Receive a task on mailbox associated with the default alias */
+   public Task taskReceive() throws NativeException,
+    JniException {
+    String alias = Host.currentHost().getName() + ":" + this.msgName();
+    return MsgNative.taskReceive(alias, -1.0, null);
+  }
+  
+  /** Receive a task on mailbox associated with the specified alias (waiting at most given time) */
+    public Task taskReceive(String alias,
+                            double timeout) throws NativeException,
+    JniException {
+    return MsgNative.taskReceive(alias, timeout, null);
+  }
+  
+  /** Receive a task on mailbox associated with the default alias (waiting at most given time) */
+   public Task taskReceive(double timeout) throws NativeException,
+    JniException {
+    String alias = Host.currentHost().getName() + ":" + this.msgName();
+    return MsgNative.taskReceive(alias, timeout, null);
+  }
+  
+   /** Receive a task on mailbox associated with the specified alias from given sender */
+    public Task taskReceive(String alias,
+                            double timeout, Host host) throws NativeException,
+    JniException {
+    return MsgNative.taskReceive(alias, timeout, host);
+  }
+  
+  /** Receive a task on mailbox associated with the default alias from given sender  (waiting at most given time) */
+  public Task taskReceive(double timeout, Host host) throws NativeException,
+    JniException {
+    String alias = Host.currentHost().getName() + ":" + this.msgName();
+    return MsgNative.taskReceive(alias, timeout, host);
+  }
+  
+   /** Receive a task on mailbox associated with the specified alias from given sender*/
+     public Task taskReceive(String alias,
+                            Host host) throws NativeException,
+    JniException {
+    return MsgNative.taskReceive(alias, -1.0, host);
+  }
+   /** Receive a task on mailbox associated with the default alias from given sender */
+   public Task taskReceive( Host host) throws NativeException,
+    JniException {
+       String alias = Host.currentHost().getName() + ":" + this.msgName();
+    return MsgNative.taskReceive(alias, -1.0, host);
+  }
+}