Return-Path: X-Original-To: apmail-karaf-dev-archive@minotaur.apache.org Delivered-To: apmail-karaf-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 81FD1D23E for ; Mon, 23 Jul 2012 14:14:47 +0000 (UTC) Received: (qmail 84931 invoked by uid 500); 23 Jul 2012 14:14:47 -0000 Delivered-To: apmail-karaf-dev-archive@karaf.apache.org Received: (qmail 84667 invoked by uid 500); 23 Jul 2012 14:14:40 -0000 Mailing-List: contact dev-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list dev@karaf.apache.org Received: (qmail 84633 invoked by uid 99); 23 Jul 2012 14:14:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 14:14:39 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gnodet@gmail.com designates 209.85.216.41 as permitted sender) Received: from [209.85.216.41] (HELO mail-qa0-f41.google.com) (209.85.216.41) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 14:14:34 +0000 Received: by qabg27 with SMTP id g27so1312425qab.0 for ; Mon, 23 Jul 2012 07:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0eKvkW0tvjNcMEdiHCb4Rq974LMWY5UcfXYVegJEouo=; b=qd7xI18zfTe/FXcFXiXaNRB0lmd9Cpcz7tm/3A8RX2GmhFbeQHnfNG8Cis/1k9a44s zht60C1XmCzZT4yKpkrEu0CLLmGqmwkRPBawks57uv1Z45xdIMSgTjrku1OD5JkYt6aA HMza4w8YOLaYGoYdQmwESUSjylORNj+vJHPaiL3cW65bUob+X5AeomOzpLMfGyRAeOI9 nZYhYaqh3JnyIrXB3SKBJ12YRyd39fuT9g2HIaWk2D9kG5ThfIqYLPZ2VhiDXrxSV7NB r1o8WkOjTUMl4eE8qDLj56Vxf1cxCjKrnzl/Zopf6Fg8pjPpz2lhrs3+AOH4MIGBDslT AAWg== MIME-Version: 1.0 Received: by 10.224.71.73 with SMTP id g9mr24780507qaj.12.1343052853326; Mon, 23 Jul 2012 07:14:13 -0700 (PDT) Received: by 10.229.95.212 with HTTP; Mon, 23 Jul 2012 07:14:13 -0700 (PDT) In-Reply-To: <20120723141045.7FFCB23888FD@eris.apache.org> References: <20120723141045.7FFCB23888FD@eris.apache.org> Date: Mon, 23 Jul 2012 16:14:13 +0200 Message-ID: Subject: Re: svn commit: r1364640 - in /karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline: BundleWatcher.java LocalConsoleManager.java From: Guillaume Nodet To: dev@karaf.apache.org Content-Type: multipart/alternative; boundary=bcaec51ba2c53cb4c504c57fdcba X-Virus-Checked: Checked by ClamAV on apache.org --bcaec51ba2c53cb4c504c57fdcba Content-Type: text/plain; charset=ISO-8859-1 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, wrote: > Author: cschneider > Date: Mon Jul 23 14:10:45 2012 > New Revision: 1364640 > > URL: 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 > > ============================================================================== > --- > 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 > > ============================================================================== > --- > 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 > 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) { > > > -- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ FuseSource, Integration everywhere http://fusesource.com --bcaec51ba2c53cb4c504c57fdcba--