karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jamie G." <jamie.goody...@gmail.com>
Subject Re: svn commit: r1372333 - in /karaf/trunk: main/src/main/java/org/apache/karaf/main/ shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/
Date Mon, 13 Aug 2012 10:57:25 GMT
-1 This behaviour was discussed on the dev list to not be made default.

On Mon, Aug 13, 2012 at 6:40 AM,  <cschneider@apache.org> wrote:
> Author: cschneider
> Date: Mon Aug 13 09:10:22 2012
> New Revision: 1372333
>
> URL: http://svn.apache.org/viewvc?rev=1372333&view=rev
> Log:
> KARAF-1640: Adding option to start console delayed. Showing some stats when console comes
up
>
> Modified:
>     karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
>     karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java
>     karaf/trunk/main/src/main/java/org/apache/karaf/main/StartupListener.java
>     karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/DelayedStarted.java
>     karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java
>
> Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java?rev=1372333&r1=1372332&r2=1372333&view=diff
> ==============================================================================
> --- karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java (original)
> +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/ConfigProperties.java Mon Aug
13 09:10:22 2012
> @@ -113,6 +113,10 @@ public class ConfigProperties {
>      private static final String KARAF_SHUTDOWN_COMMAND = "karaf.shutdown.command";
>
>      private static final String KARAF_SHUTDOWN_PID_FILE = "karaf.shutdown.pid.file";
> +
> +    private static final String KARAF_STARTUP_MESSAGE = "karaf.startup.message";
> +
> +    private static final String KARAF_DELAY_CONSOLE = "karaf.delay.console";
>
>      private static final String DEFAULT_SHUTDOWN_COMMAND = "SHUTDOWN";
>
> @@ -120,7 +124,7 @@ public class ConfigProperties {
>
>      private static final String SECURITY_PROVIDERS = "org.apache.karaf.security.providers";
>
> -    private static final String KARAF_STARTUP_MESSAGE = "karaf.startup.message";
> +
>
>      /**
>       * If a lock should be used before starting the runtime
> @@ -154,6 +158,7 @@ public class ConfigProperties {
>      String optionals;
>      File etcFolder;
>      String startupMessage;
> +    boolean delayConsoleStart;
>
>      public ConfigProperties() throws Exception {
>          this.karafHome = Utils.getKarafHome(ConfigProperties.class, PROP_KARAF_HOME,
ENV_KARAF_HOME);
> @@ -206,6 +211,8 @@ public class ConfigProperties {
>          this.portFile = props.getProperty(KARAF_SHUTDOWN_PORT_FILE);
>          this.shutdownCommand = props.getProperty(KARAF_SHUTDOWN_COMMAND, DEFAULT_SHUTDOWN_COMMAND);
>          this.startupMessage = props.getProperty(KARAF_STARTUP_MESSAGE, "Apache Karaf
starting up. Press Enter to open the shell now...");
> +        this.delayConsoleStart = Boolean.parseBoolean(props.getProperty(KARAF_DELAY_CONSOLE,
"true"));
> +        System.setProperty(KARAF_DELAY_CONSOLE, new Boolean(this.delayConsoleStart).toString());
>      }
>
>      private String getProperyOrFail(String propertyName) {
>
> Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java?rev=1372333&r1=1372332&r2=1372333&view=diff
> ==============================================================================
> --- karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java (original)
> +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/Main.java Mon Aug 13 09:10:22
2012
> @@ -210,7 +210,9 @@ public class Main {
>
>      public void launch() throws Exception {
>          config = new ConfigProperties();
> -        System.out.println(config.startupMessage);
> +        if (config.delayConsoleStart) {
> +            System.out.println(config.startupMessage);
> +        }
>          BootstrapLogManager.setProperties(config.props);
>          Lock lock = createLock();
>          lockManager = new LockManager(lock, new KarafLockCallback(), config.lockDelay);
> @@ -252,7 +254,9 @@ public class Main {
>
>          setStartLevel(config.lockStartLevel);
>          // Progress bar
> -        new StartupListener(framework.getBundleContext());
> +        if (config.delayConsoleStart) {
> +            new StartupListener(LOG, framework.getBundleContext());
> +        }
>          lockManager.startLockMonitor();
>      }
>
>
> Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/StartupListener.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/StartupListener.java?rev=1372333&r1=1372332&r2=1372333&view=diff
> ==============================================================================
> --- karaf/trunk/main/src/main/java/org/apache/karaf/main/StartupListener.java (original)
> +++ karaf/trunk/main/src/main/java/org/apache/karaf/main/StartupListener.java Mon Aug
13 09:10:22 2012
> @@ -1,5 +1,7 @@
>  package org.apache.karaf.main;
>
> +import java.util.logging.Logger;
> +
>  import org.osgi.framework.Bundle;
>  import org.osgi.framework.BundleContext;
>  import org.osgi.framework.BundleEvent;
> @@ -10,20 +12,29 @@ import org.osgi.framework.SynchronousBun
>  import org.osgi.framework.startlevel.FrameworkStartLevel;
>
>  /**
> - * Watches the startup of the framework and displays a progress bar of the number of
bundles started / total.
> - * The listener will remove itself after the desired start level is reached or the system
property karaf.console.started is set to
> - * true.
> + * Watches the startup of the framework and displays a progress bar of the
> + * number of bundles started / total. The listener will remove itself after the
> + * desired start level is reached or the system property karaf.console.started
> + * is set to true.
>   */
>  class StartupListener implements FrameworkListener, SynchronousBundleListener {
> +    private Logger log;
>      private static final String SYSTEM_PROP_KARAF_CONSOLE_STARTED = "karaf.console.started";
> +    private long startTime;
> +    private int currentPercentage;
> +
> +    private final BundleContext context;
>
> -       private final BundleContext context;
> -    StartupListener(BundleContext context) {
> +    StartupListener(Logger log, BundleContext context) {
> +        this.log = log;
>          this.context = context;
> +        this.currentPercentage = 0;
> +        this.startTime = System.currentTimeMillis();
>          context.addBundleListener(this);
>          context.addFrameworkListener(this);
>      }
> -    public synchronized void bundleChanged(BundleEvent bundleEvent) {
> +
> +    public BundleStats getBundleStats() {
>          Bundle[] bundles = context.getBundles();
>          int numActive = 0;
>          int numBundles = bundles.length;
> @@ -31,42 +42,76 @@ class StartupListener implements Framewo
>              if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) {
>                  numBundles--;
>              } else if (bundle.getState() == Bundle.ACTIVE) {
> -                numActive ++;
> +                numActive++;
>              }
>          }
> -        boolean started = Boolean.parseBoolean(System.getProperty(SYSTEM_PROP_KARAF_CONSOLE_STARTED,
"false"));
> -        if (!started) {
> -            showProgressBar(numActive, numBundles);
> +        BundleStats stats = new BundleStats();
> +        stats.numActive = numActive;
> +        stats.numTotal = numBundles;
> +        return stats;
> +    }
> +
> +    public synchronized void bundleChanged(BundleEvent bundleEvent) {
> +        BundleStats stats = getBundleStats();
> +        if (!isConsoleStarted()) {
> +            showProgressBar(stats.numActive, stats.numTotal);
>          }
>      }
> +
> +    private boolean isConsoleStarted() {
> +        return Boolean.parseBoolean(System.getProperty(SYSTEM_PROP_KARAF_CONSOLE_STARTED,
"false"));
> +    }
> +
>      public synchronized void frameworkEvent(FrameworkEvent frameworkEvent) {
>          if (frameworkEvent.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
> -            int defStartLevel = Integer.parseInt(System.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
> -            int startLevel = context.getBundle(0).adapt(FrameworkStartLevel.class).getStartLevel();
> +            int defStartLevel = Integer.parseInt(System
> +                    .getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
> +            int startLevel = context.getBundle(0)
> +                    .adapt(FrameworkStartLevel.class).getStartLevel();
>              if (startLevel >= defStartLevel) {
>                  context.removeBundleListener(this);
>                  context.removeFrameworkListener(this);
> +                long startTimeSeconds = (System.currentTimeMillis() - this.startTime)
/ 1000;
> +                BundleStats stats = getBundleStats();
> +                String message = "Karaf started in " + startTimeSeconds + "s. Bundle
stats: " + stats.numActive
> +                        + " active , " + stats.numTotal + " total";
> +                log.info(message);
> +                if (!isConsoleStarted()) {
> +                    showProgressBar(100, 100);
> +                    System.out.println(message);
> +                }
> +
>              }
>          }
>      }
> +
>      public void showProgressBar(int done, int total) {
>          int percent = (done * 100) / total;
> -        StringBuilder sb = new StringBuilder();
> -        sb.append(String.format("\r%3d%% [", percent));
> -        for (int i = 0; i < 100; i++) {
> -            if (i < percent) {
> -                sb.append('=');
> -            } else if (i == percent) {
> -                sb.append('>');
> -            } else {
> -                sb.append(' ');
> +        // Make sure we do not go backwards with percentage
> +        if (percent > currentPercentage) {
> +            currentPercentage = percent;
> +            StringBuilder sb = new StringBuilder();
> +            sb.append(String.format("\r%3d%% [", percent));
> +            for (int i = 0; i < 100; i++) {
> +                if (i < percent) {
> +                    sb.append('=');
> +                } else if (i == percent) {
> +                    sb.append('>');
> +                } else {
> +                    sb.append(' ');
> +                }
>              }
> +            sb.append(']');
> +            System.out.print(sb.toString());
> +            System.out.flush();
>          }
> -        sb.append(']');
> -        System.out.print(sb.toString());
> -        System.out.flush();
>          if (done == total) {
>              System.out.println();
>          }
>      }
> +
> +    class BundleStats {
> +        int numActive;
> +        int numTotal;
> +    }
>  }
> \ No newline at end of file
>
> Modified: karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/DelayedStarted.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/DelayedStarted.java?rev=1372333&r1=1372332&r2=1372333&view=diff
> ==============================================================================
> --- karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/DelayedStarted.java
(original)
> +++ karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/DelayedStarted.java
Mon Aug 13 09:10:22 2012
> @@ -55,8 +55,6 @@ class DelayedStarted extends Thread impl
>
>          // Signal to the main module that it can stop displaying the startup progress
>          System.setProperty(SYSTEM_PROP_KARAF_CONSOLE_STARTED, "true");
> -
> -        System.out.println();
>          this.bundleContext.removeFrameworkListener(this);
>          console.run();
>      }
>
> Modified: karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java
> URL: http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java?rev=1372333&r1=1372332&r2=1372333&view=diff
> ==============================================================================
> --- karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java
(original)
> +++ karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java
Mon Aug 13 09:10:22 2012
> @@ -88,14 +88,20 @@ public class LocalConsoleManager {
>          String agentId = startAgent("karaf");
>          this.console = consoleFactory.createLocal(this.commandProcessor, terminal, callback);
>          this.console.getSession().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentId);
> -        DelayedStarted watcher = new DelayedStarted(new Runnable() {
> -
> -            @Override
> +
> +        Runnable consoleStarter = new Runnable() {
>              public void run() {
>                  consoleFactory.startConsoleAs(console, subject);
>              }
> -        }, bundleContext, System.in);
> -        new Thread(watcher).start();
> +        };
> +
> +        boolean delayconsole = Boolean.parseBoolean(System.getProperty("karaf.delay.console"));
> +        if (delayconsole) {
> +            DelayedStarted watcher = new DelayedStarted(consoleStarter, bundleContext,
System.in);
> +            new Thread(watcher).start();
> +        } else {
> +            consoleStarter.run();
> +        }
>      }
>
>      protected String startAgent(String user) {
>
>

Mime
View raw message