Class ProcessHandler
- java.lang.Object
-
- org.projectnessie.quarkus.runner.ProcessHandler
-
public class ProcessHandler extends Object
Handles the execution of an external process, focused on running a Quarkus application jar.Starts the process configured in a
ProcessBuilder, provides a method to get theQuarkus HTTP listen URLas Quarkus prints to stdout, and manages process lifetime and line-by-line I/O pass-through for stdout + stderr.Any instance of this class can only be used to start (and stop) one process and cannot be reused for another process.
This implementation is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static longMILLIS_TO_HTTP_PORTstatic longMILLIS_TO_STOP
-
Constructor Summary
Constructors Constructor Description ProcessHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetExitCode()Retrieves the exit-code of the process, if it terminated or throws aIllegalThreadStateExceptionif it is still alive.StringgetListenUrl()Returns the http(s) listen URL as a string as emitted to stdout by Quarkus.booleanisAlive()ProcessHandlersetStderrTarget(Consumer<String> stderrTarget)ProcessHandlersetStdoutTarget(Consumer<String> stdoutTarget)ProcessHandlersetTicker(LongSupplier ticker)ProcessHandlersetTimeStopMillis(long timeStopMillis)ProcessHandlersetTimeToListenUrlMillis(long timeToListenUrlMillis)ProcessHandlerstart(ProcessBuilder processBuilder)Starts the process from the givenProcessBuilder.voidstop()Stops the process.
-
-
-
Field Detail
-
MILLIS_TO_HTTP_PORT
public static final long MILLIS_TO_HTTP_PORT
- See Also:
- Constant Field Values
-
MILLIS_TO_STOP
public static final long MILLIS_TO_STOP
- See Also:
- Constant Field Values
-
-
Method Detail
-
setTimeToListenUrlMillis
public ProcessHandler setTimeToListenUrlMillis(long timeToListenUrlMillis)
-
setTimeStopMillis
public ProcessHandler setTimeStopMillis(long timeStopMillis)
-
setStdoutTarget
public ProcessHandler setStdoutTarget(Consumer<String> stdoutTarget)
-
setStderrTarget
public ProcessHandler setStderrTarget(Consumer<String> stderrTarget)
-
setTicker
public ProcessHandler setTicker(LongSupplier ticker)
-
start
public ProcessHandler start(ProcessBuilder processBuilder) throws IOException
Starts the process from the givenProcessBuilder.- Parameters:
processBuilder- process to start- Returns:
- instance handling the process' runtime
- Throws:
IOException- usually, if the process fails to start
-
getListenUrl
public String getListenUrl() throws InterruptedException, TimeoutException
Returns the http(s) listen URL as a string as emitted to stdout by Quarkus.If the Quarkus process does not emit that URL within the time configured via
setTimeToListenUrlMillis(long), which defaults to 30000L ms, this method will throw anIllegalStateException.- Returns:
- the listen URL, never
null. - Throws:
InterruptedException- if the current thread was interrupted while waiting for the listen URL.TimeoutException- if the Quarkus process did not write the listen URL to stdout.
-
stop
public void stop()
Stops the process.Tries to gracefully stop the process via a
SIGTERM. If the process is still alive aftersetTimeStopMillis(long), which defaults to 15000L ms, the process will be killed with aSIGKILL.
-
isAlive
public boolean isAlive()
-
getExitCode
public int getExitCode() throws IllegalThreadStateExceptionRetrieves the exit-code of the process, if it terminated or throws aIllegalThreadStateExceptionif it is still alive.- Returns:
- the exit code of the process
- Throws:
IllegalThreadStateException- if the process is still alive
-
-