public class ProcessWrapper extends Object
ProcessWrapper is used by Silver Fabric as a wrapper around the java.lang.Process class, with the purpose of
providing convenience methods and additional functionality (sometimes in a platform specific manner), including:
There are two contexts in which an enabler developer might use a ProcessWrapper object. The first is in referencing and
acting on either ExecContainer's primary process or its shutdown process. These are available via the
ExecContainer.getProcess() and ExecContainer.getShutdownProcess() methods, respectively. The basic assumption here is
that in the simple case, an enabler will manage a single process and will require one additional process to shutdown the first. The
primary ProcessWrapper is created when the enabler startup command is executed, and the shutdown
ProcessWrapper is created when enabler shutdown is called.
The second context which might be useful in enabler development is when some "extra" process must be run by the enabler.
ProcessWrapper can be used to wrap a short lived task or manage an additional long running process. In either of
these cases, one of the factory methods provided by ExecContainer should be used to obtain a ProcessWrapper instance. The
recommended form to use is
getProcessWrapper(String execString, File targetDir, String pidFilename).
The pidFilename parameter is currently used for forced process killing on windows only. (In the case that the enabler is running on
some other platform, the pidFilename parameter is ignored.) On windows, the way that it is used is as follows: a
native binary "wrappid.exe" is used to actually execute the process to be run. This binary outputs its own pid to the specified
file in the target directory. Then, if a wrapped process fails to stop gracefully on its own, the ProcessWrapper.destroy() method can be
called. When this happens, the pid is passed to a second native binary "endprocess.exe", which walks the process tree and kills the
process and its children.
ExecContainer| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Destroy the wrapped process, issuing a force kill if available.
|
void |
exec()
Execute the specified process
|
File |
getPidFile()
Get the pid file used by useEndProcess()
|
Process |
getProcess()
Get the underlying
java.lang.Process used by this
ProcessWrapper |
boolean |
isRunning()
If the process is running
|
void |
setPidFile(File pidFile)
Specify the pid file used by useEndProcess()
|
void |
useEndProcessCommand(String wrapProcessCmd,
String endProcessCmd,
File pidFile)
Specify a command to run to forcefully kill the process if it is still
running when destroy() is called.
|
public void exec()
throws IOException
IOExceptionpublic void destroy()
throws Exception
Exceptionpublic void useEndProcessCommand(String wrapProcessCmd, String endProcessCmd, File pidFile)
endProcessCmd - the full path of the external program to be run to end the processpidFile - a text file containing only the pid of the process to be killedpublic File getPidFile()
public void setPidFile(File pidFile)
pidFile - a text file containing only the pid of the process to be killedpublic boolean isRunning()
public Process getProcess()
java.lang.Process used by this
ProcessWrapperCopyright © 2014 TIBCO Software, Inc. All Rights Reserved.