Changed exit mechanism on gclc
This commit is contained in:
@@ -71,6 +71,10 @@ public class ThreadedServerConsoleManager implements ConsoleManager {
|
||||
private BufferedReader input;
|
||||
/** the prompting status */
|
||||
private boolean doPrompt;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private boolean closed = false;
|
||||
|
||||
/** Create the console manager.
|
||||
*
|
||||
@@ -159,6 +163,14 @@ public class ThreadedServerConsoleManager implements ConsoleManager {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// Do nothing
|
||||
this.closed = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleManager#isClosed() */
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +116,13 @@ public class ConsoleRunnableTest {
|
||||
public void close() throws IOException {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleManager#isClosed() */
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return i == cmds.length;
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
@@ -136,7 +143,7 @@ public class ConsoleRunnableTest {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
|
||||
Thread th = new Thread(runnable);
|
||||
@@ -151,7 +158,7 @@ public class ConsoleRunnableTest {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
runnable.stop();
|
||||
Thread th = new Thread(runnable);
|
||||
@@ -166,7 +173,7 @@ public class ConsoleRunnableTest {
|
||||
Object lock = new Object();
|
||||
ConsoleApplication app = new ConsoleTestApplication(
|
||||
new ConsoleManagerTestImplementation(
|
||||
new String[] {"test", ConsoleTestApplication.EXIT}));
|
||||
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
|
||||
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@@ -34,12 +34,15 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.socket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.command.Command;
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
import fr.bigeon.gclc.command.ExitCommand;
|
||||
import fr.bigeon.gclc.command.HelpExecutor;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.prompt.CLIPrompterMessages;
|
||||
|
||||
/** A test-purpose application
|
||||
*
|
||||
@@ -56,7 +59,7 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
"See you");
|
||||
try {
|
||||
add(new ExitCommand(EXIT, this));
|
||||
addHelpCommand("help");
|
||||
add(new HelpExecutor("help", manager, this.getRoot()));
|
||||
add(new Command("test") {
|
||||
|
||||
@Override
|
||||
@@ -65,63 +68,16 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) {
|
||||
manager.println("Test command ran fine");
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
try {
|
||||
manager.println("Test command ran fine");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("manager closed", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (final InvalidCommandName e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** <p>
|
||||
* A command to exit a {@link ConsoleApplication}.
|
||||
*
|
||||
* @author Emmanuel BIGEON */
|
||||
class ExitCommand implements ICommand {
|
||||
/** The exit command manual message key */
|
||||
private static final String EXIT_MAN = "exit.man"; //$NON-NLS-1$
|
||||
/** The tip of the exit command */
|
||||
private static final String EXIT_TIP = "exit.tip"; //$NON-NLS-1$
|
||||
/** The application that will be exited when this command runs */
|
||||
private final ConsoleApplication app;
|
||||
/** The exit command name */
|
||||
private final String name;
|
||||
|
||||
/** @param name the name of the command
|
||||
* @param app the application to exit */
|
||||
public ExitCommand(String name, ConsoleApplication app) {
|
||||
this.name = name;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/** The actions to take before exiting */
|
||||
public void beforeExit() {
|
||||
// Do nothing by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void execute(String... args) {
|
||||
beforeExit();
|
||||
app.exit();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#getCommandName() */
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(ConsoleManager helpManager, String... args) {
|
||||
helpManager.println(
|
||||
CLIPrompterMessages.getString(EXIT_MAN, (Object[]) args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return CLIPrompterMessages.getString(EXIT_TIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user