Correction of message key test long run command

This commit is contained in:
Emmanuel Bigeon 2016-06-09 19:09:17 -04:00
parent edc9c2070f
commit 3ac978bdc1
4 changed files with 39 additions and 18 deletions

View File

@ -144,9 +144,6 @@ public class SocketConsoleApplicationShell implements Runnable {
public void run() {
try (ServerSocket actualServerSocket = new ServerSocket(port)) {
this.serverSocket = actualServerSocket;
final ConsoleRunnable runnable = new ConsoleRunnable(app,
promptingLock);
final Thread appTh = new Thread(runnable);
running = true;
try (PipedOutputStream outStream = new PipedOutputStream();
BufferedWriter writer = new BufferedWriter(
@ -156,11 +153,13 @@ public class SocketConsoleApplicationShell implements Runnable {
consoleInput);
BufferedReader inBuf = new BufferedReader(isr);) {
consoleManager.setInput(inBuf);
runSokectServer(appTh, writer);
runSokectServer(writer);
// Close the application
// Pass command to application
writer.write(applicationShutdown + EOL);
writer.flush();
if (app.isRunning()) {
writer.write(applicationShutdown + EOL);
writer.flush();
}
}
}
} catch (final IOException e) {
@ -172,20 +171,27 @@ public class SocketConsoleApplicationShell implements Runnable {
/** @param appTh the application thread
* @param writer the writer to the application
* @throws IOException if the communication with the client failed */
private void runSokectServer(Thread appTh,
BufferedWriter writer) throws IOException {
private void runSokectServer(BufferedWriter writer) throws IOException {
final ConsoleRunnable runnable = new ConsoleRunnable(app,
promptingLock);
Thread appThOld = null;
Thread appThNext = new Thread(runnable);
while (running) {
try (Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(
clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));) {
InputStreamReader isr = new InputStreamReader(
clientSocket.getInputStream());
BufferedReader in = new BufferedReader(isr);) {
// this is not threaded to avoid several clients at the same
// time
consoleManager.setOutput(out);
// Initiate application
if (!appTh.isAlive()) {
appTh.start();
if (appThOld == null || !appThOld.isAlive()) {
appThNext.start();
// Prepare next start
appThOld = appThNext;
appThNext = new Thread(runnable);
} else {
out.println("Reconnected"); //$NON-NLS-1$
}
@ -249,7 +255,7 @@ public class SocketConsoleApplicationShell implements Runnable {
private void communicateLoop(BufferedReader in,
BufferedWriter writer) throws IOException {
String ln;
while (running && (ln = in.readLine()) != null) {
while (app.isRunning() && (ln = in.readLine()) != null) {
if (ln.equals(close)) {
break;
}

View File

@ -76,6 +76,23 @@ public class ConsoleTestApplication extends ConsoleApplication {
}
}
});
add(new Command("long") {
@Override
public String tip() {
return "A long run test command";
}
@Override
public void execute(String... args) throws CommandRunException {
try {
Thread.sleep(2000);
manager.println("Test command ran fine");
} catch (IOException | InterruptedException e) {
throw new CommandRunException("manager closed", e);
}
}
});
} catch (final InvalidCommandName e) {
e.printStackTrace();
}

View File

@ -32,12 +32,10 @@
<!-- The fact that you are presently reading this means that you have had -->
<!-- knowledge of the CeCILL license and that you accept its terms. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>gclc-swt</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<url>http://www.bigeon.fr/emmanuel</url>
<properties>

View File

@ -83,7 +83,7 @@ public class CommandProvider implements ICommandProvider {
}
}
throw new CommandRunException(
Messages.getString("CommandProvider.unrecognized0", cmd)); //$NON-NLS-1$
Messages.getString("CommandProvider.unrecognized", cmd)); //$NON-NLS-1$
}
/* (non-Javadoc)