public class ForkedProcessService extends WorkflowExecutorService<ExecutorService> implements LongLivedProcessLifecycleEvent, Runnable
Key Features:
executionTimeout can be set to set a limit
on the duration of a processLongLivedProcessLifecycleEvent, is raised on the start
and finish of a process.ForkedProcessService(String, Map, List),
or have its simple constructor used to instantiate the service, then the
build(Map, List) command used to define the environment variables
and list of commands to execute. One of these two options MUST be exercised
before calling the services's AbstractService.start() method.
The forked process is executed in the service's serviceStart() method;
if still running when the service is stopped, serviceStop() will
attempt to stop it.
The service delegates process execution to LongLivedProcess,
receiving callbacks via the LongLivedProcessLifecycleEvent.
When the service receives a callback notifying that the process has completed,
it calls its AbstractService.stop() method. If the error code was non-zero,
the service is logged as having failed.| Constructor and Description |
|---|
ForkedProcessService(String name)
Create an instance of the service
|
ForkedProcessService(String name,
Map<String,String> env,
List<String> commandList)
Create an instance of the service, set up the process
|
| Modifier and Type | Method and Description |
|---|---|
void |
build(Map<String,String> env,
List<String> commandList)
Build the process to execute when the service is started
|
protected void |
completed()
Note the process as having completed.
|
Integer |
getExitCode() |
int |
getExitCodeSignCorrected() |
List<String> |
getRecentOutput()
Get the recent output from the process, or [] if not defined
|
List<String> |
getRecentOutput(boolean finalOutput,
int duration)
Get the recent output from the process, or [] if not defined
|
boolean |
isProcessRunning()
Is a process running: between started and terminated
|
boolean |
isProcessStarted() |
boolean |
isProcessTerminated() |
void |
onProcessExited(LongLivedProcess process,
int uncorrected,
int code)
Callback when a process has finished
|
void |
onProcessStarted(LongLivedProcess process)
Callback when a process is started
|
void |
run()
handle timeout response by escalating it to a failure
|
protected void |
serviceStart() |
protected void |
serviceStop()
Stop the service: halt the executor.
|
void |
setProcessLog(org.slf4j.Logger processLog)
Set the process log.
|
void |
setTimeout(int timeout,
int code)
Set the timeout by which time a process must have finished -or -1 for forever
|
execute, getExecutor, setExecutor, stopExecutor, submitclose, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceInit, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStoppublic ForkedProcessService(String name)
name - a namepublic ForkedProcessService(String name, Map<String,String> env, List<String> commandList) throws IOException
name - a namecommandList - list of commands is inserted on the frontenv - environment variables above those generated byIOException - IO problemsprotected void serviceStart()
throws Exception
serviceStart in class org.apache.hadoop.service.AbstractServiceExceptionprotected void serviceStop()
throws Exception
WorkflowExecutorServiceserviceStop in class WorkflowExecutorService<ExecutorService>Exception - exception.public void setProcessLog(org.slf4j.Logger processLog)
processLog - process logpublic void setTimeout(int timeout,
int code)
timeout - timeout in millisecondspublic void build(Map<String,String> env, List<String> commandList) throws IOException
commandList - list of commands is inserted on the frontenv - environment variables above those generated byIOException - IO problemspublic void onProcessStarted(LongLivedProcess process)
LongLivedProcessLifecycleEventonProcessStarted in interface LongLivedProcessLifecycleEventprocess - the process invoking the callbackpublic void onProcessExited(LongLivedProcess process, int uncorrected, int code)
LongLivedProcessLifecycleEventonProcessExited in interface LongLivedProcessLifecycleEventprocess - the process invoking the callbackuncorrected - exit code from the processcode - the code- as sign correctedpublic void run()
protected void completed()
processTerminated
is notifiedpublic boolean isProcessTerminated()
public boolean isProcessStarted()
public boolean isProcessRunning()
public Integer getExitCode()
public int getExitCodeSignCorrected()
public List<String> getRecentOutput()
public List<String> getRecentOutput(boolean finalOutput, int duration)
finalOutput - flag to indicate "wait for the final output of the process"duration - the duration, in ms,
to wait for recent output to become non-emptyCopyright © 2014–2015 The Apache Software Foundation. All rights reserved.