java.lang.Object
net.i2p.router.startup.ClientAppConfig

public class ClientAppConfigextends Object
Contains a really simple ClientApp "structure" and some static methods so they can be used both by LoadClientAppsJob and by the configuration page in the router console.

clients.config format:

Lines are of the form clientApp.x.prop=val, where x is the app number.
App numbers MUST start with 0 and be consecutive.

Properties are as follows:
main: Full class name. Required. The main() method in this
      class will be run.
name: Name to be displayed on console.
args: Arguments to the main class, separated by spaces or tabs.
      Arguments containing spaces or tabs may be quoted with ' or "
delay: Seconds before starting, default 120
onBoot: {true|false}, default false, forces a delay of 0,
        overrides delay setting
startOnLoad: {true|false} Is the client to be run at all?
                   Default true

The following additional properties are used only by plugins:
stopargs: Arguments to stop the client.
uninstallargs: Arguments to stop the client.
classpath: Additional classpath elements for the client,
           separated by commas.

The following substitutions are made in the args, stopargs,
uninstallargs, and classpath lines, for plugins only:
$I2P: The base I2P install directory
$CONFIG: The user's configuration directory (e.g. ~/.i2p)
$PLUGIN: This plugin's directory (e.g. ~/.i2p/plugins/foo)

All properties except "main" are optional.
Lines starting with "#" are comments.

If the delay is less than zero, the client is run immediately,
in the same thread, so that exceptions may be propagated to the console.
In this case, the client should either throw an exception, return quickly,
or spawn its own thread.
If the delay is greater than or equal to zero, it will be run
in a new thread, and exceptions will be logged but not propagated
to the console.
  • Field Details

    • DEFAULT_STARTUP_DELAY

      private static final long DEFAULT_STARTUP_DELAY
      Wait 15s before starting up non-boot client apps.
      See Also:
    • PROP_CLIENT_CONFIG_FILENAME

      private static final String PROP_CLIENT_CONFIG_FILENAME
      Property naming the client config file.
      See Also:
    • DEFAULT_CLIENT_CONFIG_FILENAME

      private static final String DEFAULT_CLIENT_CONFIG_FILENAME
      Default name of the client config file.
      See Also:
    • CLIENT_CONFIG_DIR

      private static final String CLIENT_CONFIG_DIR
      Directory of drop-in client config fragments.
      See Also:
    • PREFIX

      private static final String PREFIX
      Prefix of every client app property.
      See Also:
    • className

      public String className
      The main class name. This and the three fields below may be edited in the router console.
    • clientName

      public String clientName
      The display name.
    • args

      public String args
      The arguments.
    • disabled

      public boolean disabled
      Whether disabled.
    • delay

      public final long delay
      The startup delay.
    • classpath

      public final String classpath
      The classpath.
    • stopargs

      public final String stopargs
      The stop arguments.
    • uninstallargs

      public final String uninstallargs
      The uninstall arguments.
    • configFile

      File configFile
      The config file.
  • Constructor Details

    • ClientAppConfig

      public ClientAppConfig(String cl, String client, String a, long d, boolean dis)
      Create a new ClientAppConfig.
      Parameters:
      cl - the class name
      client - the display name
      a - the startup argument string handed to the client
      d - the startup delay in ms
      dis - true to keep the app from starting with the router
    • ClientAppConfig

      public ClientAppConfig(String cl, String client, String a, long d, boolean dis, String cp, String sa, String ua)
      Create a new ClientAppConfig with all fields.
      Parameters:
      cl - the class name
      client - the display name
      a - the startup argument string handed to the client
      d - the startup delay in ms
      dis - true to keep the app from starting with the router
      cp - extra classpath entries for the client's class loader, or null
      sa - the stop arguments
      ua - the uninstall arguments
  • Method Details

    • isSplitConfig

      public static boolean isSplitConfig(I2PAppContext ctx)
      Only valid for the router's clients (not plugins). Only valid after getClientApps(ctx) has been called.
      Parameters:
      ctx - the I2P app context
      Returns:
      true if split config
    • configFile

      public static File configFile(I2PAppContext ctx)
      This is the old config file. Only valid if not a split config.
      Parameters:
      ctx - the I2P app context
      Returns:
      the config file
    • configDir

      public static File configDir(I2PAppContext ctx)
      This is the config dir. Only valid if a split config.
      Parameters:
      ctx - the I2P app context
      Returns:
      the config directory
    • getClientApps

      public static List<ClientAppConfig> getClientApps(RouterContext ctx)
      Go through the files, and return a List of ClientAppConfig structures This is for the router.
      Parameters:
      ctx - the router context
      Returns:
      the list of client app configs
    • getClientApps

      public static List<ClientAppConfig> getClientApps(File cfgFile) throws IOException
      Go through the file, and return a List of ClientAppConfig structures.
      Parameters:
      cfgFile - the config file to read
      Returns:
      the list of client app configs
      Throws:
      IOException - if the file cannot be read
    • migrate

      private static boolean migrate(I2PAppContext ctx, List<ClientAppConfig> apps, File from, File dir)
      Copies the app configs from the old file to individual files in the new directory.
      Parameters:
      ctx - the app context
      apps - the apps already loaded
      from - the file to copy from
      dir - the directory to copy to
      Returns:
      true if any config moved
    • getClientApps

      private static List<ClientAppConfig> getClientApps(Properties clientApps)
      Reads all the app configs from the properties.
      Parameters:
      clientApps - the properties to read
      Returns:
      the app configs found
    • getClientApp

      private static ClientAppConfig getClientApp(Properties clientApps, String prefix)
      Reads one app config by its key prefix.
      Parameters:
      clientApps - the properties to read
      prefix - the prefix of the app's keys
      Returns:
      the config, null if absent
    • writeClientAppConfig

      public static void writeClientAppConfig(I2PAppContext ctx, ClientAppConfig app) throws IOException
      Classpath and stopargs not supported. All other apps in the file will be deleted. Do not use if multiple apps in a single file - use writeClientAppConfig(ctx, apps). If app.configFile is null, a new file will be created and assigned.
      Parameters:
      ctx - the I2P app context
      app - the client app config to write
      Throws:
      IOException - if the file cannot be written
    • writeClientAppConfig

      public static void writeClientAppConfig(I2PAppContext ctx, List<ClientAppConfig> apps) throws IOException
      Classpath and stopargs not supported. All other apps in the files will be deleted. Do not add apps with this method - use writeClientAppConfig(ctx, app). Do not delete apps with this method - use deleteClientAppConfig(ClientAppConfig).
      Parameters:
      ctx - the I2P app context
      apps - the list of client app configs to write
      Throws:
      IOException - if the file cannot be written
    • writeClientAppConfig

      private static void writeClientAppConfig(List<ClientAppConfig> apps, File cfgFile) throws IOException
      All to a single file, apps.configFile ignored.
      Parameters:
      apps - the client app configs to write, in order
      cfgFile - the single file to write them all to
      Throws:
      IllegalArgumentException - if null cfgFile
      IOException - if the file cannot be written
    • deleteClientAppConfig

      public static boolean deleteClientAppConfig(ClientAppConfig cac) throws IOException
      This works for both split and non-split config. If this is the only config in the file, the file will be deleted; otherwise the file will be saved with the remaining configs.
      Parameters:
      cac - the client app config to delete
      Returns:
      true if the config was removed, leaving the file deleted when it was the last one or rewritten with the remainder otherwise
      Throws:
      IllegalArgumentException - if cac has a null configfile
      IOException - if the file cannot be read or written
    • hashCode

      public int hashCode()
      Hash code based on class name.
      Overrides:
      hashCode in class Object
      Returns:
      whether h code is present
    • equals

      public boolean equals(Object o)
      Matches on class, args, and name only.
      Overrides:
      equals in class Object