public class LongLivedProcess extends Object implements Runnable
Hadoop's Shell class assumes it is executing
a short lived application; this class allows for the process to run for the
life of the Java process that forked it.
It is designed to be embedded inside a YARN service, though this is not
the sole way that it can be used
Key Features:
LongLivedProcessLifecycleEvent, is raised on the start
and finish of a process.| Modifier and Type | Field and Description |
|---|---|
static int |
RECENT_LINE_LOG_LIMIT
Limit on number of lines to retain in the "recent" line list:64
|
| Constructor and Description |
|---|
LongLivedProcess(String name,
org.slf4j.Logger processLog,
List<String> commands)
Create an instance
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
describeBuilder()
Get a text description of the builder suitable for log output
|
void |
dumpEnv(StringBuilder buffer)
Dump the environment to a string builder
|
String |
getCommand() |
List<String> |
getCommands()
Get the command list
|
String |
getEnv(String variable)
Get the process environment
|
Integer |
getExitCode()
Get the exit code: null until the process has finished
|
Integer |
getExitCodeSignCorrected()
Get the exit code sign corrected: null until the process has finished
|
Process |
getProcess()
Get the process reference
|
ProcessBuilder |
getProcessBuilder()
Get the process builder -this can be manipulated
up to the start() operation.
|
List<String> |
getRecentOutput()
Get the lines of recent output
|
List<String> |
getRecentOutput(boolean finalOutput,
int duration)
Get the recent output from the process, or [] if not defined
|
boolean |
isFinalOutputProcessed()
Query to see if the final output has been processed
|
boolean |
isRecentOutputEmpty() |
boolean |
isRunning()
probe to see if the process is running
|
void |
putEnvMap(Map<String,String> map)
Bulk set the environment from a map.
|
void |
run()
Entry point for waiting for the program to finish
|
void |
setEnv(String envVar,
String val)
Add an entry to the environment
|
void |
setLifecycleCallback(LongLivedProcessLifecycleEvent lifecycleCallback)
Set an optional application exit callback
|
void |
setProcessLog(org.slf4j.Logger processLog)
Set the process log.
|
void |
setRecentLineLimit(int recentLineLimit)
Set the limit on recent lines to retain
|
void |
start()
Spawn the application
|
void |
stop()
Stop the process if it is running.
|
public static final int RECENT_LINE_LOG_LIMIT
public void setRecentLineLimit(int recentLineLimit)
recentLineLimit - size of rolling list of recent lines.public void setLifecycleCallback(LongLivedProcessLifecycleEvent lifecycleCallback)
lifecycleCallback - callback to notify on application exitpublic void setEnv(String envVar, String val)
envVar - envVar -must not be nullval - valuepublic void putEnvMap(Map<String,String> map)
map - map to addpublic String getEnv(String variable)
variable - environment variablepublic void setProcessLog(org.slf4j.Logger processLog)
processLog - new log ... may be nullpublic Process getProcess()
public ProcessBuilder getProcessBuilder()
public String getCommand()
public boolean isRunning()
public Integer getExitCode()
public Integer getExitCodeSignCorrected()
public void stop()
protected String describeBuilder()
public void dumpEnv(StringBuilder buffer)
buffer - the buffer to append topublic void run()
public void start()
throws IOException
IOException - IO problemspublic List<String> getRecentOutput()
public boolean isRecentOutputEmpty()
public boolean isFinalOutputProcessed()
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,
ro wait for recent output to become non-emptyCopyright © 2014–2015 The Apache Software Foundation. All rights reserved.