Class LocalForkedProcess
- java.lang.Object
-
- de.gebit.integrity.runner.forking.LocalForkedProcess
-
- All Implemented Interfaces:
ForkedProcess
public class LocalForkedProcess extends Object implements ForkedProcess
A forked process implementation that wraps a local process.- Author:
- Rene Schneider - initial API and implementation
-
-
Constructor Summary
Constructors Constructor Description LocalForkedProcess(Process aProcess)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStreamgetErrorStream()Returns the stream carrying standard error (STDERR) of the process.StringgetHost()Returns the network host name where this process is running.InputStreamgetInputStream()Returns the stream carrying standard output (STDOUT) of the process.intgetPort()Returns the port where this processes' Integrity Test Runner is open for management connections.booleanisAlive()Checks whether the forked process is up and running.voidkill()Kills the forked process, if it is running, and waits for it to exit.
This functionality is not strictly required, since a test runner process should always end itself after finishing all its tests, which then leads to the forks automatically exiting gracefully after doing their duty as well.
-
-
-
Field Detail
-
process
protected Process process
The OS process encapsulated.
-
-
Constructor Detail
-
LocalForkedProcess
public LocalForkedProcess(Process aProcess)
Creates a new instance.- Parameters:
aProcess- the process to wrap
-
-
Method Detail
-
isAlive
public boolean isAlive()
Description copied from interface:ForkedProcessChecks whether the forked process is up and running. This is a mandatory method.- Specified by:
isAlivein interfaceForkedProcess- Returns:
- true if the process is running, false if it has ended or not even started (for example due to an error)
-
kill
public void kill()
Description copied from interface:ForkedProcessKills the forked process, if it is running, and waits for it to exit.
This functionality is not strictly required, since a test runner process should always end itself after finishing all its tests, which then leads to the forks automatically exiting gracefully after doing their duty as well. But in case a fork got started, but it is impossible for the main process to create a remoting connection to it, the main process will call this method in order to ensure clean termination of the forked process, which would otherwise sit there forever and wait for its master to connect.- Specified by:
killin interfaceForkedProcess
-
getInputStream
public InputStream getInputStream()
Description copied from interface:ForkedProcessReturns the stream carrying standard output (STDOUT) of the process. Supporting this kind of communication is optional.- Specified by:
getInputStreamin interfaceForkedProcess- Returns:
- a ready-to-be-read
InputStreamor null if this is not supported by the forked process
-
getErrorStream
public InputStream getErrorStream()
Description copied from interface:ForkedProcessReturns the stream carrying standard error (STDERR) of the process. Supporting this kind of communication is optional.- Specified by:
getErrorStreamin interfaceForkedProcess- Returns:
- a ready-to-be-read
InputStreamor null if this is not supported by the forked process
-
getHost
public String getHost()
Description copied from interface:ForkedProcessReturns the network host name where this process is running. In case of local processes, "localhost" shall be returned, but distributed processes on other machines might of course return different values. This is a mandatory method if the forks' STDOUT stream is not available (through which host and port would otherwise be communicated to the master) OR if the host communicated via STDOUT is a wildcard address, otherwise it is optional and will not be called. It may return "null" as long as the fork has not yet brought up its remoting network binding - in that case, the connection attempts are paused until remoting is available.- Specified by:
getHostin interfaceForkedProcess- Returns:
- the network host name where the process is running, or null if the process is not yet available for connection
-
getPort
public int getPort()
Description copied from interface:ForkedProcessReturns the port where this processes' Integrity Test Runner is open for management connections. This is a mandatory method if the forks' STDOUT stream is not available (through which host and port would otherwise be communicated to the master), otherwise it is optional and will not be called. IfForkedProcess.getHost()returns a non-null value, this method must return a meaningful value as well (it will also not be called beforeForkedProcess.getHost()was called and returned a non-null value, so it doesn't matter what it returns before that point in time, or if it is even callable).- Specified by:
getPortin interfaceForkedProcess- Returns:
- the remoting port of the test runner
-
-