Class 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 Description
      protected double startTime
      Time at which the process should be created
    • Constructor Summary

      Constructors 
      Constructor Description
      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.
      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[] argsParam)
      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.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void create​(Host host)
      The native method to create an MSG process.
      void exit()
      Stops the execution of the current actor
      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
      static Process getCurrentProcess()
      This static method returns the currently running process.
      Host getHost()
      Returns the host of the process.
      java.lang.String getName()
      Returns the name 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()
      Simply kills the receiving process.
      static void kill​(Process p)  
      static void killAll()
      This method kills all running process of the simulation.
      abstract void main​(java.lang.String[] args)
      The main function of the process (to implement by the user).
      void migrate​(Host host)
      Migrates a process to another host.
      void restart()
      Restarts the process from the beginning
      void resume()
      Resume a process that was suspended by suspend().
      void run()
      This method runs the process.
      void setAutoRestart​(boolean autoRestart)
      Specify whether the process should restart when its host restarts after a failure A process naturally stops when its host stops.
      void setKillTime​(double killTime)
      Set the kill time of the process
      static void sleep​(long millis)
      Makes the current process sleep until millis milliseconds 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.
      void waitFor​(double seconds)
      Makes the current process sleep until time seconds have elapsed.
      static void yield()
      Yield the current process.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • startTime

        protected double startTime
        Time at which the process should be created
    • Constructor Detail

      • 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 - Where to create the process.
        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
        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 - Where to create the process.
        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.
      • 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 - Where to create the process.
        name - The name of the process.
      • Process

        public Process​(Host host,
                       java.lang.String name,
                       java.lang.String[] argsParam)
        Constructs a new process from a host and his name, the arguments of here method function are specified by the parameter args.
        Parameters:
        host - Where to create the process.
        name - The name of the process.
        argsParam - 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 - Where to create the process.
        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​(Host host)
        The native method to create an MSG process.
        Parameters:
        host - where to create the process.
      • killAll

        public static void killAll()
        This method kills all running process of the simulation.
      • kill

        public void kill()
        Simply kills the receiving process. SimGrid sometimes have issues when you kill processes that are currently communicating and such. We are working on it to fix the issues.
      • kill

        public static void kill​(Process p)
      • suspend

        public void suspend()
        Suspends the process. See resume() to resume it afterward
      • resume

        public void resume()
        Resume a process that was suspended by suspend().
      • isSuspended

        public boolean isSuspended()
        Tests if a process is suspended.
        See Also:
        suspend(), resume()
      • yield

        public static void yield()
        Yield the current process. All other processes that are ready at the same timestamp will be executed first
      • setAutoRestart

        public void setAutoRestart​(boolean autoRestart)
        Specify whether the process should restart when its host restarts after a failure A process naturally stops when its host stops. It starts again only if autoRestart is set to true. Otherwise, it just disappears when the host stops.
      • restart

        public void restart()
        Restarts the process from the beginning
      • getName

        public java.lang.String getName()
        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)
        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.
      • 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
      • getCurrentProcess

        public static Process getCurrentProcess()
        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 milliseconds 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. Unlike waitFor(double) which takes seconds, this method takes milliseconds and nanoseconds. Overloads Thread.sleep.
        Parameters:
        millis - the length of time to sleep in milliseconds.
        nanos - additional 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
      • start

        public final void start()
        This method actually creates and run the process. It is a noop if the process is already launched.
      • run

        public void run()
        This method runs the process. It 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 by the user).
        Parameters:
        args -
        Throws:
        MsgException
      • exit

        public void exit()
        Stops the execution of the current actor
      • getCount

        public static int getCount()
        This static method returns the current amount of processes running
        Returns:
        The count of the running processes