net.i2p.router.web

## Class ShellService

- java.lang.Object
- - net.i2p.router.web.ShellService

- All Implemented Interfaces:
    ClientApp

      public class ShellService
      extends Object
      implements ClientApp

  Alternative to ShellCommand for plugins based on ProcessBuilder, which manages a process and keeps track of it's state by maintaining a Process object. Keeps track of the process, and reports start/stop status correctly on configplugins. When running a ShellService from a clients.config file, the user MUST pass -shellservice.name in the args field in clients.config to override the plugin name. The name passed to -shellservice.name should be unique to avoid causing issues. (https://i2pgit.org/i2p-hackers/i2p.i2p/-/merge_requests/39#note_4234) -shellservice.displayName is optional and configures the name of the plugin which is shown on the console. In most cases, the -shellservice.name must be the same as the plugin name in order for the $PLUGIN field in clients.config to match the expected value. If this is not the case, i.e. (-shellservice.name != plugin.name), you must not use $PLUGIN in your clients.config file. The recommended way to use this tool is to manage a single forked app/process, with a single ShellService, in a single plugin. When you are writing your clients.config file, please take note that $PLUGIN will be derived from the `shellservice.name` field in the config file args. Works on Windows, OSX, and Linux.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShellService(I2PAppContext context, ClientAppManager listener, String[] args)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getDisplayName()` The display name of the ClientApp, used in user interfaces.
    `String` | `getName()` The generic name of the ClientApp, used for registration, e.g.
    `ClientAppState` | `getState()` Query the state of managed process and determine if it is running or not.
    `boolean` | `isProcessRunning()` Determine if the process running or not.
    `boolean` | `isProcessStopped()` Determine if the process running or not.
    `void` | `shutdown(String[] args)` Shut down the process by calling Process.destroy()
    `void` | `startup()` Determine if a ShellService corresponding to the wrapped application has been started yet.

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

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

- - ### Constructor Detail

    - #### ShellService

          public ShellService(I2PAppContext context,
                              ClientAppManager listener,
                              String[] args)

  - ### Method Detail

    - #### getDisplayName

          public String getDisplayName()

      The display name of the ClientApp, used in user interfaces. The app must translate.
      Specified by:
        `getDisplayName` in interface `ClientApp`
      Returns:
        non-null

    - #### getName

          public String getName()

      The generic name of the ClientApp, used for registration, e.g. "console". Do not translate. Has a special use in the context of ShellService, must match the plugin name.
      Specified by:
        `getName` in interface `ClientApp`
      Returns:
        non-null

    - #### getState

          public ClientAppState getState()

      Query the state of managed process and determine if it is running or not. Convert to corresponding ClientAppState and return the correct value.
      Specified by:
        `getState` in interface `ClientApp`
      Returns:
        non-null

    - #### isProcessRunning

          public boolean isProcessRunning()

      Determine if the process running or not.
      Returns:
        `true` if the Process is running, `false` if the Process is not running

    - #### isProcessStopped

          public boolean isProcessStopped()

      Determine if the process running or not.
      Returns:
        `true` if the Process is NOT running, `false` if the Process is running

    - #### shutdown

          public void shutdown(String[] args)
                        throws Throwable

      Shut down the process by calling Process.destroy()
      Specified by:
        `shutdown` in interface `ClientApp`
      Parameters:
        `args` - generally null but could be stopArgs from clients.config
      Throws:
        `Throwable` - on shutdown failure

    - #### startup

          public void startup()
                       throws Throwable

      Determine if a ShellService corresponding to the wrapped application has been started yet. If it hasn't, attempt to start the process and notify the router that it has been started.
      Specified by:
        `startup` in interface `ClientApp`
      Throws:
        `Throwable` - on startup failure