Class ProcessSupport

java.lang.Object
de.iip_ecosphere.platform.services.environment.ProcessSupport

public class ProcessSupport extends Object
Process execution support functions. Process scripts or binaries shall be packaged using a Maven assembly descriptor into a ZIP file in the "root" of the Jar/Service artifact (fallback for testing can be defined, e.g., src/main/python/...). Here, the name is free, but shall not collide with the default process artifacts of generated services.
Author:
Holger Eichelberger, SSE
  • Field Details

    • INHERIT_IO

      public static final Consumer<ProcessBuilder> INHERIT_IO
      A simple default customizer always requesting to inherit the process IO (standard in/out/err). May particularly be helpful for debugging.
  • Constructor Details

    • ProcessSupport

      public ProcessSupport()
  • Method Details

    • callPython

      public static void callPython(ProcessSupport.ScriptOwner owner, String script, Consumer<String> cmdResult, String... args)
      Call python scripts, waiting for and killing finally. Scripts shall be located in a Maven packaged ZIP represented by owner (including unpacking state).
      Parameters:
      owner - the script owner and data instance
      script - the script file name to execute in the context of owner
      cmdResult - a consumer for the result, may be null for none
      args - the process arguments for the script including python arguments (first), script and script arguments
    • createPythonProcess

      public static Process createPythonProcess(File dir, String script, Consumer<ProcessBuilder> procCustomizer, String... args) throws IOException
      Creates and starts a Python process.
      Parameters:
      dir - the home dir where to find the script/run it within
      script - the script to execute
      procCustomizer - allows to customize the internal process builder, may be null for none
      args - the process arguments for the script including python arguments (first), script and script arguments
      Returns:
      the created process
      Throws:
      IOException - if process creation fails
    • waitForAndKill

      public static int waitForAndKill(Process proc, String script, Consumer<String> cmdResult, String resultFile)
      Wait for a (scripted) process until it is really dead.
      Parameters:
      proc - the process to wait for
      script - the script name for logging
      cmdResult - a consumer for the result, may be null for none
      resultFile - file to read result from, e.g., short lived processes, if null use standard in
      Returns:
      the process status, -1 if the process was not executed
      See Also:
    • callPythonWaitForAndKill

      public static int callPythonWaitForAndKill(File dir, String script, Consumer<String> cmdResult, String resultFile, Consumer<ProcessBuilder> cust, String... args)
      Call python, wait for ending and kill it if needed. Catch all exceptions.
      Parameters:
      dir - the home dir where to find the script/run it within
      script - the script to execute
      cmdResult - a consumer for the result, may be null for none
      resultFile - file to read result from, e.g., short lived processes, if null use standard in
      cust - optional process customizer, may be null for none
      args - the process arguments for the script including python arguments (first), script and script arguments
      Returns:
      the process status, -1 if the process was not executed
      See Also: