Package org.apache.maven.surefire.booter
Interface ProcessChecker
public interface ProcessChecker
Interface for checking if a process (typically the parent Maven plugin) is still alive.
Implementations allow the forked JVM to detect when its parent Maven process has terminated, enabling cleanup and preventing orphaned processes.
- Since:
- 3.5.5
-
Method Summary
Modifier and TypeMethodDescriptionbooleancanUse()Deprecated.voidDestroys any active commands or subprocesses used by this checker.booleanChecks if the process is still alive.static booleanReturns whether the ProcessHandle API is available in the current JVM.booleanChecks if the checker has been stopped.static ProcessCheckerCreates the appropriateProcessCheckerimplementation for the given parent PID.org.apache.maven.surefire.booter.ProcessInfoReturns information about the process being checked.voidstop()Stops the checker and releases any resources.
-
Method Details
-
of
Creates the appropriateProcessCheckerimplementation for the given parent PID.On Java 9+, uses
ProcessHandleCheckerwhich leverages theProcessHandleAPI. On Java 8, falls back toPpidCheckerwhich uses native commands.- Parameters:
ppid- the parent process ID as a string, ornull- Returns:
- a new checker instance, or
nullif ppid isnull
-
isProcessHandleSupported
static boolean isProcessHandleSupported()Returns whether the ProcessHandle API is available in the current JVM.- Returns:
trueif running on Java 9+ with ProcessHandle available
-
canUse
Deprecated.with using ProcessHandleChecker on Java 9+, this method will always returntrueand can be removed in a future release.Checks whether this checker can be used to monitor the process.This method must return
truebeforeisProcessAlive()can be called.- Returns:
trueif the checker is operational and can monitor the process
-
isProcessAlive
boolean isProcessAlive()Checks if the process is still alive.This method can only be called after
canUse()has returnedtrue.- Returns:
trueif the process is still running;falseif it has terminated or if the PID has been reused by a different process- Throws:
IllegalStateException- ifcanUse()returnsfalseor if the checker has been stopped
-
stop
void stop()Stops the checker and releases any resources.After calling this method,
canUse()will returnfalse. -
destroyActiveCommands
void destroyActiveCommands()Destroys any active commands or subprocesses used by this checker.This is called during shutdown to ensure clean termination.
-
isStopped
boolean isStopped()Checks if the checker has been stopped.- Returns:
trueifstop()ordestroyActiveCommands()has been called
-
processInfo
org.apache.maven.surefire.booter.ProcessInfo processInfo()Returns information about the process being checked.- Returns:
- the process information, or
nullif not yet initialized
-
trueand can be removed in a future release.