- All Implemented Interfaces:
ClientApp
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.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClientAppManagerThe manager notified of the state changes.private final StringThe command line being run.private final I2PAppContextThe app context.private final FileFile the command's errors are written to.private final LogLogger for the shell service.private final FileFile the command's output is written to.private ProcessThe running process, while started.private final ProcessBuilderBuilder launching the external command.private ClientAppStateCurrent state of the service.private static final StringOption naming the service for display.private StringName of the service shown in the console.private static final PatternSplits a command line argument on the equals sign.private StringInternal name of the service.private static final StringOption naming the service internally.private static final StringDirectory the command is looked up in.Constructor Summary
ConstructorsConstructorDescriptionShellService(I2PAppContext context, ClientAppManager listener, String[] args) Creates a ShellService from command-line args, validating the executable and setting up log files.Method Summary
Modifier and TypeMethodDescriptionprivate voidchangeState(ClientAppState newState, String message) Changes the app state and notifies listeners.private voidchangeState(ClientAppState newState, String message, Exception ex) Changes the app state and notifies listeners.The display name of the ClientApp, used in user interfaces.getName()The generic name of the ClientApp, used for registration, e.g.getState()Query the state of managed process and determine if it is running or not.booleanDetermine if the process running or not.booleanDetermine if the process running or not.voidShut down the process by callingProcess.destroy().voidstartup()Determine if a ShellService corresponding to the wrapped application has been started yet.Extract the app process arguments, filtering out -shellservice options.
Field Details
NAME_OPTION
Option naming the service internally.- See Also:
DISPLAY_NAME_OPTION
Option naming the service for display.- See Also:
PLUGIN_DIR
Directory the command is looked up in.- See Also:
EQUALS_SPLIT
Splits a command line argument on the equals sign._log
Logger for the shell service._pb
Builder launching the external command._context
The app context._cmgr
The manager notified of the state changes._commandPath
The command line being run._errorLog
File the command's errors are written to._outputLog
File the command's output is written to._state
Current state of the service.name
Internal name of the service.displayName
Name of the service shown in the console._p
The running process, while started.
Constructor Details
ShellService
Creates a ShellService from command-line args, validating the executable and setting up log files.- Parameters:
context- the application context supplying the log managerlistener- the client app manager to notify of this app's state changesargs- the command line arguments: the executable path first, then the arguments to pass to that executable
Method Details
trimArgs
changeState
Changes the app state and notifies listeners.- Parameters:
newState- the new statemessage- the message for the listenersex- the exception, null if none
changeState
Changes the app state and notifies listeners.- Parameters:
newState- the new statemessage- the message for the listeners
startup
isProcessStopped
public boolean isProcessStopped()Determine if the process running or not.- Returns:
trueif the Process is NOT running,falseif the Process is running
isProcessRunning
public boolean isProcessRunning()Determine if the process running or not.- Returns:
trueif the Process is running,falseif the Process is not running
shutdown
getState
Query the state of managed process and determine if it is running or not. Convert to corresponding ClientAppState and return the correct value.getName
getDisplayName
The display name of the ClientApp, used in user interfaces. The app must translate.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- non-null