Process
Date: 2013-11-17

org.simgrid.msg

## Class Process

- java.lang.Object
- - org.simgrid.msg.Process

- All Implemented Interfaces:
    java.lang.Runnable

      public abstract class Process
      extends java.lang.Object
      implements java.lang.Runnable

  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). To create your own process you must inherit your own process from this class and override the method "main()". For example if you want to use a process named Slave proceed as it : (1) import the class Process of the package simgrid.msg import simgrid.msg.Process; public class Slave extends simgrid.msg.Process { (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 example, for the previous 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 automatically launched and managed by Msg. A process use tasks to simulate communications or computations with another process. For more information see Task. For more information on host concept see Host.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `java.util.Vector<java.lang.String>` | `args` The arguments of the method function of the process.
    `protected Host` | `host` The host of the process
    `long` | `id` Even if this attribute is public you must never access to it.
    `double` | `killTime` Kill time of the process
    `protected java.lang.String` | `name` The name of the process.
    `static long` | `nextProcessId` Even if this attribute is public you must never access to it.
    `protected int` | `pid` The PID of the process
    `protected int` | `ppid` The PPID of the process
    `double` | `startTime` Start time of the process

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Process()` Default constructor
    `` | `Process(Host host, java.lang.String name)` Constructs a new process from a host and his name.
    `` | `Process(Host host, java.lang.String name, java.lang.String[] args)` Constructs a new process from a host and his name, the arguments of here method function are specified by the parameter args.
    `` | `Process(Host host, java.lang.String name, java.lang.String[] args, double startTime, double killTime)` Constructs a new process from a host and his name, the arguments of here method function are specified by the parameter args.
    `` | `Process(java.lang.String hostname, java.lang.String name)` Constructs a new process from the name of a host and his name.
    `` | `Process(java.lang.String hostname, java.lang.String name, java.lang.String[] args)` Constructs a new process from the name of a host and his name.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `create(java.lang.String hostName)` The natively implemented method to create an MSG process.
    `static Process` | `currentProcess()` This static method returns the currently running process.
    `void` | `exit()`
    `static Process` | `fromPID(int PID)` This static method gets a process from a PID.
    `static int` | `getCount()` This static method returns the current amount of processes running
    `Host` | `getHost()` Returns the host of the process.
    `int` | `getPID()` This method returns the PID of the process.
    `int` | `getPPID()` This method returns the PID of the parent of a process.
    `java.lang.String` | `getProperty(java.lang.String name)` Returns the value of a given process property.
    `boolean` | `isSuspended()` Tests if a process is suspended.
    `void` | `kill()` This method kill a process.
    `static int` | `killAll(int resetPID)` This method kills all running process of the simulation.
    `abstract void` | `main(java.lang.String[] args)` The main function of the process (to implement).
    `void` | `migrate(Host host)` Migrates a process to another host.
    `java.lang.String` | `msgName()` Returns the name of the process
    `static void` | `nativeInit()` Class initializer, to initialize various JNI stuff
    `void` | `pause()` Deprecated.
    `void` | `restart()` Restarts the process from the beginning
    `void` | `resume()` Resumes a suspended process by resuming the task on which it was waiting for the completion.
    `void` | `run()` This method runs the process.
    `void` | `setAutoRestart(boolean autoRestart)` Sets the "auto-restart" flag of the process.
    `void` | `setKillTime(double killTime)` Set the kill time of the process
    `void` | `showArgs()`
    `static void` | `sleep(long millis)` Makes the current process sleep until millis millisecondes have elapsed.
    `static void` | `sleep(long millis, int nanos)` Makes the current process sleep until millis milliseconds and nanos nanoseconds have elapsed.
    `void` | `start()` This method actually creates and run the process.
    `void` | `suspend()` Suspends the process by suspending the task on which it was waiting for the completion.
    `void` | `waitFor(double seconds)` Makes the current process sleep until time seconds have elapsed.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### nextProcessId

          public static long nextProcessId

      Even if this attribute is public you must never access to it. It is used to compute the id of an MSG process.

    - #### id

          public long id

      Even if this attribute is public you must never access to it. It is compute automatically during the creation of the object. The native functions use this identifier to synchronize the process.

    - #### startTime

          public double startTime

      Start time of the process

    - #### killTime

          public double killTime

      Kill time of the process

    - #### name

          protected java.lang.String name

      The name of the process.

    - #### pid

          protected int pid

      The PID of the process

    - #### ppid

          protected int ppid

      The PPID of the process

    - #### host

          protected Host host

      The host of the process

    - #### args

          public java.util.Vector<java.lang.String> args

      The arguments of the method function of the process.

  - ### Constructor Detail

    - #### Process

          protected Process()

      Default constructor

    - #### Process

          public Process(java.lang.String hostname,
                 java.lang.String name)
                  throws HostNotFoundException

      Constructs a new process from the name of a host and his name. The method function of the process doesn't have argument.
      Parameters:
        `hostname` - The name of the host of the process to create.
        `name` - The name of the process.
      Throws:
        `HostNotFoundException` - if no host with this name exists.

    - #### Process

          public Process(java.lang.String hostname,
                 java.lang.String name,
                 java.lang.String[] args)
                  throws HostNotFoundException,
                         NativeException

      Constructs a new process from the name of a host and his name. The arguments of the method function of the process are specified by the parameter args.
      Parameters:
        `hostname` - The name of the host of the process to create.
        `name` - The name of the process.
        `args` - The arguments of the main function of the process.
      Throws:
        `HostNotFoundException` - if no host with this name exists. NativeException
        `NativeException`

    - #### Process

          public Process(Host host,
                 java.lang.String name)

      Constructs a new process from a host and his name. The method function of the process doesn't have argument.
      Parameters:
        `host` - The host of the process to create.
        `name` - The name of the process.

    - #### Process

          public Process(Host host,
                 java.lang.String name,
                 java.lang.String[] args)

      Constructs a new process from a host and his name, the arguments of here method function are specified by the parameter args.
      Parameters:
        `host` - The host of the process to create.
        `name` - The name of the process.
        `args` - The arguments of main method of the process.

    - #### Process

          public Process(Host host,
                 java.lang.String name,
                 java.lang.String[] args,
                 double startTime,
                 double killTime)

      Constructs a new process from a host and his name, the arguments of here method function are specified by the parameter args.
      Parameters:
        `host` - The host of the process to create.
        `name` - The name of the process.
        `args` - The arguments of main method of the process.
        `startTime` - Start time of the process
        `killTime` - Kill time of the process

  - ### Method Detail

    - #### create

          protected void create(java.lang.String hostName)
                         throws HostNotFoundException

      The natively implemented method to create an MSG process.
      Parameters:
        `hostName` - A valid (bound) host where create the process.
      Throws:
        `HostNotFoundException`

    - #### killAll

          public static int killAll(int resetPID)

      This method kills all running process of the simulation.
      Parameters:
        `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.
      Returns:
        The function returns the PID of the next created process.

    - #### kill

          public void kill()

      This method kill a process.

    - #### suspend

          public void suspend()

      Suspends the process by suspending the task on which it was waiting for the completion.

    - #### pause

          @Deprecated
          public void pause()

      Deprecated.
      Suspends the process by suspending the task on which it was waiting for the completion. DEPRECATED: use suspend instead.

    - #### setAutoRestart

          public void setAutoRestart(boolean autoRestart)

      Sets the "auto-restart" flag of the process.

    - #### restart

          public void restart()

      Restarts the process from the beginning

    - #### resume

          public void resume()

      Resumes a suspended process by resuming the task on which it was waiting for the completion.

    - #### isSuspended

          public boolean isSuspended()

      Tests if a process is suspended.
      Returns:
        The method returns true if the process is suspended. Otherwise the method returns false.

    - #### msgName

          public java.lang.String msgName()

      Returns the name of the process

    - #### getHost

          public Host getHost()

      Returns the host of the process.
      Returns:
        The host instance of the process.

    - #### fromPID

          public static Process fromPID(int PID)
                                 throws NativeException

      This static method gets a process from a PID.
      Parameters:
        `PID` - The process identifier of the process to get.
      Returns:
        The process with the specified PID.
      Throws:
        `NativeException` - on error in the native SimGrid code

    - #### getPID

          public int getPID()

      This method returns the PID of the process.
      Returns:
        The PID of the process.

    - #### getPPID

          public int getPPID()

      This method returns the PID of the parent of a process.
      Returns:
        The PID of the parent of the process.

    - #### getProperty

          public java.lang.String getProperty(java.lang.String name)

      Returns the value of a given process property.

    - #### setKillTime

          public void setKillTime(double killTime)

      Set the kill time of the process
      Parameters:
        `killTime` - the time when the process is killed

    - #### currentProcess

          public static Process currentProcess()

      This static method returns the currently running process.
      Returns:
        The current process.

    - #### migrate

          public void migrate(Host host)

      Migrates a process to another host.
      Parameters:
        `host` - The host where to migrate the process.

    - #### sleep

          public static void sleep(long millis)
                            throws HostFailureException

      Makes the current process sleep until millis millisecondes have elapsed. You should note that unlike "waitFor" which takes seconds, this method takes milliseconds. FIXME: Not optimal, maybe we should have two native functions.
      Parameters:
        `millis` - the length of time to sleep in milliseconds.
      Throws:
        `HostFailureException`

    - #### sleep

          public static void sleep(long millis,
                   int nanos)
                            throws HostFailureException

      Makes the current process sleep until millis milliseconds and nanos nanoseconds have elapsed. You should note that unlike "waitFor" which takes seconds, this method takes milliseconds and nanoseconds. Overloads Thread.sleep.
      Parameters:
        `millis` - the length of time to sleep in milliseconds.
        `nanos` - additionnal nanoseconds to sleep.
      Throws:
        `HostFailureException`

    - #### waitFor

          public void waitFor(double seconds)
                       throws HostFailureException

      Makes the current process sleep until time seconds have elapsed.
      Parameters:
        `seconds` - The time the current process must sleep.
      Throws:
        `HostFailureException`

    - #### showArgs

          public void showArgs()

    - #### start

          public final void start()
                           throws HostNotFoundException

      This method actually creates and run the process. It is a noop if the process is already launched.
      Throws:
        `HostNotFoundException`

    - #### run

          public void run()

      This method runs the process. Il calls the method function that you must overwrite.
      Specified by:
        `run` in interface `java.lang.Runnable`

    - #### main

          public abstract void main(java.lang.String[] args)
                             throws MsgException

      The main function of the process (to implement).
      Parameters:
        `args` -
      Throws:
        `MsgException`

    - #### exit

          public void exit()

    - #### nativeInit

          public static void nativeInit()

      Class initializer, to initialize various JNI stuff

    - #### getCount

          public static int getCount()

      This static method returns the current amount of processes running
      Returns:
        The count of the running processes