Class SpawnProcess
- Direct Known Subclasses:
Adapter
- Since:
- 1
- Version:
- 10
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a command line argument.getArgs()Return the exit status of the process.getGroup()Return the group that the program should be run as.Return the listener attached to the process.getPath()intgetPid()intReturn anInputStreamthat reads from stderr of the running process.Return anOutputStreamthat writes data to stdin of the running process.Return anInputStreamthat reads from stdout of the running process.getUser()Return the user that the program should be run as.booleanisDaemon()Return true if this is a daemon process.booleanReturn true if this process supports I/O streaming back to java.voidremove()Remove the process from the run list, killing the process if it's currently running.voidrestart()Kill the daemon process and let the service restart it.setDaemon(boolean enable) Set if this is a daemon process.Set the group that the program should be run as.voidsetListener(SpawnProcessListener listener) Set the listener to receive lifecycle events from the process.setLogFile(String logFile) Redirect stdout/stderr to the specified file name in the/mnt/logsdirectory.Set the path to the executable.Set the path to the executable.voidsetPriority(int priority) Set the priority of the process.setStreaming(boolean enable) Enable I/O streaming for this process.Set the user (and group) that the program should be run as.setWorkingDir(File dir) Set the working directory.setWorkingDir(String path) Set the working directory.toString()booleanwaitForStart(long timeout) Wait for the process to start.
-
Field Details
-
MAX_PATH_LEN
public static final int MAX_PATH_LEN- See Also:
-
MAX_USER_GROUP_LEN
public static final int MAX_USER_GROUP_LEN- See Also:
-
MIN_PRIORITY
public static final int MIN_PRIORITY- See Also:
-
MAX_PRIORITY
public static final int MAX_PRIORITY- See Also:
-
-
Constructor Details
-
SpawnProcess
public SpawnProcess()Create a newSpawnProcess.- Since:
- 1
-
-
Method Details
-
isDaemon
public boolean isDaemon()Return true if this is a daemon process. Daemon processes are long running and will be automatically restarted if they crash.- Since:
- 10
-
setDaemon
Set if this is a daemon process. A daemon process will auto-restart if it crashes and will continue running until stopped via the service. A daemon process is inherently headless, meaning it cannot stream I/O.Cannot be changed after the process is started.
- Parameters:
enable- if true, process will be a daemon process- Since:
- 10
-
isStreaming
public boolean isStreaming()Return true if this process supports I/O streaming back to java. Streaming is disabled by default. Daemon processes are don't allow streaming, and streaming will be set to false when the process is started.- Since:
- 10
-
setStreaming
Enable I/O streaming for this process. This allows java applications to write to stdin of the application and read stdout / stderr. This works even in multi-node environments where the spawner may be on a different node. Daemon processes don't support I/O streaming and this flag will be set false when the daemon process starts.If streaming is enabled and a log file is specified, stdout/stderr will be directed to the log file. In this case the stdout/stderr input streams will be null. It is still possible to write stdout to the application however.
Cannot be changed after the process is started.
- Parameters:
enable- if true, enable I/O streaming support- Since:
- 10
-
setPath
Set the path to the executable.Cannot be changed after the process is started.
- Parameters:
file- the path to the executable- Since:
- 1
-
setPath
Set the path to the executable.Cannot be changed after the process is started.
- Parameters:
path- path to the executable- Since:
- 1
-
setWorkingDir
Set the working directory.Cannot be changed after the process is started.
- Parameters:
dir- the working directory- Since:
- 1
-
setWorkingDir
Set the working directory.Cannot be changed after the process is started.
- Parameters:
path- path to the working directory- Since:
- 1
-
setLogFile
Redirect stdout/stderr to the specified file name in the/mnt/logsdirectory. The file must be a valid filename. If a path is specified, it will be stripped off and only the final filename will be used. When set, this file will be created in the log directory and will be subject to standard log processing processes.If a log file is specified, I/O streaming of stdout/stderr is disabled.
Cannot be changed after the process is started.
- Parameters:
logFile- the name of the log file- Since:
- 1
-
getUser
Return the user that the program should be run as.- Returns:
- the desired user for the program
- Since:
- 1
-
setUser
Set the user (and group) that the program should be run as. This will lookup the specified user and switch to the associated uid and default gid for the user. If this user doesn't exist, the program will fail to spawn. Leave unset or set to null to run as the same user as the adapter (typically root).Cannot be changed after the process is started.
- Parameters:
user- the user used to run the program- Since:
- 1
-
getGroup
Return the group that the program should be run as.- Returns:
- the desired group for the program
- Since:
- 1
-
setGroup
Set the group that the program should be run as. If setUser() was called, this will already set the group to the default group for the user. Use this to switch the user to another non-default group. If the group doesn't exist, the program will fail to spawn.Cannot be changed after the process is started.
- Parameters:
group- the group used to run the program- Since:
- 1
-
getListener
Return the listener attached to the process.- Since:
- 10
-
setListener
Set the listener to receive lifecycle events from the process.- Parameters:
listener- the listener to attach- Since:
- 10
-
addArg
Add a command line argument.Cannot be changed after the process is started.
- Parameters:
arg- the argument to add- Since:
- 1
-
setPriority
public void setPriority(int priority) Set the priority of the process. This can only be called until the process is created. After this you must use SpawnService.setPriority().- Parameters:
priority- the priority of the process -20..19 (unix semantics)- Since:
- 1
-
getExitStatus
Return the exit status of the process. If the process is a daemon, it will only be set until process is restarted. Alternately, attach a listener to the process to receive exit callbacks with the exit status information.- Since:
- 10
-
remove
public void remove()Remove the process from the run list, killing the process if it's currently running. This is typically used to remove a daemon process fromSpawnService. This is equivalent to callingSpawnService.removeProcess().- Since:
- 10
-
restart
public void restart()Kill the daemon process and let the service restart it. This can be an effective way to reset a daemon process that is not acting correctlyThis only works for daemon processes. This does nothing for non-daemon processes.
- Since:
- 10
-
waitForStart
public boolean waitForStart(long timeout) Wait for the process to start.- Parameters:
timeout- how long to wait- Returns:
- true if started
- Since:
- 1
-
getStdinOutputStream
Return anOutputStreamthat writes data to stdin of the running process. This allows java to write input to running programs. This will return null until the process has been added toSpawnService.Daemon processes don't support I/O streaming. This will return null if the process is a daemon.
- Since:
- 10
-
getStdoutInputStream
Return anInputStreamthat reads from stdout of the running process. This allows java to read output from running programs. This will return null until the process has been added toSpawnService.If the process is configured to output to a log file, streaming I/O is not available and this will return null.
Daemon processes don't support I/O streaming. This will return null if the process is a daemon.
- Since:
- 10
-
getStderrInputStream
Return anInputStreamthat reads from stderr of the running process. This allows java to read output from running programs. This will return null until the process has been added toSpawnService.If the process is configured to output to a log file, streaming I/O is not available and this will return null.
Daemon processes don't support I/O streaming. This will return null if the process is a daemon.
- Since:
- 10
-
toString
-
getPath
-
getWorkingDir
-
getArgs
-
getLogFile
-
getPid
public int getPid() -
getPriority
public int getPriority()
-