Yeah, I understand that the user can break the wait loop by typing enter, but my point is that there are cases where bundles may not be resolved or started and I don't think we should consider those as errors. If a bundle has been marked as being stopped (using bundle:stop xxx), the console will never show up after a restart.
So a better way would be to check for the start level and wait until the start level is up to the final state (which can be found in etc/config.properties iirc). That would ensure that any problems (or any stopped bundle) would still end up showing the console. On Mon, Jul 23, 2012 at 4:40 PM, Christian Schneider < [email protected]> wrote: > The code waits for input in parallel. So if the user types enter he can > get a console at any time. I did not change the start level of console to > allow for that early access. > > Christian > > Am 23.07.2012 16:14, schrieb Guillaume Nodet: > > Won't that change forbid to start the console if any bundle is in error >> somehow ? >> So if a user installs a bundle which can not start, he can't debug >> anymore ? >> >> On Mon, Jul 23, 2012 at 4:10 PM, <[email protected]> wrote: >> >> Author: cschneider >>> Date: Mon Jul 23 14:10:45 2012 >>> New Revision: 1364640 >>> >>> URL: >>> http://svn.apache.org/viewvc?**rev=1364640&view=rev<http://svn.apache.org/viewvc?rev=1364640&view=rev> >>> Log: >>> KARAF-1640 Start shell when all bundles are resolved or active >>> >>> Added: >>> >>> karaf/trunk/shell/console/src/**main/java/org/apache/karaf/** >>> shell/console/impl/jline/**BundleWatcher.java >>> Modified: >>> >>> karaf/trunk/shell/console/src/**main/java/org/apache/karaf/** >>> shell/console/impl/jline/**LocalConsoleManager.java >>> >>> Added: >>> karaf/trunk/shell/console/src/**main/java/org/apache/karaf/** >>> shell/console/impl/jline/**BundleWatcher.java >>> URL: >>> http://svn.apache.org/viewvc/**karaf/trunk/shell/console/src/** >>> main/java/org/apache/karaf/**shell/console/impl/jline/** >>> BundleWatcher.java?rev=**1364640&view=auto<http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/BundleWatcher.java?rev=1364640&view=auto> >>> >>> ==============================**==============================** >>> ================== >>> --- >>> karaf/trunk/shell/console/src/**main/java/org/apache/karaf/** >>> shell/console/impl/jline/**BundleWatcher.java >>> (added) >>> +++ >>> karaf/trunk/shell/console/src/**main/java/org/apache/karaf/** >>> shell/console/impl/jline/**BundleWatcher.java >>> Mon Jul 23 14:10:45 2012 >>> @@ -0,0 +1,77 @@ >>> +package org.apache.karaf.shell.**console.impl.jline; >>> + >>> +import java.io.IOException; >>> +import java.io.PrintStream; >>> + >>> +import org.fusesource.jansi.Ansi; >>> +import org.osgi.framework.Bundle; >>> +import org.osgi.framework.**BundleContext; >>> + >>> +public class BundleWatcher implements Runnable { >>> + >>> + private final BundleContext context; >>> + private final Runnable consoleStartCallBack; >>> + private final PrintStream out; >>> + >>> + public BundleWatcher(BundleContext context, PrintStream out, >>> Runnable >>> consoleStartCallBack) { >>> + this.context = context; >>> + this.out = out; >>> + this.consoleStartCallBack = consoleStartCallBack; >>> + } >>> + >>> + @Override >>> + public void run() { >>> + boolean startConsole = false; >>> + out.println("Apache Karaf starting up. Press Enter to start the >>> shell now ..."); >>> + out.println(); >>> + while (!startConsole) { >>> + BundleStats stats = getBundleStats(); >>> + //out.print(Ansi.ansi().**cursorUp(1).toString()); >>> + out.println(String.format("**Bundles - total: %d, active: >>> %d, >>> resolved: %d, installed: %d ", >>> + stats.numTotal, stats.numActive, stats.numResolved, >>> stats.numInstalled)); >>> + try { >>> + Thread.sleep(500); >>> + } catch (InterruptedException e) { >>> + } >>> + try { >>> + if (System.in.available() > 0) { >>> + char ch = (char) System.in.read(); >>> + if (ch == '\r') { >>> + startConsole = true; >>> + } >>> + } >>> + } catch (IOException e) { >>> + } >>> + if (stats.numActive + stats.numResolved == stats.numTotal) { >>> + startConsole = true; >>> + } >>> + } >>> + consoleStartCallBack.run(); >>> + } >>> + >>> + private BundleStats getBundleStats() { >>> + Bundle[] bundles = context.getBundles(); >>> + BundleStats stats = new BundleStats(); >>> + stats.numTotal = bundles.length; >>> + for (Bundle bundle : bundles) { >>> + if (bundle.getState() == Bundle.ACTIVE) { >>> + stats.numActive ++; >>> + } >>> + if (bundle.getState() == Bundle.RESOLVED) { >>> + stats.numResolved ++; >>> + } >>> + if (bundle.getState() == Bundle.INSTALLED) { >>> + stats.numInstalled ++; >>> + } >>> + } >>> + return stats; >>> + } >>> + >>> + class BundleStats { >>> + int numResolved = 0; >>> + int numActive = 0; >>> + int numInstalled = 0; >>> + int numTotal = 0; >>> + } >>> + >>> +} >>> >>> 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=**1364640&r1=1364639&r2=1364640&**view=diff<http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/LocalConsoleManager.java?rev=1364640&r1=1364639&r2=1364640&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 Jul 23 14:10:45 2012 >>> @@ -33,6 +33,7 @@ import >>> org.apache.karaf.shell.**console.Co<http://org.apache.karaf.shell.console.Co> >>> import org.apache.karaf.shell.**console.ConsoleFactory; >>> import org.apache.sshd.agent.**SshAgent; >>> import org.apache.sshd.agent.local.**AgentImpl; >>> +import org.fusesource.jansi.Ansi; >>> import org.osgi.framework.**BundleContext; >>> import org.osgi.framework.**ServiceRegistration; >>> import org.slf4j.Logger; >>> @@ -84,7 +85,14 @@ 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); >>> - consoleFactory.startConsoleAs(**console, subject); >>> + BundleWatcher watcher = new BundleWatcher(bundleContext, >>> System.out, new Runnable() { >>> + >>> + @Override >>> + public void run() { >>> + consoleFactory.startConsoleAs(**console, subject); >>> + } >>> + }); >>> + new Thread(watcher).start(); >>> } >>> >>> protected String startAgent(String user) { >>> >>> >>> >>> >> > > -- > Christian Schneider > http://www.liquid-reality.de > > Open Source Architect > Talend Application Integration Division http://www.talend.com > > -- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ FuseSource, Integration everywhere http://fusesource.com
