Service wrapper for an external program that is launched and can/will terminate. This service is notified when the subprocess terminates, and stops itself and converts a non-zero exit code into a failure exception.
Key Features:
- The property {@link #executionTimeout} can be set to set a limiton the duration of a process
- Output is streamed to the output logger provided
. - The most recent lines of output are saved to a linked list
. - A synchronous callback, {@link LongLivedProcessLifecycleEvent}, is raised on the start and finish of a process.
Usage:
The service can be built in the constructor, {@link #ForkedProcessService(String,Map,List)}, or have its simple constructor used to instantiate the service, then the {@link #build(Map,List)} command used to define the environment variablesand list of commands to execute. One of these two options MUST be exercised before calling the services's {@link #start()} method.
The forked process is executed in the service's {@link #serviceStart()} method;if still running when the service is stopped, {@link #serviceStop()} willattempt to stop it.
The service delegates process execution to {@link LongLivedProcess}, receiving callbacks via the {@link LongLivedProcessLifecycleEvent}. When the service receives a callback notifying that the process has completed, it calls its {@link #stop()} method. If the error code was non-zero, the service is logged as having failed.