Class ProcessManager


  • @ThreadSafe
    public class ProcessManager
    extends java.lang.Object
    A simple process manager which forks processes and kills them if necessary.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.io.File INHERIT_IO_FILE
      A symbolic file to indicate that we want to inherit I/O of parent process.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ProcessManager create()  
      ProcessManager.RunningProcess startProcess​(java.lang.String id, java.lang.String command, java.util.List<java.lang.String> args, java.util.Map<java.lang.String,​java.lang.String> env)
      Forks a process with the given command, arguments, and additional environment variables.
      ProcessManager.RunningProcess startProcess​(java.lang.String id, java.lang.String command, java.util.List<java.lang.String> args, java.util.Map<java.lang.String,​java.lang.String> env, java.io.File outputFile)  
      void stopProcess​(java.lang.String id)
      Stops a previously started process identified by its unique id.
      • Methods inherited from class java.lang.Object

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

      • INHERIT_IO_FILE

        public static final java.io.File INHERIT_IO_FILE
        A symbolic file to indicate that we want to inherit I/O of parent process.
    • Method Detail

      • startProcess

        public ProcessManager.RunningProcess startProcess​(java.lang.String id,
                                                          java.lang.String command,
                                                          java.util.List<java.lang.String> args,
                                                          java.util.Map<java.lang.String,​java.lang.String> env)
                                                   throws java.io.IOException
        Forks a process with the given command, arguments, and additional environment variables.
        Parameters:
        id - A unique id for the process
        command - The name of the executable to run
        args - Arguments to provide to the executable
        env - Additional environment variables for the process to be forked
        Returns:
        A RunningProcess which can be checked for liveness
        Throws:
        java.io.IOException
      • startProcess

        public ProcessManager.RunningProcess startProcess​(java.lang.String id,
                                                          java.lang.String command,
                                                          java.util.List<java.lang.String> args,
                                                          java.util.Map<java.lang.String,​java.lang.String> env,
                                                          java.io.File outputFile)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • stopProcess

        public void stopProcess​(java.lang.String id)
        Stops a previously started process identified by its unique id.