public final class GridJavaProcess extends Object
Process suited to run any Java class as separate java process.
This launcher supports simple interchange-with-a-process protocol to talk (in fact, listen) to process.
For the moment the only message in protocol is run process PID. Class-to-run should print it's PID
prefixed with #PID_MSG_PREFIX to tell the GridJavaProcess it's PID.
Protocol transport is any of (or both) system.out and/or system.err, so any protocol message should be printed in the class-to-run.
NOTE 1: For the moment inner class running is not supported.
NOTE 2: This util class should work fine on Linux, Mac OS and Windows.
| Modifier and Type | Field and Description |
|---|---|
static String |
PID_MSG_PREFIX
Internal protocol message prefix saying that the next text in the outputted line is pid.
|
| Modifier and Type | Method and Description |
|---|---|
static GridJavaProcess |
exec(Class cls,
String params,
@Nullable IgniteLogger log,
@Nullable IgniteInClosure<String> printC,
@Nullable GridAbsClosure procKilledC)
Executes main() method of the given class in a separate system process.
|
static GridJavaProcess |
exec(Class cls,
String params,
@Nullable IgniteLogger log,
@Nullable IgniteInClosure<String> printC,
@Nullable GridAbsClosure procKilledC,
@Nullable Collection<String> jvmArgs,
@Nullable String cp)
Executes main() method of the given class in a separate system process.
|
static GridJavaProcess |
exec(String clsName,
String params,
@Nullable IgniteLogger log,
@Nullable IgniteInClosure<String> printC,
@Nullable GridAbsClosure procKilledC,
@Nullable String javaHome,
@Nullable Collection<String> jvmArgs,
@Nullable String cp)
Executes main() method of the given class in a separate system process.
|
int |
getPid()
Returns pid of the java process.
|
Process |
getProcess()
Exposes wrapped java Process.
|
void |
kill()
Kills the java process.
|
void |
killProcess()
Kills process using
Process.destroy(). |
public static final String PID_MSG_PREFIX
public static GridJavaProcess exec(Class cls, String params, @Nullable @Nullable IgniteLogger log, @Nullable @Nullable IgniteInClosure<String> printC, @Nullable @Nullable GridAbsClosure procKilledC) throws Exception
cls - Class with main() method to be run.params - main() method parameters.printC - Optional closure to be called each time wrapped process prints line to system.out or system.err.procKilledC - Optional closure to be called when process termination is detected.log - Log to use.ProcessException - If any problem occurred.public static GridJavaProcess exec(Class cls, String params, @Nullable @Nullable IgniteLogger log, @Nullable @Nullable IgniteInClosure<String> printC, @Nullable @Nullable GridAbsClosure procKilledC, @Nullable @Nullable Collection<String> jvmArgs, @Nullable @Nullable String cp) throws Exception
cls - Class with main() method to be run.params - main() method parameters.printC - Optional closure to be called each time wrapped process prints line to system.out or system.err.procKilledC - Optional closure to be called when process termination is detected.log - Log to use.jvmArgs - JVM arguments to use.cp - Additional classpath.ProcessException - If any problem occurred.public static GridJavaProcess exec(String clsName, String params, @Nullable @Nullable IgniteLogger log, @Nullable @Nullable IgniteInClosure<String> printC, @Nullable @Nullable GridAbsClosure procKilledC, @Nullable @Nullable String javaHome, @Nullable @Nullable Collection<String> jvmArgs, @Nullable @Nullable String cp) throws Exception
clsName - Class with main() method to be run.params - main() method parameters.log - Log to use.printC - Optional closure to be called each time wrapped process prints line to system.out or system.err.procKilledC - Optional closure to be called when process termination is detected.javaHome - Java home location. The process will be started under given JVM.jvmArgs - JVM arguments to use.cp - Additional classpath.ProcessException - If any problem occurred.public void kill()
throws Exception
Exception - If any problem occurred.public void killProcess()
Process.destroy().public int getPid()
public Process getProcess()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.11.0 Release Date : September 11 2021