You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/05/30 09:40:17 UTC
svn commit: r410206 - in
/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console:
ConsoleFactory.java InteractiveConsole.java
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();