Package de.gebit.integrity.runner.forking

## 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

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Process` | `process` | The OS process encapsulated.

  - ### 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
    --- | --- | ---
    `InputStream` | `getErrorStream()` | Returns the stream carrying standard error (STDERR) of the process.
    `String` | `getHost()` | Returns the network host name where this process is running.
    `InputStream` | `getInputStream()` | Returns the stream carrying standard output (STDOUT) of the process.
    `int` | `getPort()` | Returns the port where this processes' Integrity Test Runner is open for management connections.
    `boolean` | `isAlive()` | Checks whether the forked process is up and running.
    `void` | `kill()` | 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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: `ForkedProcess`
      Checks whether the forked process is up and running. This is a mandatory method.
      Specified by:
        `isAlive` in interface `ForkedProcess`
      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: `ForkedProcess`
      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. 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:
        `kill` in interface `ForkedProcess`

    - #### getInputStream

          public InputStream getInputStream()

      Description copied from interface: `ForkedProcess`
      Returns the stream carrying standard output (STDOUT) of the process. Supporting this kind of communication is optional.
      Specified by:
        `getInputStream` in interface `ForkedProcess`
      Returns:
        a ready-to-be-read `InputStream` or null if this is not supported by the forked process

    - #### getErrorStream

          public InputStream getErrorStream()

      Description copied from interface: `ForkedProcess`
      Returns the stream carrying standard error (STDERR) of the process. Supporting this kind of communication is optional.
      Specified by:
        `getErrorStream` in interface `ForkedProcess`
      Returns:
        a ready-to-be-read `InputStream` or null if this is not supported by the forked process

    - #### getHost

          public String getHost()

      Description copied from interface: `ForkedProcess`
      Returns 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:
        `getHost` in interface `ForkedProcess`
      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: `ForkedProcess`
      Returns 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. If `ForkedProcess.getHost()` returns a non-null value, this method must return a meaningful value as well (it will also not be called before `ForkedProcess.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:
        `getPort` in interface `ForkedProcess`
      Returns:
        the remoting port of the test runner