Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 99504 invoked from network); 30 May 2006 07:40:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 May 2006 07:40:39 -0000 Received: (qmail 92453 invoked by uid 500); 30 May 2006 07:40:39 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 92418 invoked by uid 500); 30 May 2006 07:40:39 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 92407 invoked by uid 99); 30 May 2006 07:40:39 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 00:40:39 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 00:40:38 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 33AAE1A983A; Tue, 30 May 2006 00:40:18 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r410206 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console: ConsoleFactory.java InteractiveConsole.java Date: Tue, 30 May 2006 07:40:17 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060530074018.33AAE1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jdillon Date: Tue May 30 00:40:17 2006 New Revision: 410206 URL: http://svn.apache.org/viewvc?rev=410206&view=rev Log: Expose the running state of the interactive console Start of factory to abstract the flavor of the console to be used by all components (like script command) Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java (with props) Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java?rev=410206&view=auto ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java (added) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java Tue May 30 00:40:17 2006 @@ -0,0 +1,36 @@ +/* + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.gshell.console; + +/** + * Interface to abstract creation of {@link Console} instances. + * + * @version $Id$ + */ +public interface ConsoleFactory +{ + // + // TODO: Need to hookup ConsoleFactory to allow instances to be created by components + // (like the script command) with out needing to know which is the right flavor + // + + // + // TODO: Re-eval if this needs to be an interface... might not + // + + Console create(IO io) throws Exception; +} Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java?rev=410206&r1=410205&r2=410206&view=diff ============================================================================== --- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java (original) +++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java Tue May 30 00:40:17 2006 @@ -36,9 +36,11 @@ private final Console console; - private Executor executor; + private final Executor executor; - private Prompter prompter; + private final Prompter prompter; + + private boolean running = false; private boolean shutdownOnNull = false; @@ -75,40 +77,22 @@ return shutdownOnNull; } + public boolean isRunning() { + return running; + } + + // + // abort() ? + // + public void run() { log.info("Running..."); - boolean debug = log.isDebugEnabled(); - boolean running = true; + running = true; while (running) { try { - String line; - - while ((line = console.readLine(prompter.getPrompt())) != null) { - if (debug) { - log.debug("Read line: " + line); - } - - Executor.Result result = executor.execute(line); - - // Allow executor to request that the loop stop - if (result == Executor.Result.STOP) { - log.debug("Executor requested STOP"); - running = false; - break; - } - } - - // - // TODO: Probably need to expose more configurability for handing/rejecting shutdown - // - - // Line was null, maybe shutdown - if (shutdownOnNull) { - log.debug("Input was null; which will cause shutdown"); - running = false; - } + doRun(); } catch (Exception e) { log.error("Exception", e); @@ -121,10 +105,43 @@ log.info("Stopped"); } + private void doRun() throws Exception { + boolean debug = log.isDebugEnabled(); + String line; + + while ((line = console.readLine(prompter.getPrompt())) != null) { + if (debug) { + log.debug("Read line: " + line); + } + + Executor.Result result = executor.execute(line); + + // Allow executor to request that the loop stop + if (result == Executor.Result.STOP) { + log.debug("Executor requested STOP"); + running = false; + break; + } + } + + // Line was null, maybe shutdown + if (shutdownOnNull) { + log.debug("Input was null; which will cause shutdown"); + running = false; + } + + // + // TODO: Probably need to expose more configurability for handing/rejecting shutdown + // + } + // // Executor // + /** + * Allows custom processing, the "do something". + */ public static interface Executor { enum Result { @@ -139,6 +156,9 @@ // Prompter // + /** + * Allows custom prompt handling. + */ public static interface Prompter { String getPrompt();