Changeset 16a14d4


Ignore:
Timestamp:
Mar 15, 2010 4:19:19 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b397de1
Parents:
c151352
Message:
  • Clients:
    • Negative delay means run immediately and inline
    • Add methods to test class and run inline, to propagate errors to the console
    • Add javadoc for clients.config format
    • Use new methods for plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java

    rc151352 r16a14d4  
    181181     *  @throws just about anything, caller would be wise to catch Throwable
    182182     */
    183     static boolean stopPlugin(RouterContext ctx, String appName) throws IOException {
     183    static boolean stopPlugin(RouterContext ctx, String appName) throws Exception {
    184184        Log log = ctx.logManager().getLog(PluginStarter.class);
    185185        File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);
     
    229229
    230230    /** @return true on success - caller should call stopPlugin() first */
    231     static boolean deletePlugin(RouterContext ctx, String appName) throws IOException {
     231    static boolean deletePlugin(RouterContext ctx, String appName) throws Exception {
    232232        Log log = ctx.logManager().getLog(PluginStarter.class);
    233233        File pluginDir = new File(ctx.getAppDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);
     
    349349    }
    350350
    351     /** @param action "start" or "stop" or "uninstall" */
    352     private static void runClientApps(RouterContext ctx, File pluginDir, List<ClientAppConfig> apps, String action) {
     351    /**
     352     *  @param action "start" or "stop" or "uninstall"
     353     *  @throws just about anything if an app has a delay less than zero, caller would be wise to catch Throwable
     354     *  If no apps have a delay less than zero, it shouldn't throw anything
     355     */
     356    private static void runClientApps(RouterContext ctx, File pluginDir, List<ClientAppConfig> apps, String action) throws Exception {
    353357        Log log = ctx.logManager().getLog(PluginStarter.class);
    354358        for(ClientAppConfig app : apps) {
     
    389393                addToClasspath(cp, app.clientName, log);
    390394            }
    391             if (app.delay == 0 || !action.equals("start")) {
     395
     396            if (app.delay < 0 && action.equals("start")) {
     397                // this will throw exceptions
     398                LoadClientAppsJob.runClientInline(app.className, app.clientName, argVal, log);
     399            } else if (app.delay == 0 || !action.equals("start")) {
     400                // quick check, will throw ClassNotFoundException on error
     401                LoadClientAppsJob.testClient(app.className);
    392402                // run this guy now
    393403                LoadClientAppsJob.runClient(app.className, app.clientName, argVal, log);
    394404            } else {
     405                // quick check, will throw ClassNotFoundException on error
     406                LoadClientAppsJob.testClient(app.className);
    395407                // wait before firing it up
    396408                ctx.jobQueue().addJob(new LoadClientAppsJob.DelayedRunClient(ctx, app.className, app.clientName, argVal, app.delay));
  • router/java/src/net/i2p/router/startup/ClientAppConfig.java

    rc151352 r16a14d4  
    1919 * page in the router console.
    2020 *
     21 * <pre>
     22 *
     23 * clients.config format:
     24 *
     25 * Lines are of the form clientApp.x.prop=val, where x is the app number.
     26 * App numbers MUST start with 0 and be consecutive.
     27 *
     28 * Properties are as follows:
     29 *      main: Full class name. Required. The main() method in this
     30 *            class will be run.
     31 *      name: Name to be displayed on console.
     32 *      args: Arguments to the main class, separated by spaces or tabs.
     33 *            Arguments containing spaces or tabs may be quoted with ' or "
     34 *      delay: Seconds before starting, default 120
     35 *      onBoot: {true|false}, default false, forces a delay of 0,
     36 *              overrides delay setting
     37 *      startOnLoad: {true|false} Is the client to be run at all?
     38 *                    Default true
     39 *
     40 * The following additional properties are used only by plugins:
     41 *      stopargs: Arguments to stop the client.
     42 *      uninstallargs: Arguments to stop the client.
     43 *      classpath: Additional classpath elements for the client,
     44 *                 separated by commas.
     45 *
     46 * The following substitutions are made in the args, stopargs,
     47 * uninstallargs, and classpath lines, for plugins only:
     48 *      $I2P: The base I2P install directory
     49 *      $CONFIG: The user's configuration directory (e.g. ~/.i2p)
     50 *      $PLUGIN: This plugin's directory (e.g. ~/.i2p/plugins/foo)
     51 *
     52 * All properties except "main" are optional.
     53 * Lines starting with "#" are comments.
     54 *
     55 * If the delay is less than zero, the client is run immediately,
     56 * in the same thread, so that exceptions may be propagated to the console.
     57 * In this case, the client should either throw an exception, return quickly,
     58 * or spawn its own thread.
     59 * If the delay is greater than or equal to zero, it will be run
     60 * in a new thread, and exceptions will be logged but not propagated
     61 * to the console.
     62 *
     63 * </pre>
    2164 */
    2265public class ClientAppConfig {
  • router/java/src/net/i2p/router/startup/LoadClientAppsJob.java

    rc151352 r16a14d4  
    1212
    1313/**
    14  * Run any client applications specified in the router.config.  If any clientApp
     14 * Run any client applications specified in clients.config.  If any clientApp
    1515 * contains the config property ".onBoot=true" it'll be launched immediately, otherwise
    1616 * it'll get queued up for starting 2 minutes later.
     
    4141                continue;
    4242            String argVal[] = parseArgs(app.args);
    43             if (app.delay == 0) {
     43            if (app.delay <= 0) {
    4444                // run this guy now
    4545                runClient(app.className, app.clientName, argVal, _log);
     
    119119    }
    120120
     121    /**
     122     *  Use to test if the class is present,
     123     *  to propagate an error back to the user,
     124     *  since runClient() runs in a separate thread.
     125     *
     126     *  @since 0.7.13
     127     */
     128    public static void testClient(String className) throws ClassNotFoundException {
     129        Class.forName(className);
     130    }
     131
     132    /**
     133     *  Run client in this thread.
     134     *
     135     *  @throws just about anything, caller would be wise to catch Throwable
     136     *  @since 0.7.13
     137     */
     138    public static void runClientInline(String className, String clientName, String args[], Log log) throws Exception {
     139        if (log.shouldLog(Log.INFO))
     140            log.info("Loading up the client application " + clientName + ": " + className + " " + Arrays.toString(args));
     141        if (args == null)
     142            args = new String[0];
     143        Class cls = Class.forName(className);
     144        Method method = cls.getMethod("main", new Class[] { String[].class });
     145        method.invoke(cls, new Object[] { args });
     146    }
     147
     148    /**
     149     *  Run client in a new thread.
     150     */
    121151    public static void runClient(String className, String clientName, String args[], Log log) {
    122152        if (log.shouldLog(Log.INFO))
Note: See TracChangeset for help on using the changeset viewer.