Class ProcessSupport
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.ProcessSupport
-
public class ProcessSupport extends java.lang.ObjectProcess 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProcessSupport.ScriptOwnerHolds the script context.
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Consumer<java.lang.ProcessBuilder>INHERIT_IOA simple default customizer always requesting to inherit the process IO (standard in/out/err).
-
Constructor Summary
Constructors Constructor Description ProcessSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcallPython(ProcessSupport.ScriptOwner owner, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String... args)Call python scripts, waiting for and killing finally.static intcallPythonWaitForAndKill(java.io.File dir, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String resultFile, java.util.function.Consumer<java.lang.ProcessBuilder> cust, java.lang.String... args)Call python, wait for ending and kill it if needed.static java.lang.ProcesscreatePythonProcess(java.io.File dir, java.lang.String script, java.util.function.Consumer<java.lang.ProcessBuilder> procCustomizer, java.lang.String... args)Creates and starts a Python process.static intwaitForAndKill(java.lang.Process proc, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String resultFile)Wait for a (scripted) process until it is really dead.
-
-
-
Method Detail
-
callPython
public static void callPython(ProcessSupport.ScriptOwner owner, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String... args)
Call python scripts, waiting for and killing finally. Scripts shall be located in a Maven packaged ZIP represented byowner(including unpacking state).- Parameters:
owner- the script owner and data instancescript- the script file name to execute in the context ofownercmdResult- a consumer for the result, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments
-
createPythonProcess
public static java.lang.Process createPythonProcess(java.io.File dir, java.lang.String script, java.util.function.Consumer<java.lang.ProcessBuilder> procCustomizer, java.lang.String... args) throws java.io.IOExceptionCreates and starts a Python process.- Parameters:
dir- the home dir where to find the script/run it withinscript- the script to executeprocCustomizer- allows to customize the internal process builder, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments- Returns:
- the created process
- Throws:
java.io.IOException- if process creation fails
-
waitForAndKill
public static int waitForAndKill(java.lang.Process proc, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String resultFile)Wait for a (scripted) process until it is really dead.- Parameters:
proc- the process to wait forscript- the script name for loggingcmdResult- a consumer for the result, may be null for noneresultFile- file to read result from, e.g., short lived processes, ifnulluse standard in- Returns:
- the process status,
-1if the process was not executed - See Also:
AbstractProcessService.redirectIO(InputStream, PrintStream)
-
callPythonWaitForAndKill
public static int callPythonWaitForAndKill(java.io.File dir, java.lang.String script, java.util.function.Consumer<java.lang.String> cmdResult, java.lang.String resultFile, java.util.function.Consumer<java.lang.ProcessBuilder> cust, java.lang.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 withinscript- the script to executecmdResult- a consumer for the result, may be null for noneresultFile- file to read result from, e.g., short lived processes, ifnulluse standard incust- optional process customizer, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments- Returns:
- the process status,
-1if the process was not executed - See Also:
createPythonProcess(File, String, Consumer, String...),waitForAndKill(Process, String, Consumer, String)
-
-